GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
poly.c File Reference

Vector library - polygon related fns. More...

#include <math.h>
#include <stdlib.h>
#include <grass/vector.h>
#include <grass/linkm.h>
#include <grass/glocale.h>
Include dependency graph for Vlib/poly.c:

Go to the source code of this file.

Macros

#define FP_AVG(A, B)
 

Functions

int Vect__intersect_y_line_with_poly (const struct line_pnts *, double, struct line_pnts *)
 
int Vect__intersect_x_line_with_poly (const struct line_pnts *, double, struct line_pnts *)
 
int Vect_get_point_in_area (struct Map_info *Map, int area, double *X, double *Y)
 Get point inside area and outside all islands.
 
int Vect_get_point_in_poly (const struct line_pnts *Points, double *X, double *Y)
 Get point inside polygon.
 
int Vect_find_poly_centroid (const struct line_pnts *points, double *cent_x, double *cent_y)
 Get centroid of polygon.
 
int Vect_find_poly_centroid_cog (const struct line_pnts *Points, const struct line_pnts **IPoints, int n_isles, double *cent_x, double *cent_y)
 Get centroid of polygon.
 
int Vect_get_point_in_poly_isl (const struct line_pnts *Points, const struct line_pnts **IPoints, int n_isles, double *att_x, double *att_y)
 Get point inside polygon but outside the islands specifiled in IPoints.
 
int Vect_point_in_poly (double X, double Y, const struct line_pnts *Points)
 Determines if a point (X,Y) is inside a polygon.
 
int Vect_point_in_area_outer_ring (double X, double Y, struct Map_info *Map, int area, struct bound_box *box)
 Determines if a point (X,Y) is inside an area outer ring. Islands are not considered.
 
int Vect_point_in_island (double X, double Y, struct Map_info *Map, int isle, struct bound_box *box)
 Determines if a point (X,Y) is inside an island.
 

Detailed Description

Vector library - polygon related fns.

Higher level functions for reading/writing/manipulating vectors.

SPDX-FileCopyrightText: 2001-2009 GRASS Development Team SPDX-License-Identifier: GPL-2.0-or-later

Author
Original author CERL, probably Dave Gerdes or Mike Higgins.
Update to GRASS 5.7 Radim Blazek and David D. Gray.

Definition in file Vlib/poly.c.

Macro Definition Documentation

◆ FP_AVG

#define FP_AVG (   A,
 
)
Value:
(((A) > 0 && (B) < 0) || ((A) < 0 && (B) > 0) ? (((A) + (B)) / 2.) \
: ((A) + ((B) - (A)) / 2.))

Definition at line 23 of file Vlib/poly.c.

Function Documentation

◆ Vect__intersect_x_line_with_poly()

int Vect__intersect_x_line_with_poly ( const struct line_pnts Points,
double  x,
struct line_pnts Inter 
)

Definition at line 185 of file Vlib/poly.c.

References b, line_pnts::n_points, Vect_append_point(), line_pnts::x, and line_pnts::y.

Referenced by Vect_get_point_in_poly_isl().

◆ Vect__intersect_y_line_with_poly()

int Vect__intersect_y_line_with_poly ( const struct line_pnts Points,
double  y,
struct line_pnts Inter 
)

Definition at line 130 of file Vlib/poly.c.

References b, line_pnts::n_points, Vect_append_point(), line_pnts::x, and line_pnts::y.

Referenced by Vect_get_point_in_poly_isl().

◆ Vect_find_poly_centroid()

int Vect_find_poly_centroid ( const struct line_pnts points,
double cent_x,
double cent_y 
)

Get centroid of polygon.

Parameters
pointspolygon
[out]cent_x,cent_ycentroid coordinates
Returns
0 on success
-1 on error

Definition at line 383 of file Vlib/poly.c.

References line_pnts::n_points, line_pnts::x, and line_pnts::y.

Referenced by Vect_get_point_in_poly(), and Vect_get_point_in_poly_isl().

◆ Vect_find_poly_centroid_cog()

int Vect_find_poly_centroid_cog ( const struct line_pnts Points,
const struct line_pnts **  IPoints,
int  n_isles,
double cent_x,
double cent_y 
)

Get centroid of polygon.

Calculate the center of gravity of the area considering any islands

Parameters
Pointspolygon
IPointsisles (list of isle boundaries)
n_islesnumber of isles
[out]cent_x,cent_ycentroid coordinates
Returns
0 on success
-1 on error
Since
version 8.6

Definition at line 437 of file Vlib/poly.c.

References bound_box::E, bound_box::N, line_pnts::n_points, bound_box::S, Vect_line_box(), bound_box::W, line_pnts::x, x, and line_pnts::y.

