Functions

line.c File Reference

Vector library - geometry manipulation. More...

#include <stdlib.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/Vect.h>
#include <grass/glocale.h>
Include dependency graph for line.c:

Go to the source code of this file.

Functions

struct line_pnts * Vect__new_line_struct (void)
 Creates and initializes a struct line_pnts.
struct line_pnts * Vect_new_line_struct ()
 Creates and initializes a struct line_pnts.
int Vect_destroy_line_struct (struct line_pnts *p)
 Frees all memory associated with a struct line_pnts, including the struct itself.
int Vect_copy_xyz_to_pnts (struct line_pnts *Points, double *x, double *y, double *z, int n)
 Copy points from array to line structure.
int Vect_reset_line (struct line_pnts *Points)
 Reset line.
int Vect_append_point (struct line_pnts *Points, double x, double y, double z)
 Appends one point to the end of a line.
int Vect_line_insert_point (struct line_pnts *Points, int index, double x, double y, double z)
 Insert new point at index position and move all old points at that position and above up.
int Vect_line_delete_point (struct line_pnts *Points, int index)
 Delete point at given index and move all points above down.
int Vect_line_prune (struct line_pnts *Points)
 Remove duplicate points, i.e. zero length segments.
int Vect_line_prune_thresh (struct line_pnts *Points, double threshold)
 Remove points in threshold.
int Vect_append_points (struct line_pnts *Points, struct line_pnts *APoints, int direction)
 Appends points to the end of a line.
int Vect_copy_pnts_to_xyz (struct line_pnts *Points, double *x, double *y, double *z, int *n)
 Copy points from line structure to array.
int Vect_point_on_line (struct line_pnts *Points, double distance, double *x, double *y, double *z, double *angle, double *slope)
 Find point on line in the specified distance.
int Vect_line_segment (struct line_pnts *InPoints, double start, double end, struct line_pnts *OutPoints)
 Create line segment.
double Vect_line_length (struct line_pnts *Points)
 Calculate line length, 3D-length in case of 3D vector line.
double Vect_line_geodesic_length (struct line_pnts *Points)
 Calculate line length.
int Vect_line_distance (struct line_pnts *points, double ux, double uy, double uz, int with_z, double *px, double *py, double *pz, double *dist, double *spdist, double *lpdist)
 calculate line distance.
double Vect_points_distance (double x1, double y1, double z1, double x2, double y2, double z2, int with_z)
 Calculate distance of 2 points.
int Vect_line_box (struct line_pnts *Points, BOUND_BOX *Box)
 Get bounding box of line.
void Vect_line_reverse (struct line_pnts *Points)
 Reverse the order of vertices.
int Vect_get_line_cat (struct Map_info *Map, int line, int field)
 Fetches FIRST category number for given vector line and field.

Detailed Description

Vector library - geometry manipulation.

(C) 2001-2008 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:
Original author CERL, probably Dave Gerdes or Mike Higgins. Update to GRASS 5.7 Radim Blazek and David D. Gray.
Date:
2001-2008

Definition in file line.c.


Function Documentation

struct line_pnts * Vect__new_line_struct ( void   ) [read]

Creates and initializes a struct line_pnts.

Use Vect_new_line_struct() instead.

This structure is used for reading and writing vector lines and polygons. The library routines handle all memory allocation. If 3 lines in memory are needed at the same time, then simply 3 line_pnts structures have to be used

Parameters:
void
Returns:
pointer to line_pnts
NULL on error

Definition at line 65 of file line.c.

Referenced by Vect_new_line_struct().

int Vect_append_point ( struct line_pnts *  Points,
double  x,
double  y,
double  z 
)

Appends one point to the end of a line.

Returns new number of points or -1 on out of memory Note, this will append to whatever is in line struct. If you are re-using a line struct, be sure to clear out old data first by calling Vect_reset_line().

Parameters:
Pointsline
x,y,zpoint coordinates to be added
Returns:
number of points

Definition at line 166 of file line.c.

References dig_alloc_points().

Referenced by V2_read_line_ogr(), Vect__intersect_line_with_poly(), Vect_area_buffer2(), Vect_break_lines_list(), Vect_break_polygons(), Vect_clean_small_angles_at_nodes(), Vect_line_buffer(), Vect_line_intersection(), Vect_line_segment(), Vect_net_nearest_nodes(), Vect_net_shortest_path_coor(), Vect_point_buffer2(), Vect_snap_lines_list(), Vedit_bulk_labeling(), Vedit_merge_lines(), and Vedit_split_lines().

int Vect_append_points ( struct line_pnts *  Points,
struct line_pnts *  APoints,
int  direction 
)

Appends points to the end of a line.

Note, this will append to whatever is in line struct. If you are re-using a line struct, be sure to clear out old data first by calling Vect_reset_line().

Parameters:
Pointsline
APointspoints to be included
directiondirection (GV_FORWARD, GV_BACKWARD)
Returns:
new number of points
-1 on out of memory

Definition at line 310 of file line.c.

