GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71806
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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

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

Referenced by Vect_snap_line().

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

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

Referenced by Vect_snap_line().

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

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

Referenced by Vect_snap_line().

Function Documentation

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 960 of file Vlib/snap.c.

References bound_box::B, RTree_Rect::boundary, boxlist::box, dig_distance2_point_to_line(), bound_box::E, G_debug(), G_free(), GV_FORWARD, boxlist::id, bound_box::N, line_pnts::n_points, ilist::n_values, boxlist::n_values, NULL, RTreeCreateTree(), RTreeDestroyTree(), RTreeInsertRect(), RTreeSearch(), RTreeSetOverflow(), bound_box::S, bound_box::T, ilist::value, Vect_append_point(), Vect_append_points(), Vect_destroy_boxlist(), Vect_destroy_cats_struct(), Vect_destroy_line_struct(), Vect_line_alive(), Vect_line_prune(), Vect_new_boxlist(), Vect_new_cats_struct(), Vect_new_line_struct(), Vect_read_line(), Vect_reset_boxlist(), Vect_reset_line(), bound_box::W, x, line_pnts::x, X1W, line_pnts::y, Y1S, line_pnts::z, and Z1B.

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 906 of file Vlib/snap.c.

References _, G_debug(), G_ilist_add(), G_important_message(), NULL, Vect_destroy_list(), Vect_get_num_lines(), Vect_line_alive(), Vect_new_list(), Vect_read_line(), and 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 170 of file Vlib/snap.c.

References getenv().

Referenced by Vect_snap_lines().