grass  7.8.6
About: GRASS (Geographic Resources Analysis Support System) is a raster- and vector-based GIS, image processing system, graphics production system and spatial modeling system.
  Fossies Dox: grass-7.8.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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 snap.c:

Go to the source code of this file.

Classes

struct  XPNT
 
struct  NEW
 
struct  NEW2
 

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

static int sort_new (const void *pa, const void *pb)
 
static int sort_new2 (const void *pa, const void *pb)
 
static int find_item (int id, const struct RTree_Rect *rect, void *list)
 
static int add_item (int id, const struct RTree_Rect *rect, void *list)
 
static int find_item_box (int id, const struct RTree_Rect *rect, void *list)
 
static int add_item_box (int id, const struct RTree_Rect *rect, void *list)
 
static void Vect_snap_lines_list_rtree (struct Map_info *, const struct ilist *, double, struct Map_info *)
 
static void Vect_snap_lines_list_kdtree (struct Map_info *, const struct ilist *, double, struct Map_info *)
 
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 snap.c.

Macro Definition Documentation

◆ X1W

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

Definition at line 27 of file snap.c.

◆ Y1S

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

Definition at line 28 of file snap.c.

◆ Z1B

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

Definition at line 29 of file snap.c.

Function Documentation

◆ add_item()

static int add_item ( int  id,
const struct RTree_Rect rect,
void *  list 
)
static

Definition at line 85 of file snap.c.

References G_ilist_add().

Referenced by Vect_snap_lines_list_rtree().

◆ add_item_box()

static int add_item_box ( int  id,
const struct RTree_Rect rect,
void *  list 
)
static

Definition at line 109 of file snap.c.

References bound_box::B, dig_boxlist_add(), bound_box::E, bound_box::N, bound_box::S, bound_box::T, and bound_box::W.

Referenced by Vect_snap_line().

◆ find_item()

static int find_item ( int  id,
const struct RTree_Rect rect,
void *  list 
)
static

Definition at line 78 of file snap.c.

References G_ilist_add().

Referenced by Vect_snap_lines_list_rtree().

◆ find_item_box()

static int find_item_box ( int  id,
const struct RTree_Rect rect,
void *  list 
)
static

Definition at line 92 of file snap.c.

References bound_box::B, dig_boxlist_add(), bound_box::E, bound_box::N, bound_box::S, bound_box::T, and bound_box::W.

Referenced by Vect_snap_line().

◆ sort_new()

static int sort_new ( const void *  pa,
const void *  pb 
)
static

Definition at line 47 of file snap.c.

References NEW::along.

Referenced by Vect_snap_lines_list_kdtree(), and Vect_snap_lines_list_rtree().

◆ sort_new2()

static int sort_new2 ( const void *  pa,
const void *  pb 
)
static

Definition at line 69 of file snap.c.

References NEW2::along.

Referenced by Vect_snap_line().

◆ 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 961 of file snap.c.

References add_item_box(), NEW2::along, dig_distance2_point_to_line(), dist2(), find_item_box(), G_debug(), G_free(), GV_FORWARD, line(), line_pnts::n_points, ilist::n_values, NULL, Points, RTreeCreateTree(), RTreeDestroyTree(), RTreeInsertRect(), RTreeSearch(), RTreeSetOverflow(), sort_new2(), 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(), line_pnts::x, x, NEW2::x, x1, X1W, x2, line_pnts::y, NEW2::y, Y1S, line_pnts::z, NEW2::z, and Z1B.

◆ 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 907 of file snap.c.

References _, G_debug(), G_ilist_add(), G_important_message(), line(), NULL, type, Vect_destroy_list(), Vect_get_num_lines(), Vect_line_alive(), Vect_new_list(), Vect_read_line(), and Vect_snap_lines_list().

◆ 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 snap.c.

References getenv(), Vect_snap_lines_list_kdtree(), and Vect_snap_lines_list_rtree().

Referenced by Vect_snap_lines().

◆ Vect_snap_lines_list_kdtree()

◆ Vect_snap_lines_list_rtree()