References dig_alloc_points().

Referenced by V1_read_next_line_ogr(), Vect_build_line_area(), Vect_get_area_points(), Vect_get_isle_points(), Vect_line_buffer(), and Vect_net_shortest_path_coor().

int Vect_copy_pnts_to_xyz ( struct line_pnts *  Points,
double *  x,
double *  y,
double *  z,
int *  n 
)

Copy points from line structure to array.

x/y/z arrays MUST be at least as large as Points->n_points

Also note that n is a pointer to int.

Parameters:
Pointsline
x,y,zcoordinates arrays
nnumber of points
Returns:
number of points copied

Definition at line 357 of file line.c.

int Vect_copy_xyz_to_pnts ( struct line_pnts *  Points,
double *  x,
double *  y,
double *  z,
int  n 
)

Copy points from array to line structure.

Parameters:
Pointsline structure
x,y,zcoordinates
numberof points to be copied
Returns:
0 on success
-1 on out of memory

Definition at line 113 of file line.c.

References dig_alloc_points().

Referenced by Vect_line_check_intersection().

int Vect_destroy_line_struct ( struct line_pnts *  p )
int Vect_get_line_cat ( struct Map_info *  Map,
int  line,
int  field 
)

Fetches FIRST category number for given vector line and field.

Parameters:
Mapvector map
lineline id
fieldlayer number
Returns:
-1 no category
category number (>=0)

Definition at line 812 of file line.c.

References Vect_cat_get(), Vect_new_cats_struct(), and Vect_read_line().

int Vect_line_box ( struct line_pnts *  Points,
BOUND_BOX *  Box 
)

Get bounding box of line.

Parameters:
Pointsline
[out]Boxbounding box
Returns:
0

Definition at line 768 of file line.c.

References dig_line_box().

Referenced by V1_read_next_line_nat(), V1_read_next_line_ogr(), and Vect_remove_duplicates().

int Vect_line_delete_point ( struct line_pnts *  Points,
int  index 
)

Delete point at given index and move all points above down.

Parameters:
Pointsline
index(from 0 to Points->n_points-1)
Returns:
number of points

Definition at line 225 of file line.c.

Referenced by Vect_clean_small_angles_at_nodes(), and Vedit_remove_vertex().

int Vect_line_distance ( struct line_pnts *  points,
double  ux,
double  uy,
double  uz,
int  with_z,
double *  px,
double *  py,
double *  pz,
double *  dist,
double *  spdist,
double *  lpdist 
)

calculate line distance.

Sets (if not null):

  • px, py - point on line,
  • dist - distance to line,
  • spdist - distance to point on line from segment beginning,
  • sldist - distance to point on line form line beginning along line
Parameters:
pointsline
ux,uy,uzpoint coordinates
with_zflag if to use z coordinate (3D calculation)
[out]px,py,pzpoint on line
[out]distdistance to line,
[out]spdistdistance of point from segment beginning
[out]lpdistdistance of point from line
Returns:
nearest segment (first is 1)

Definition at line 628 of file line.c.

References dig_distance2_point_to_line().

Referenced by Vect_find_line_list(), Vect_line_check_intersection(), Vect_net_nearest_nodes(), Vect_net_shortest_path_coor(), Vedit_add_vertex(), and Vedit_split_lines().

double Vect_line_geodesic_length ( struct line_pnts *  Points )

Calculate line length.

If projection is LL, the length is measured along the geodesic.

Parameters:
Pointsline
Returns:
line length

Definition at line 580 of file line.c.

Referenced by Vect_net_build_graph().

int Vect_line_insert_point ( struct line_pnts *  Points,
int  index,
double  x,
double  y,
double  z 
)

Insert new point at index position and move all old points at that position and above up.

Parameters:
Pointsline
index(from 0 to Points->n_points-1)
x,y,zpoint coordinates
Returns:
number of points
-1 on error (alocation)

Definition at line 192 of file line.c.

References dig_alloc_points().

Referenced by Vedit_add_vertex().

double Vect_line_length ( struct line_pnts *  Points )

Calculate line length, 3D-length in case of 3D vector line.

For Lat-Long use Vect_line_geodesic_length() instead.

Parameters:
Pointsline
Returns:
line length

Definition at line 552 of file line.c.

Referenced by Vect_area_perimeter(), Vect_line_segment(), Vect_net_build_graph(), Vect_net_nearest_nodes(), Vect_net_shortest_path_coor(), Vect_point_on_line(), Vect_remove_small_areas(), Vedit_bulk_labeling(), and Vedit_split_lines().

int Vect_line_prune ( struct line_pnts *  Points )

Remove duplicate points, i.e. zero length segments.

Parameters:
Pointsline
Returns:
number of points

Definition at line 253 of file line.c.

Referenced by Vect_break_lines_list(), Vect_break_polygons(), Vect_clean_small_angles_at_nodes(), Vect_line_buffer(), Vect_snap_lines_list(), and Vedit_add_vertex().

