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 uint32_t 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);
185 for (t = 0; t < poly->
nrings; t++)
200 for (t=0; t<poly->
nrings; t++)
217 memcpy(ret, g,
sizeof(
LWPOLY));
219 for ( i = 0; i < g->
nrings; i++ ) {
232 memcpy(ret, g,
sizeof(
LWPOLY));
235 for ( i = 0; i < ret->
nrings; i++ )
255 int new_maxrings = 2 * (poly->
nrings + 1);
281 for (i=1; i<poly->
nrings; i++)
298 for ( i = 1; i < poly->
nrings; i++)
318 for (i=0; i<poly->
nrings; i++)
324 for (j = 0; j < i; j++)
344 for (i=0; i<p1->
nrings; i++)
365 int srid = shell->
srid;
369 lwerror(
"lwpoly_from_lwlines: shell must have at least 4 points");
371 lwerror(
"lwpoly_from_lwlines: shell must be closed");
374 for (nrings=1; nrings<=nholes; nrings++)
376 const LWLINE *hole = holes[nrings-1];
378 if ( hole->
srid != srid )
379 lwerror(
"lwpoly_from_lwlines: mixed SRIDs in input lines");
382 lwerror(
"lwpoly_from_lwlines: holes must have at least 4 points");
384 lwerror(
"lwpoly_from_lwlines: holes must be closed");
408 for( i = 0; i < poly->
nrings; i++ )
430 for ( i = 0; i < poly->
nrings; i ++ )
443 double poly_area = 0.0;
447 lwerror(
"lwpoly_area called with null polygon pointer!");
449 for ( i=0; i < poly->
nrings; i++ )
452 double ringarea = 0.0;
460 poly_area += ringarea;
462 poly_area -= ringarea;
479 LWDEBUGF(2,
"in lwgeom_polygon_perimeter (%d rings)", poly->
nrings);
481 for (i=0; i<poly->
nrings; i++)
497 LWDEBUGF(2,
"in lwgeom_polygon_perimeter (%d rings)", poly->
nrings);
499 for (i=0; i<poly->
nrings; i++)
513 for ( i = 0; i < poly->
nrings; i++ )
549 for ( i = 1; i < poly->
nrings; i++ )
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
int ptarray_is_closed_3d(const POINTARRAY *pa)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
#define FLAGS_SET_BBOX(flags, value)
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
void printPA(POINTARRAY *pa)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
void * lwrealloc(void *mem, size_t size)
#define FLAGS_NDIMS(flags)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
#define FLAGS_GET_M(flags)
void ptarray_free(POINTARRAY *pa)
#define FLAGS_GET_ZM(flags)
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,...
void * lwalloc(size_t size)
#define FLAGS_SET_READONLY(flags, value)
int ptarray_is_closed_2d(const POINTARRAY *pa)
#define LW_TRUE
Return types for functions with status returns.
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
#define SRID_UNKNOWN
Unknown SRID value.
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 lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
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...
#define LW_INSIDE
Constants for point-in-polygon return values.
void ptarray_reverse_in_place(POINTARRAY *pa)
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
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.
int ptarray_isccw(const POINTARRAY *pa)
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
LWPOLY * lwpoly_clone_deep(const LWPOLY *g)
int lwpoly_startpoint(const LWPOLY *poly, POINT4D *pt)
uint32_t lwpoly_count_vertices(LWPOLY *poly)
void printLWPOLY(LWPOLY *poly)
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
int lwpoly_is_clockwise(LWPOLY *poly)
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
LWPOLY * lwpoly_force_dims(const LWPOLY *poly, int hasz, int hasm)
int lwpoly_is_empty(const LWPOLY *poly)
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
void lwpoly_release(LWPOLY *lwpoly)
void lwpoly_force_clockwise(LWPOLY *poly)
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
LWPOLY * lwpoly_segmentize2d(const LWPOLY *poly, double dist)
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
void lwpoly_free(LWPOLY *poly)
LWPOLY * lwpoly_clone(const LWPOLY *g)
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
int lwpoly_is_closed(const LWPOLY *poly)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.