37 #define CHECK_POLY_RINGS_ZM 1 47 #ifdef CHECK_POLY_RINGS_ZM 52 if ( nrings < 1 )
lwerror(
"lwpoly_construct: need at least 1 ring");
57 #ifdef CHECK_POLY_RINGS_ZM 59 for (i=1; i<nrings; i++)
62 lwerror(
"lwpoly_construct: mixed dimensioned rings");
73 result->
rings = points;
122 const int segments = 4*segments_per_quarter;
129 if (segments_per_quarter == 0)
131 lwerror(
"Need at least one segment per quarter-circle.");
137 lwerror(
"Radius must be positive.");
141 theta = 2*M_PI / segments;
147 radius *= sqrt(1 + pow(tan(theta/2), 2));
149 for (i = 0; i <= segments; i++)
151 pt.
x = x + radius*sin(i * theta);
152 pt.
y = y + radius*cos(i * theta);
183 for (t=0; t<poly->
nrings; t++)
185 if ( poly->
rings[t] )
202 for (t=0; t<poly->
nrings; t++)
219 memcpy(ret, g,
sizeof(
LWPOLY));
221 for ( i = 0; i < g->
nrings; i++ ) {
234 memcpy(ret, g,
sizeof(
LWPOLY));
237 for ( i = 0; i < ret->
nrings; i++ )
257 int new_maxrings = 2 * (poly->
nrings + 1);
283 for (i=1; i<poly->
nrings; i++)
300 for ( i = 1; i < poly->
nrings; i++)
318 for (i=0; i<poly->
nrings; i++)
329 for (i=0; i<poly->
nrings; i++)
332 if ( ! newrings[i] ) {
352 for (i=0; i<p1->
nrings; i++)
373 int srid = shell->
srid;
377 lwerror(
"lwpoly_from_lwlines: shell must have at least 4 points");
379 lwerror(
"lwpoly_from_lwlines: shell must be closed");
382 for (nrings=1; nrings<=nholes; nrings++)
384 const LWLINE *hole = holes[nrings-1];
386 if ( hole->
srid != srid )
387 lwerror(
"lwpoly_from_lwlines: mixed SRIDs in input lines");
390 lwerror(
"lwpoly_from_lwlines: holes must have at least 4 points");
392 lwerror(
"lwpoly_from_lwlines: holes must be closed");
408 for (i=0; i<poly->
nrings; i++)
435 for( i = 0; i < poly->
nrings; i++ )
457 for ( i = 0; i < poly->
nrings; i ++ )
469 LWDEBUGF(2,
"%s: simplifying polygon with %d rings", __func__, ipoly->
nrings);
477 for ( i = 0; i < ipoly->
nrings; i++ )
484 if ( preserve_collapsed && i == 0 )
526 double poly_area = 0.0;
530 lwerror(
"lwpoly_area called with null polygon pointer!");
532 for ( i=0; i < poly->
nrings; i++ )
535 double ringarea = 0.0;
543 poly_area += ringarea;
545 poly_area -= ringarea;
562 LWDEBUGF(2,
"in lwgeom_polygon_perimeter (%d rings)", poly->
nrings);
564 for (i=0; i<poly->
nrings; i++)
580 LWDEBUGF(2,
"in lwgeom_polygon_perimeter (%d rings)", poly->
nrings);
582 for (i=0; i<poly->
nrings; i++)
596 for ( i = 0; i < poly->
nrings; i++ )
632 for ( i = 1; i < poly->
nrings; i++ )
654 double minvisiblearea = grid->
xsize * grid->
ysize;
657 LWDEBUGF(3,
"lwpoly_grid: applying grid to polygon with %d rings", poly->
nrings);
661 for (ri=0; ri<poly->nrings; ri++)
673 LWDEBUGF(3,
"grid_polygon3d: ring%d skipped ( <4 pts )", ri);
681 lwerror(
"lwpoly_grid, memory error");
686 LWDEBUGF(3,
"lwpoly_grid: simplified polygon with %d rings", opoly->
nrings);
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
LWPOLY * lwpoly_grid(const LWPOLY *poly, const gridspec *grid)
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
void lwpoly_release(LWPOLY *lwpoly)
int ptarray_is_closed_3d(const POINTARRAY *pa)
LWGEOM * lwpoly_remove_repeated_points(const LWPOLY *poly, double tolerance)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void ptarray_free(POINTARRAY *pa)
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
POINTARRAY * ptarray_segmentize2d(const POINTARRAY *ipa, double dist)
Returns a modified POINTARRAY so that no segment is longer than the given distance (computed using 2d...
void printLWPOLY(LWPOLY *poly)
#define FLAGS_GET_ZM(flags)
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
LWPOLY * lwpoly_clone(const LWPOLY *g)
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
int ptarray_is_closed_2d(const POINTARRAY *pa)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
int lwpoly_is_closed(const LWPOLY *poly)
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
int lwpoly_is_clockwise(LWPOLY *poly)
int ptarray_isccw(const POINTARRAY *pa)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
LWPOLY * lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed)
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
#define LW_INSIDE
Constants for point-in-polygon return values.
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
LWPOLY * lwpoly_clone_deep(const LWPOLY *g)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
void lwpoly_reverse(LWPOLY *poly)
LWPOLY * lwpoly_force_dims(const LWPOLY *poly, int hasz, int hasm)
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
int lwpoly_startpoint(const LWPOLY *poly, POINT4D *pt)
LWPOLY * lwpoly_segmentize2d(LWPOLY *poly, double dist)
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
#define FLAGS_SET_BBOX(flags, value)
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
void printPA(POINTARRAY *pa)
int lwpoly_count_vertices(LWPOLY *poly)
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
POINTARRAY * ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints)
void lwpoly_free(LWPOLY *poly)
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
void * lwrealloc(void *mem, size_t size)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
void ptarray_reverse(POINTARRAY *pa)
#define FLAGS_GET_M(flags)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary...
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
void lwpoly_force_clockwise(LWPOLY *poly)
void * lwalloc(size_t size)
#define LWDEBUGF(level, msg,...)
#define FLAGS_NDIMS(flags)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
int lwpoly_is_empty(const LWPOLY *poly)
#define FLAGS_SET_READONLY(flags, value)