|
GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
|
Vector library - vector feature geometry. More...

Go to the source code of this file.
Functions | |
| struct line_pnts * | Vect__new_line_struct (void) |
| Creates and initializes a struct line_pnts (internal use only) | |
| struct line_pnts * | Vect_new_line_struct (void) |
| Creates and initializes a line_pnts structure. | |
| void | Vect_destroy_line_struct (struct line_pnts *p) |
| Frees all memory associated with a line_pnts structure, including the structure itself. | |
| int | Vect_copy_xyz_to_pnts (struct line_pnts *Points, const double *x, const double *y, const double *z, int n) |
| Copy points from array to line_pnts structure. | |
| void | 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_get_point (const struct line_pnts *Points, int index, double *x, double *y, double *z) |
| Get line point of given index. | |
| int | Vect_get_num_line_points (const struct line_pnts *Points) |
| Get number of line points. | |
| 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, const struct line_pnts *APoints, int direction) |
| Appends points to the end of a line. | |
| int | Vect_copy_pnts_to_xyz (const struct line_pnts *Points, double *x, double *y, double *z, int *n) |
| Copy points from line structure to array. | |
| int | Vect_point_on_line (const 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 (const struct line_pnts *InPoints, double start, double end, struct line_pnts *OutPoints) |
| Create line segment. | |
| double | Vect_line_length (const struct line_pnts *Points) |
| Calculate line length, 3D-length in case of 3D vector line. | |
| double | Vect_line_geodesic_length (const struct line_pnts *Points) |
| Calculate line length. | |
| int | Vect_line_distance (const 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 distance of point to line. | |
| int | Vect_line_geodesic_distance (const 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 geodesic distance of point to line in meters. | |
| double | Vect_points_distance (double x1, double y1, double z1, double x2, double y2, double z2, int with_z) |
| Calculate distance of 2 points. | |
| void | Vect_line_box (const struct line_pnts *Points, struct 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. | |
Vector library - vector feature geometry.
(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.
Definition in file line.c.
Creates and initializes a struct line_pnts (internal use only)
Use Vect_new_line_struct() instead.
Definition at line 55 of file line.c.
References line_pnts::alloc_points, malloc(), line_pnts::n_points, NULL, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vect_new_line_struct().
Appends one point to the end of a line.
If you are re-using a line struct, be sure to clear out old data first by calling Vect_reset_line().
Calls G_fatal_error() when out of memory.
| Points | pointer to line_pnts structure |
| x,y,z | point coordinates to be added |
Definition at line 148 of file line.c.
References _, dig_alloc_points(), G_fatal_error(), line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by I_rasterize(), IL_write_point_2d(), line_check_intersection2(), NetA_add_point_on_node(), V2_read_line_sfa(), V2_read_next_line_ogr(), V2_read_next_line_pg(), V2_write_line_sfa(), Vect__intersect_x_line_with_poly(), Vect__intersect_y_line_with_poly(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_clean_small_angles_at_nodes(), Vect_line_buffer(), Vect_line_intersection(), Vect_line_intersection2(), Vect_line_segment(), Vect_net_nearest_nodes(), Vect_point_buffer2(), Vect_snap_line(), Vedit_bulk_labeling(), Vedit_merge_lines(), and Vedit_split_lines().
| int Vect_append_points | ( | struct line_pnts * | Points, |
| const struct line_pnts * | APoints, | ||
| int | direction | ||
| ) |
Appends points to the end of a line.
Note, this will append to whatever is in line_pnts structure. If you are re-using a line struct, be sure to clear out old data first by calling Vect_reset_line().
| Points | pointer to line_pnts structure |
| APoints | points to be included |
| direction | direction (GV_FORWARD, GV_BACKWARD) |
Definition at line 335 of file line.c.
References dig_alloc_points(), GV_FORWARD, line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by V1_read_line_pg(), V2_read_line_pg(), Vect__get_area_points_nat(), Vect__get_area_points_pg(), Vect_line_buffer(), Vect_merge_lines(), and Vect_snap_line().
| int Vect_copy_pnts_to_xyz | ( | const 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.
| Points | pointer to line_pnts structure |
| x,y,z | coordinates arrays |
| n | number of points |
Definition at line 380 of file line.c.
References line_pnts::n_points, NULL, line_pnts::x, line_pnts::y, and line_pnts::z.
| int Vect_copy_xyz_to_pnts | ( | struct line_pnts * | Points, |
| const double * | x, | ||
| const double * | y, | ||
| const double * | z, | ||
| int | n | ||
| ) |
Copy points from array to line_pnts structure.
| Points | pointer to line_ptns structure |
| x,y,z | array of coordinates |
| n | number of points to be copied |
Definition at line 99 of file line.c.
References dig_alloc_points(), line_pnts::n_points, NULL, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by line_check_intersection(), P_Aux_to_Vector(), P_Sparse_Points(), and Vect_read_ascii().
Frees all memory associated with a line_pnts structure, including the structure itself.
| p | pointer to line_pnts structure |
Definition at line 77 of file line.c.
References line_pnts::alloc_points, G_free(), line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by I_rasterize(), NetA_add_point_on_node(), NetA_get_node_costs(), NetA_points_to_nodes(), NetA_varray_to_nodes(), P_estimate_splinestep(), P_Read_Vector_Region_Map(), P_Sparse_Points(), V2_delete_line_pg(), V2_write_line_sfa(), Vect__copy_areas(), Vect__free_cache(), Vect__load_plus_pg(), Vect_area_buffer2(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_clean_small_angles_at_nodes(), Vect_get_area_area(), Vect_get_area_perimeter(), Vect_get_map_box1(), Vect_line_buffer2(), Vect_line_intersection(), Vect_line_intersection2(), Vect_merge_lines(), Vect_net_ttb_build_graph(), Vect_overlay_and(), Vect_read_ascii(), Vect_read_line_to_wkb(), Vect_remove_duplicates(), Vect_remove_small_areas_ext(), Vect_remove_small_areas_nat(), Vect_snap_line(), Vect_topo_check(), Vect_write_ascii(), vector2perimeters(), 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().
Fetches FIRST category number for given vector line and field.
| Map | pointer to Map_info structure |
| line | line id |
| field | layer number |
Definition at line 929 of file line.c.
References line_cats::cat, line_cats::field, G_debug(), NULL, Vect_cat_get(), Vect_new_cats_struct(), and Vect_read_line().
Get number of line points.
| Points | pointer to line_pnts structure |
Definition at line 267 of file line.c.
References line_pnts::n_points.
Referenced by Vect_sfa_is_line_closed().
Get bounding box of line.
| Points | pointer to line_pnts structure | |
| [out] | Box | bounding box |
Definition at line 888 of file line.c.
References Box, and dig_line_box().
Referenced by V1_read_next_line_nat(), V2_read_next_line_nat(), V2_read_next_line_ogr(), V2_read_next_line_pg(), and Vedit_bulk_labeling().
Delete point at given index and move all points above down.
| Points | pointer to line_pnts structure |
| index | point (from 0 to Points->n_points-1) |
Definition at line 210 of file line.c.
References _, G_fatal_error(), line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vect_clean_small_angles_at_nodes(), and Vedit_remove_vertex().
| int Vect_line_distance | ( | const 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 distance of point to line.
Sets (if not null):
| points | pointer to line_pnts structure | |
| ux,uy,uz | point coordinates | |
| with_z | flag if to use z coordinate (3D calculation) | |
| [out] | px,py,pz | point on line |
| [out] | dist | distance to line |
| [out] | spdist | distance to point on line from segment beginning |
| [out] | lpdist | distance to point on line from line beginning along line |
Definition at line 648 of file line.c.
References dig_distance2_point_to_line(), line_pnts::n_points, NULL, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by line_check_intersection(), line_check_intersection2(), Vect_find_line_list(), Vect_net_nearest_nodes(), Vedit_add_vertex(), and Vedit_split_lines().
| int Vect_line_geodesic_distance | ( | const 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 geodesic distance of point to line in meters.
Sets (if not null):
| points | pointer to line_pnts structure | |
| ux,uy,uz | point coordinates | |
| with_z | flag if to use z coordinate (3D calculation) | |
| [out] | px,py,pz | point on line |
| [out] | dist | distance to line |
| [out] | spdist | distance to point on line from segment beginning |
| [out] | lpdist | distance to point on line from line beginning along line |
Definition at line 751 of file line.c.
References dig_distance2_point_to_line(), G_begin_distance_calculations(), G_distance(), line_pnts::n_points, NULL, line_pnts::x, line_pnts::y, and line_pnts::z.
Calculate line length.
If projection is LL, the length is measured along the geodesic.
| Points | pointer to line_pnts structure geometry |
Definition at line 602 of file line.c.
References G_begin_distance_calculations(), G_geodesic_distance(), line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vect_get_area_perimeter(), Vect_net_build_graph(), and Vect_net_ttb_build_graph().
| int Vect_line_get_point | ( | const struct line_pnts * | Points, |
| int | index, | ||
| double * | x, | ||
| double * | y, | ||
| double * | z | ||
| ) |
Get line point of given index.
Calls G_fatal_error() when index is not range in.
| Points | pointer to line_pnts structure |
| index | point index (from 0 to Points->n_points-1) |
| x | pointer to x coordinate or NULL |
| y | pointer to y coordinate or NULL |
| z | pointer to z coordinate or NULL |
Definition at line 244 of file line.c.
References _, G_fatal_error(), line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Insert new point at index position and move all old points at that position and above up.
| Points | pointer to line_pnts structure |
| index | (from 0 to Points->n_points-1) |
| x,y,z | point coordinates |
Definition at line 176 of file line.c.
References _, dig_alloc_points(), G_fatal_error(), line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vedit_add_vertex().
Calculate line length, 3D-length in case of 3D vector line.
For Lat-Long use Vect_line_geodesic_length() instead.
| Points | pointer to line_pnts structure geometry |
Definition at line 575 of file line.c.
References line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vect_line_segment(), Vect_net_build_graph(), Vect_net_nearest_nodes(), Vect_net_ttb_build_graph(), Vect_point_on_line(), Vect_remove_small_areas_ext(), Vect_remove_small_areas_nat(), Vect_topo_check(), Vedit_bulk_labeling(), and Vedit_split_lines().
Remove duplicate points, i.e. zero length segments.
| Points | pointer to line_pnts structure |
Definition at line 279 of file line.c.
References line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vect_area_buffer2(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_build_line_area(), Vect_clean_small_angles_at_nodes(), Vect_get_area_area(), Vect_get_area_perimeter(), Vect_line_buffer(), Vect_line_buffer2(), Vect_line_segment(), Vect_remove_duplicates(), Vect_snap_line(), Vedit_add_vertex(), and Vedit_merge_lines().
Remove points in threshold.
| Points | pointer to line_pnts structure |
| threshold | threshold value |
Definition at line 309 of file line.c.
References dig_prune(), and line_pnts::n_points.
Reverse the order of vertices.
| Points | pointer to line_pnts structure to be changed |
Definition at line 898 of file line.c.
References line_pnts::n_points, line_pnts::x, line_pnts::y, and line_pnts::z.
Referenced by Vedit_flip_lines().
| int Vect_line_segment | ( | const 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.
| InPoints | input line |
| start | segment number |
| end | segment number |
| OutPoints | output line |
Definition at line 517 of file line.c.
References _, G_debug(), G_warning(), NULL, Vect_append_point(), Vect_line_length(), Vect_line_prune(), Vect_point_on_line(), and Vect_reset_line().
Creates and initializes a line_pnts structure.
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.
To free allocated memory call Vect_destroy_line_struct().
Calls G_fatal_error() on error.
Definition at line 45 of file line.c.
References _, G_fatal_error(), NULL, and Vect__new_line_struct().
Referenced by Gp_load_sites(), Gv_load_vect(), I_rasterize(), IL_vector_input_data_2d(), line_check_intersection(), line_check_intersection2(), NetA_add_point_on_node(), NetA_get_node_costs(), NetA_points_to_nodes(), NetA_varray_to_nodes(), P_Aux_to_Vector(), P_estimate_splinestep(), P_Read_Vector_Region_Map(), P_Sparse_Points(), V1_rewrite_line_nat(), V2_delete_line_nat(), V2_delete_line_pg(), V2_delete_line_sfa(), V2_restore_line_nat(), V2_rewrite_line_nat(), V2_rewrite_line_pg(), V2_write_line_sfa(), Vect__copy_areas(), Vect__get_area_points_nat(), Vect__load_plus_pg(), Vect__reallocate_cache(), Vect_area_buffer2(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_build_line_area(), Vect_build_nat(), Vect_clean_small_angles_at_nodes(), Vect_find_island(), Vect_find_line_list(), Vect_get_area_area(), Vect_get_area_perimeter(), Vect_get_line_box(), Vect_get_map_box1(), Vect_get_point_in_area(), Vect_get_point_in_poly_isl(), Vect_line_buffer(), Vect_line_buffer2(), Vect_line_intersection(), Vect_line_intersection2(), Vect_merge_lines(), Vect_net_build_graph(), Vect_net_nearest_nodes(), Vect_net_ttb_build_graph(), Vect_overlay_and(), Vect_point_buffer2(), Vect_point_in_area_outer_ring(), Vect_point_in_island(), Vect_read_ascii(), Vect_read_line_to_wkb(), Vect_remove_duplicates(), Vect_remove_small_areas_ext(), Vect_remove_small_areas_nat(), Vect_select_lines_by_polygon(), Vect_snap_line(), Vect_tin_get_z(), Vect_topo_check(), Vect_write_ascii(), vector2perimeters(), 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 | ( | const 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 beginning, measured along line.
If the distance is greater than line length or negative, error is returned.
| Points | pointer to line_pnts structure |
| distance | distance value |
| x,y,z | pointers to point coordinates or NULL |
| angle | pointer to angle of line in that point (radians, counter clockwise from x axis) or NULL |
| slope | pointer to slope angle in radians (positive up) |
Definition at line 413 of file line.c.
References G_debug(), line_pnts::n_points, NULL, Vect_line_length(), line_pnts::x, line_pnts::y, and line_pnts::z.
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.
| x1,y1,z1 | first point |
| x2,y2,z2 | second point |
| with_z | use z coordinate |
Definition at line 866 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().
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().
| Points | pointer to line_pnts structure to be reset |
Definition at line 129 of file line.c.
References line_pnts::n_points.
Referenced by IL_write_point_2d(), line_check_intersection(), line_check_intersection2(), NetA_add_point_on_node(), V1_read_line_ogr(), V1_read_line_pg(), V2_read_line_pg(), V2_read_line_sfa(), V2_read_next_line_ogr(), V2_read_next_line_pg(), Vect__get_area_points_nat(), Vect__get_area_points_pg(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_clean_small_angles_at_nodes(), Vect_get_area_points(), Vect_get_isle_points(), Vect_line_buffer(), Vect_line_segment(), Vect_merge_lines(), Vect_net_nearest_nodes(), Vect_snap_line(), Vedit_merge_lines(), and Vedit_split_lines().