Referenced by Vect_get_point_in_poly_isl().

◆ Vect_get_point_in_area()

int Vect_get_point_in_area ( struct Map_info Map,
int  area,
double X,
double Y 
)

Get point inside area and outside all islands.

Take a line and intersect it with the polygon and any islands. sort the list of X values from these intersections. This will be a list of segments alternating IN/OUT/IN/OUT of the polygon. Pick the largest IN segment and take the midpoint.

Parameters
Mapvector map
areaarea id
[out]X,Ypoint coordinateds
Returns
0 on success
-1 on error

Definition at line 59 of file Vlib/poly.c.

References G_debug(), G_realloc, NULL, Vect_get_area_isle(), Vect_get_area_num_isles(), Vect_get_area_points(), Vect_get_isle_points(), Vect_get_point_in_poly_isl(), Vect_new_line_struct(), X, and Y.

◆ Vect_get_point_in_poly()

int Vect_get_point_in_poly ( const struct line_pnts Points,
double X,
double Y 
)

Get point inside polygon.

This does NOT consider ISLANDS!

Parameters
Pointspolygon
[out]X,Ypoint coordinates
Returns
0 on success
-1 on error

Definition at line 236 of file Vlib/poly.c.

References _, G_debug(), G_warning(), link_exit_on_error(), link_init(), link_new(), line_pnts::n_points, NULL, Vect_find_poly_centroid(), Vect_point_in_poly(), X, line_pnts::x, x, and Y.

Referenced by V2_write_line_sfa().

◆ Vect_get_point_in_poly_isl()

int Vect_get_point_in_poly_isl ( const struct line_pnts Points,
const struct line_pnts **  IPoints,
int  n_isles,
double att_x,
double att_y 
)

Get point inside polygon but outside the islands specifiled in IPoints.

Take a line and intersect it with the polygon and any islands. sort the list of X values from these intersections. This will be a list of segments alternating IN/OUT/IN/OUT of the polygon. Pick the largest IN segment and take the midpoint.

Parameters
Pointspolygon (boundary)
IPointsisles (list of isle boundaries)
n_islesnumber of isles
[out]att_x,att_ypoint coordinates
Returns
0 on success
-1 on error

Definition at line 545 of file Vlib/poly.c.

References FP_AVG, G_debug(), G_warning(), max, line_pnts::n_points, Vect__intersect_x_line_with_poly(), Vect__intersect_y_line_with_poly(), Vect_find_poly_centroid(), Vect_find_poly_centroid_cog(), Vect_new_line_struct(), Vect_point_in_poly(), line_pnts::x, and line_pnts::y.

Referenced by Vect_get_point_in_area().

◆ Vect_point_in_area_outer_ring()

int Vect_point_in_area_outer_ring ( double  X,
double  Y,
struct Map_info Map,
int  area,
struct bound_box box 
)

Determines if a point (X,Y) is inside an area outer ring. Islands are not considered.

Parameters
X,Ypoint coordinates
Mapvector map
areaarea id
boxarea bounding box
Returns
0 - outside
1 - inside
2 - on the boundary

Definition at line 1007 of file Vlib/poly.c.

References bound_box::E, G_debug(), bound_box::N, Vect_get_area_points(), Vect_new_line_struct(), Vect_point_in_poly(), W, X, and Y.

Referenced by Vect_find_area(), Vect_isle_find_area(), and Vect_point_in_area().

◆ Vect_point_in_island()

int Vect_point_in_island ( double  X,
double  Y,
struct Map_info Map,
int  isle,
struct bound_box box 
)

Determines if a point (X,Y) is inside an island.

Parameters
X,Ypoint coordinates
Mapvector map
isleisle id
boxisle bounding box
Returns
0 - outside
1 - inside
2 - on the boundary

Definition at line 1045 of file Vlib/poly.c.

References bound_box::E, G_debug(), bound_box::N, Vect_get_isle_points(), Vect_new_line_struct(), Vect_point_in_poly(), W, X, and Y.

Referenced by Vect_find_area(), Vect_find_island(), and Vect_point_in_area().

◆ Vect_point_in_poly()

int Vect_point_in_poly ( double  X,
double  Y,
const struct line_pnts Points 
)

Determines if a point (X,Y) is inside a polygon.

Parameters
X,Ypoint coordinates
Pointspolygon
Returns
0 - outside
1 - inside
2 - on the boundary

Definition at line 977 of file Vlib/poly.c.

References G_debug(), line_pnts::n_points, X, and Y.

Referenced by Vect_get_point_in_poly(), Vect_get_point_in_poly_isl(), Vect_point_in_area_outer_ring(), Vect_point_in_island(), and Vect_select_lines_by_polygon().