GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
Vlib/snap.c File Reference

Vector library - Clean vector map (snap lines) More...

#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <grass/vector.h>
#include <grass/glocale.h>
#include <grass/kdtree.h>
Include dependency graph for Vlib/snap.c:

Go to the source code of this file.

Macros

#define X1W   0x01 /* x1 is West, x2 East */
 
#define Y1S   0x02 /* y1 is South, y2 North */
 
#define Z1B   0x04 /* z1 is Bottom, z2 Top */
 

Functions

void Vect_snap_lines_list (struct Map_info *Map, const struct ilist *List_lines, double thresh, struct Map_info *Err)
 Snap selected lines to existing vertex in threshold. More...
 
void Vect_snap_lines (struct Map_info *Map, int type, double thresh, struct Map_info *Err)
 Snap lines in vector map to existing vertex in threshold. More...
 
int Vect_snap_line (struct Map_info *Map, struct ilist *reflist, struct line_pnts *Points, double thresh, int with_z, int *nsnapped, int *ncreated)
 Snap a line to reference lines in Map with threshold. More...
 

Detailed Description

Vector library - Clean vector map (snap lines)

Higher level functions for reading/writing/manipulating vectors.

(C) 2001-2009 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Radim Blazek
update to GRASS 7 Markus Metz

Definition in file Vlib/snap.c.

Macro Definition Documentation

◆ X1W

#define X1W   0x01 /* x1 is West, x2 East */

Definition at line 27 of file Vlib/snap.c.

◆ Y1S

#define Y1S   0x02 /* y1 is South, y2 North */

Definition at line 28 of file Vlib/snap.c.

◆ Z1B

#define Z1B   0x04 /* z1 is Bottom, z2 Top */

Definition at line 29 of file Vlib/snap.c.

Function Documentation

◆ Vect_snap_line()

int Vect_snap_line ( struct Map_info Map,
struct ilist reflist,
struct line_pnts Points,
double  thresh,
int  with_z,
int *  nsnapped,
int *  ncreated 
)

Snap a line to reference lines in Map with threshold.

3D snapping is supported. The line to snap and the reference lines can but do not need to be in different vector maps.

Vect_snap_line() uses less memory, but is slower than Vect_snap_lines_list()

For details on snapping, see Vect_snap_lines_list()

Parameters
[in]Mapinput map with reference lines
[in]reflistlist of reference lines
[in,out]Pointsline points to snap
[in]threshthreshold in which to snap vertices
[in]with_z2D or 3D snapping
[in,out]nsnappednumber of snapped vertices
[in,out]ncreatednumber of new vertices (on segments)
Returns
1 if line was changed, otherwise 0

Definition at line 949 of file Vlib/snap.c.

◆ Vect_snap_lines()

void Vect_snap_lines ( struct Map_info Map,
int  type,
double  thresh,
struct Map_info Err 
)

Snap lines in vector map to existing vertex in threshold.

For details see Vect_snap_lines_list()

Parameters
[in]Mapinput map where vertices will be snapped
[in]typetype of lines to snap
[in]threshthreshold in which snap vertices
[out]Errvector map where lines representing snap are written or NULL
Returns
void

Definition at line 896 of file Vlib/snap.c.

◆ Vect_snap_lines_list()

void Vect_snap_lines_list ( struct Map_info Map,
const struct ilist List_lines,
double  thresh,
struct Map_info Err 
)

Snap selected lines to existing vertex in threshold.

Snap selected lines to existing vertices of other selected lines. 3D snapping is not supported.

Lines showing how vertices were snapped may be optionally written to error map. Input map must be opened on level 2 for update at least on GV_BUILD_BASE.

As mentioned above, lines are not necessarily snapped to nearest vertex! For example:

|
| 1         line 3 is snapped to line 1,
|           then line 2 is not snapped to common node at lines 1 and 3,
because it is already outside of threshold
----------- 3

|
| 2
|

The algorithm selects anchor vertices and snaps non-anchor vertices to these anchors. The distance between anchor vertices is always > threshold. If there is more than one anchor vertex within threshold around a non-anchor vertex, this vertex is snapped to the nearest anchor vertex within threshold.

Parameters
Mapinput map where vertices will be snapped
List_lineslist of lines to snap
threshthreshold in which snap vertices
[out]Errvector map where lines representing snap are written or NULL
Returns
void

Definition at line 169 of file Vlib/snap.c.