int Vect_line_prune_thresh ( struct line_pnts *  Points,
double  threshold 
)

Remove points in threshold.

Parameters:
Pointsline
thresholdthreshold value
Returns:
number of points in result

Definition at line 283 of file line.c.

References dig_prune().

void Vect_line_reverse ( struct line_pnts *  Points )

Reverse the order of vertices.

Parameters:
Pointsline to be changed
Returns:
void

Definition at line 781 of file line.c.

Referenced by Vedit_flip_lines().

int Vect_line_segment ( struct line_pnts *  InPoints,
double  start,
double  end,
struct line_pnts *  OutPoints 
)

Create line segment.

Creates segment of InPoints from start to end measured along the line and write it to OutPoints.

If the distance is greater than line length or negative, error is returned.

Parameters:
InPointsinput line
startsegment number
endsegment number
OutPointsoutput line
Returns:
1 success
0 error when start > length or end < 0 or start < 0 or end > length

Definition at line 495 of file line.c.

References Vect_append_point(), Vect_line_length(), Vect_point_on_line(), and Vect_reset_line().

struct line_pnts* Vect_new_line_struct (  ) [read]

Creates and initializes a struct line_pnts.

This structure is used for reading and writing vector lines and polygons. The library routines handle all memory allocation. If 3 lines in memory are needed at the same time, then simply 3 line_pnts structures have to be used

Parameters:
void
Returns:
pointer to line_pnts
NULL on error

Definition at line 55 of file line.c.

References Vect__new_line_struct().

Referenced by V1_rewrite_line_nat(), V2_restore_line_nat(), Vect_area_buffer2(), Vect_break_lines_list(), Vect_break_polygons(), Vect_build_line_area(), Vect_build_nat(), Vect_clean_small_angles_at_nodes(), Vect_copy_map_lines(), Vect_find_island(), Vect_find_line_list(), Vect_get_area_area(), Vect_get_area_points(), Vect_get_isle_points(), Vect_get_point_in_area(), Vect_get_point_in_poly_isl(), Vect_isle_find_area(), Vect_line_buffer(), Vect_line_buffer2(), Vect_line_check_intersection(), Vect_line_intersection(), Vect_net_build_graph(), Vect_net_nearest_nodes(), Vect_net_shortest_path_coor(), Vect_overlay_and(), Vect_point_buffer2(), Vect_point_in_area_outer_ring(), Vect_point_in_island(), Vect_remove_duplicates(), Vect_remove_small_areas(), Vect_select_lines_by_polygon(), Vect_snap_lines_list(), Vect_tin_get_z(), Vedit_add_vertex(), Vedit_bulk_labeling(), Vedit_chtype_lines(), Vedit_copy_lines(), Vedit_flip_lines(), Vedit_merge_lines(), Vedit_modify_cats(), Vedit_move_lines(), Vedit_move_vertex(), Vedit_remove_vertex(), Vedit_select_by_query(), Vedit_snap_lines(), Vedit_snap_point(), and Vedit_split_lines().

int Vect_point_on_line ( struct line_pnts *  Points,
double  distance,
double *  x,
double *  y,
double *  z,
double *  angle,
double *  slope 
)

Find point on line in the specified distance.

From the begining, measured along line.

If the distance is greater than line length or negative, error is returned.

Parameters:
Pointsline
distancedistance value
x,y,zpointers to point coordinates or NULL
anglepointer to angle of line in that point (radians, counter clockwise from x axis) or NULL
slopepointer to slope angle in radians (positive up)
Returns:
number of segment the point is on (first is 1),
0 error when point is outside the line

Definition at line 391 of file line.c.

References Vect_line_length().

Referenced by Vect_line_segment().

double Vect_points_distance ( double  x1,
double  y1,
double  z1,
double  x2,
double  y2,
double  z2,
int  with_z 
)

Calculate distance of 2 points.

Simply uses Pythagoras.

Parameters:
x1,y1,z1first point
x2,y2,z2second point
with_zuse z coordinate
Returns:
distance

Definition at line 742 of file line.c.

Referenced by Vect_clean_small_angles_at_nodes(), Vect_find_node(), Vedit_add_vertex(), Vedit_get_min_distance(), Vedit_move_vertex(), Vedit_remove_vertex(), Vedit_snap_line(), and Vedit_snap_point().

int Vect_reset_line ( struct line_pnts *  Points )

Reset line.

Make sure line structure is clean to be re-used, i.e. it has no points associated with it Points must have previously been created with Vect_new_line_struct().

Parameters:
Pointsline to be reset
Returns:
0

Definition at line 146 of file line.c.

Referenced by V1_read_next_line_ogr(), V2_read_line_ogr(), Vect_break_lines_list(), Vect_break_polygons(), Vect_build_line_area(), Vect_clean_small_angles_at_nodes(), Vect_line_buffer(), Vect_line_segment(), Vect_net_nearest_nodes(), Vect_net_shortest_path_coor(), Vect_snap_lines_list(), Vedit_merge_lines(), and Vedit_split_lines().