PostGIS  2.3.7dev-r@@SVN_REVISION@@
lwpoly.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright (C) 2012 Sandro Santilli <strk@kbt.io>
22  * Copyright (C) 2001-2006 Refractions Research Inc.
23  *
24  **********************************************************************/
25 
26 
27 /* basic LWPOLY manipulation */
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <math.h>
33 #include "liblwgeom_internal.h"
34 #include "lwgeom_log.h"
35 
36 
37 #define CHECK_POLY_RINGS_ZM 1
38 
39 /* construct a new LWPOLY. arrays (points/points per ring) will NOT be copied
40  * use SRID=SRID_UNKNOWN for unknown SRID (will have 8bit type's S = 0)
41  */
42 LWPOLY*
43 lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
44 {
45  LWPOLY *result;
46  int hasz, hasm;
47 #ifdef CHECK_POLY_RINGS_ZM
48  char zm;
49  uint32_t i;
50 #endif
51 
52  if ( nrings < 1 ) lwerror("lwpoly_construct: need at least 1 ring");
53 
54  hasz = FLAGS_GET_Z(points[0]->flags);
55  hasm = FLAGS_GET_M(points[0]->flags);
56 
57 #ifdef CHECK_POLY_RINGS_ZM
58  zm = FLAGS_GET_ZM(points[0]->flags);
59  for (i=1; i<nrings; i++)
60  {
61  if ( zm != FLAGS_GET_ZM(points[i]->flags) )
62  lwerror("lwpoly_construct: mixed dimensioned rings");
63  }
64 #endif
65 
66  result = (LWPOLY*) lwalloc(sizeof(LWPOLY));
67  result->type = POLYGONTYPE;
68  result->flags = gflags(hasz, hasm, 0);
69  FLAGS_SET_BBOX(result->flags, bbox?1:0);
70  result->srid = srid;
71  result->nrings = nrings;
72  result->maxrings = nrings;
73  result->rings = points;
74  result->bbox = bbox;
75 
76  return result;
77 }
78 
79 LWPOLY*
80 lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2,
81  POINT4D *p3, POINT4D *p4)
82 {
83  POINTARRAY *pa = ptarray_construct_empty(hasz, hasm, 5);
84  LWPOLY *lwpoly = lwpoly_construct_empty(SRID_UNKNOWN, hasz, hasm);
85 
91 
92  lwpoly_add_ring(lwpoly, pa);
93 
94  return lwpoly;
95 }
96 
97 LWPOLY*
98 lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
99 {
100  const int segments = 4*segments_per_quarter;
101  const double theta = 2*M_PI / segments;
102  LWPOLY *lwpoly;
103  POINTARRAY *pa;
104  POINT4D pt;
105  uint32_t i;
106 
107  if (segments_per_quarter < 1)
108  {
109  lwerror("Need at least one segment per quarter-circle.");
110  return NULL;
111  }
112 
113  if (radius < 0)
114  {
115  lwerror("Radius must be positive.");
116  return NULL;
117  }
118 
119  lwpoly = lwpoly_construct_empty(srid, LW_FALSE, LW_FALSE);
120  pa = ptarray_construct_empty(LW_FALSE, LW_FALSE, segments + 1);
121 
122  if (exterior)
123  radius *= sqrt(1 + pow(tan(theta/2), 2));
124 
125  for (i = 0; i <= segments; i++)
126  {
127  pt.x = x + radius*sin(i * theta);
128  pt.y = y + radius*cos(i * theta);
129  ptarray_append_point(pa, &pt, LW_TRUE);
130  }
131 
132  lwpoly_add_ring(lwpoly, pa);
133  return lwpoly;
134 }
135 
136 LWPOLY*
137 lwpoly_construct_empty(int srid, char hasz, char hasm)
138 {
139  LWPOLY *result = lwalloc(sizeof(LWPOLY));
140  result->type = POLYGONTYPE;
141  result->flags = gflags(hasz,hasm,0);
142  result->srid = srid;
143  result->nrings = 0;
144  result->maxrings = 1; /* Allocate room for ring, just in case. */
145  result->rings = lwalloc(result->maxrings * sizeof(POINTARRAY*));
146  result->bbox = NULL;
147  return result;
148 }
149 
150 void lwpoly_free(LWPOLY *poly)
151 {
152  int t;
153 
154  if( ! poly ) return;
155 
156  if ( poly->bbox )
157  lwfree(poly->bbox);
158 
159  for (t=0; t<poly->nrings; t++)
160  {
161  if ( poly->rings[t] )
162  ptarray_free(poly->rings[t]);
163  }
164 
165  if ( poly->rings )
166  lwfree(poly->rings);
167 
168  lwfree(poly);
169 }
170 
171 void printLWPOLY(LWPOLY *poly)
172 {
173  int t;
174  lwnotice("LWPOLY {");
175  lwnotice(" ndims = %i", (int)FLAGS_NDIMS(poly->flags));
176  lwnotice(" SRID = %i", (int)poly->srid);
177  lwnotice(" nrings = %i", (int)poly->nrings);
178  for (t=0; t<poly->nrings; t++)
179  {
180  lwnotice(" RING # %i :",t);
181  printPA(poly->rings[t]);
182  }
183  lwnotice("}");
184 }
185 
186 /* @brief Clone LWLINE object. Serialized point lists are not copied.
187  *
188  * @see ptarray_clone
189  */
190 LWPOLY *
192 {
193  int i;
194  LWPOLY *ret = lwalloc(sizeof(LWPOLY));
195  memcpy(ret, g, sizeof(LWPOLY));
196  ret->rings = lwalloc(sizeof(POINTARRAY *)*g->nrings);
197  for ( i = 0; i < g->nrings; i++ ) {
198  ret->rings[i] = ptarray_clone(g->rings[i]);
199  }
200  if ( g->bbox ) ret->bbox = gbox_copy(g->bbox);
201  return ret;
202 }
203 
204 /* Deep clone LWPOLY object. POINTARRAY are copied, as is ring array */
205 LWPOLY *
207 {
208  int i;
209  LWPOLY *ret = lwalloc(sizeof(LWPOLY));
210  memcpy(ret, g, sizeof(LWPOLY));
211  if ( g->bbox ) ret->bbox = gbox_copy(g->bbox);
212  ret->rings = lwalloc(sizeof(POINTARRAY *)*g->nrings);
213  for ( i = 0; i < ret->nrings; i++ )
214  {
215  ret->rings[i] = ptarray_clone_deep(g->rings[i]);
216  }
217  FLAGS_SET_READONLY(ret->flags,0);
218  return ret;
219 }
220 
224 int
226 {
227  if( ! poly || ! pa )
228  return LW_FAILURE;
229 
230  /* We have used up our storage, add some more. */
231  if( poly->nrings >= poly->maxrings )
232  {
233  int new_maxrings = 2 * (poly->nrings + 1);
234  poly->rings = lwrealloc(poly->rings, new_maxrings * sizeof(POINTARRAY*));
235  poly->maxrings = new_maxrings;
236  }
237 
238  /* Add the new ring entry. */
239  poly->rings[poly->nrings] = pa;
240  poly->nrings++;
241 
242  return LW_SUCCESS;
243 }
244 
245 void
247 {
248  int i;
249 
250  /* No-op empties */
251  if ( lwpoly_is_empty(poly) )
252  return;
253 
254  /* External ring */
255  if ( ptarray_isccw(poly->rings[0]) )
256  ptarray_reverse(poly->rings[0]);
257 
258  /* Internal rings */
259  for (i=1; i<poly->nrings; i++)
260  if ( ! ptarray_isccw(poly->rings[i]) )
261  ptarray_reverse(poly->rings[i]);
262 
263 }
264 
265 void
267 {
269 }
270 
271 void
273 {
274  int i;
275  if ( lwpoly_is_empty(poly) ) return;
276  for (i=0; i<poly->nrings; i++)
277  ptarray_reverse(poly->rings[i]);
278 }
279 
280 LWPOLY *
281 lwpoly_segmentize2d(LWPOLY *poly, double dist)
282 {
283  POINTARRAY **newrings;
284  uint32_t i;
285 
286  newrings = lwalloc(sizeof(POINTARRAY *)*poly->nrings);
287  for (i=0; i<poly->nrings; i++)
288  {
289  newrings[i] = ptarray_segmentize2d(poly->rings[i], dist);
290  if ( ! newrings[i] ) {
291  while (i--) ptarray_free(newrings[i]);
292  lwfree(newrings);
293  return NULL;
294  }
295  }
296  return lwpoly_construct(poly->srid, NULL,
297  poly->nrings, newrings);
298 }
299 
300 /*
301  * check coordinate equality
302  * ring and coordinate order is considered
303  */
304 char
305 lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
306 {
307  uint32_t i;
308 
309  if ( p1->nrings != p2->nrings ) return 0;
310  for (i=0; i<p1->nrings; i++)
311  {
312  if ( ! ptarray_same(p1->rings[i], p2->rings[i]) )
313  return 0;
314  }
315  return 1;
316 }
317 
318 /*
319  * Construct a polygon from a LWLINE being
320  * the shell and an array of LWLINE (possibly NULL) being holes.
321  * Pointarrays from intput geoms are cloned.
322  * SRID must be the same for each input line.
323  * Input lines must have at least 4 points, and be closed.
324  */
325 LWPOLY *
327  uint32_t nholes, const LWLINE **holes)
328 {
329  uint32_t nrings;
330  POINTARRAY **rings = lwalloc((nholes+1)*sizeof(POINTARRAY *));
331  int srid = shell->srid;
332  LWPOLY *ret;
333 
334  if ( shell->points->npoints < 4 )
335  lwerror("lwpoly_from_lwlines: shell must have at least 4 points");
336  if ( ! ptarray_is_closed_2d(shell->points) )
337  lwerror("lwpoly_from_lwlines: shell must be closed");
338  rings[0] = ptarray_clone_deep(shell->points);
339 
340  for (nrings=1; nrings<=nholes; nrings++)
341  {
342  const LWLINE *hole = holes[nrings-1];
343 
344  if ( hole->srid != srid )
345  lwerror("lwpoly_from_lwlines: mixed SRIDs in input lines");
346 
347  if ( hole->points->npoints < 4 )
348  lwerror("lwpoly_from_lwlines: holes must have at least 4 points");
349  if ( ! ptarray_is_closed_2d(hole->points) )
350  lwerror("lwpoly_from_lwlines: holes must be closed");
351 
352  rings[nrings] = ptarray_clone_deep(hole->points);
353  }
354 
355  ret = lwpoly_construct(srid, NULL, nrings, rings);
356  return ret;
357 }
358 
359 LWGEOM*
360 lwpoly_remove_repeated_points(const LWPOLY *poly, double tolerance)
361 {
362  uint32_t i;
363  POINTARRAY **newrings;
364 
365  newrings = lwalloc(sizeof(POINTARRAY *)*poly->nrings);
366  for (i=0; i<poly->nrings; i++)
367  {
368  newrings[i] = ptarray_remove_repeated_points_minpoints(poly->rings[i], tolerance, 4);
369  }
370 
371  return (LWGEOM*)lwpoly_construct(poly->srid,
372  poly->bbox ? gbox_copy(poly->bbox) : NULL,
373  poly->nrings, newrings);
374 
375 }
376 
377 
378 LWPOLY*
379 lwpoly_force_dims(const LWPOLY *poly, int hasz, int hasm)
380 {
381  LWPOLY *polyout;
382 
383  /* Return 2D empty */
384  if( lwpoly_is_empty(poly) )
385  {
386  polyout = lwpoly_construct_empty(poly->srid, hasz, hasm);
387  }
388  else
389  {
390  POINTARRAY **rings = NULL;
391  int i;
392  rings = lwalloc(sizeof(POINTARRAY*) * poly->nrings);
393  for( i = 0; i < poly->nrings; i++ )
394  {
395  rings[i] = ptarray_force_dims(poly->rings[i], hasz, hasm);
396  }
397  polyout = lwpoly_construct(poly->srid, NULL, poly->nrings, rings);
398  }
399  polyout->type = poly->type;
400  return polyout;
401 }
402 
403 int lwpoly_is_empty(const LWPOLY *poly)
404 {
405  if ( (poly->nrings < 1) || (!poly->rings) || (!poly->rings[0]) || (poly->rings[0]->npoints < 1) )
406  return LW_TRUE;
407  return LW_FALSE;
408 }
409 
411 {
412  int i = 0;
413  int v = 0; /* vertices */
414  assert(poly);
415  for ( i = 0; i < poly->nrings; i ++ )
416  {
417  v += poly->rings[i]->npoints;
418  }
419  return v;
420 }
421 
422 LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed)
423 {
424  int i;
425  LWPOLY *opoly = lwpoly_construct_empty(ipoly->srid, FLAGS_GET_Z(ipoly->flags), FLAGS_GET_M(ipoly->flags));
426 
427  LWDEBUGF(2, "%s: simplifying polygon with %d rings", __func__, ipoly->nrings);
428 
429  if ( lwpoly_is_empty(ipoly) )
430  {
431  lwpoly_free(opoly);
432  return NULL;
433  }
434 
435  for ( i = 0; i < ipoly->nrings; i++ )
436  {
437  POINTARRAY *opts;
438  int minvertices = 0;
439 
440  /* We'll still let holes collapse, but if we're preserving */
441  /* and this is a shell, we ensure it is kept */
442  if ( preserve_collapsed && i == 0 )
443  minvertices = 4;
444 
445  opts = ptarray_simplify(ipoly->rings[i], dist, minvertices);
446 
447  LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
448 
449  /* Less points than are needed to form a closed ring, we can't use this */
450  if ( opts->npoints < 4 )
451  {
452  LWDEBUGF(3, "ring%d skipped (% pts)", i, opts->npoints);
453  ptarray_free(opts);
454  if ( i ) continue;
455  else break; /* Don't scan holes if shell is collapsed */
456  }
457 
458  /* Add ring to simplified polygon */
459  if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
460  {
461  lwpoly_free(opoly);
462  return NULL;
463  }
464  }
465 
466  LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
467  opoly->type = ipoly->type;
468 
469  if( lwpoly_is_empty(opoly) )
470  {
471  lwpoly_free(opoly);
472  return NULL;
473  }
474 
475  return opoly;
476 }
477 
481 double
482 lwpoly_area(const LWPOLY *poly)
483 {
484  double poly_area = 0.0;
485  int i;
486 
487  if ( ! poly )
488  lwerror("lwpoly_area called with null polygon pointer!");
489 
490  for ( i=0; i < poly->nrings; i++ )
491  {
492  POINTARRAY *ring = poly->rings[i];
493  double ringarea = 0.0;
494 
495  /* Empty or messed-up ring. */
496  if ( ring->npoints < 3 )
497  continue;
498 
499  ringarea = fabs(ptarray_signed_area(ring));
500  if ( i == 0 ) /* Outer ring, positive area! */
501  poly_area += ringarea;
502  else /* Inner ring, negative area! */
503  poly_area -= ringarea;
504  }
505 
506  return poly_area;
507 }
508 
509 
514 double
516 {
517  double result=0.0;
518  int i;
519 
520  LWDEBUGF(2, "in lwgeom_polygon_perimeter (%d rings)", poly->nrings);
521 
522  for (i=0; i<poly->nrings; i++)
523  result += ptarray_length(poly->rings[i]);
524 
525  return result;
526 }
527 
532 double
534 {
535  double result=0.0;
536  int i;
537 
538  LWDEBUGF(2, "in lwgeom_polygon_perimeter (%d rings)", poly->nrings);
539 
540  for (i=0; i<poly->nrings; i++)
541  result += ptarray_length_2d(poly->rings[i]);
542 
543  return result;
544 }
545 
546 int
548 {
549  int i = 0;
550 
551  if ( poly->nrings == 0 )
552  return LW_TRUE;
553 
554  for ( i = 0; i < poly->nrings; i++ )
555  {
556  if (FLAGS_GET_Z(poly->flags))
557  {
558  if ( ! ptarray_is_closed_3d(poly->rings[i]) )
559  return LW_FALSE;
560  }
561  else
562  {
563  if ( ! ptarray_is_closed_2d(poly->rings[i]) )
564  return LW_FALSE;
565  }
566  }
567 
568  return LW_TRUE;
569 }
570 
571 int
573 {
574  if ( poly->nrings < 1 )
575  return LW_FAILURE;
576  return ptarray_startpoint(poly->rings[0], pt);
577 }
578 
579 int
580 lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
581 {
582  int i;
583 
584  if ( lwpoly_is_empty(poly) )
585  return LW_FALSE;
586 
587  if ( ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE )
588  return LW_FALSE;
589 
590  for ( i = 1; i < poly->nrings; i++ )
591  {
592  if ( ptarray_contains_point(poly->rings[i], pt) == LW_INSIDE )
593  return LW_FALSE;
594  }
595  return LW_TRUE;
596 }
597 
598 
599 
600 LWPOLY* lwpoly_grid(const LWPOLY *poly, const gridspec *grid)
601 {
602  LWPOLY *opoly;
603  int ri;
604 
605 #if 0
606  /*
607  * TODO: control this assertion
608  * it is assumed that, since the grid size will be a pixel,
609  * a visible ring should show at least a white pixel inside,
610  * thus, for a square, that would be grid_xsize*grid_ysize
611  */
612  double minvisiblearea = grid->xsize * grid->ysize;
613 #endif
614 
615  LWDEBUGF(3, "lwpoly_grid: applying grid to polygon with %d rings", poly->nrings);
616 
617  opoly = lwpoly_construct_empty(poly->srid, lwgeom_has_z((LWGEOM*)poly), lwgeom_has_m((LWGEOM*)poly));
618 
619  for (ri=0; ri<poly->nrings; ri++)
620  {
621  POINTARRAY *ring = poly->rings[ri];
622  POINTARRAY *newring;
623 
624  newring = ptarray_grid(ring, grid);
625 
626  /* Skip ring if not composed by at least 4 pts (3 segments) */
627  if ( newring->npoints < 4 )
628  {
629  ptarray_free(newring);
630 
631  LWDEBUGF(3, "grid_polygon3d: ring%d skipped ( <4 pts )", ri);
632 
633  if ( ri ) continue;
634  else break; /* this is the external ring, no need to work on holes */
635  }
636 
637  if ( ! lwpoly_add_ring(opoly, newring) )
638  {
639  lwerror("lwpoly_grid, memory error");
640  return NULL;
641  }
642  }
643 
644  LWDEBUGF(3, "lwpoly_grid: simplified polygon with %d rings", opoly->nrings);
645 
646  if ( ! opoly->nrings )
647  {
648  lwpoly_free(opoly);
649  return NULL;
650  }
651 
652  return opoly;
653 }
double x
Definition: liblwgeom.h:351
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
LWPOLY * lwpoly_grid(const LWPOLY *poly, const gridspec *grid)
Definition: lwpoly.c:600
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
Definition: ptarray.c:658
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition: lwpoly.c:482
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:89
void lwfree(void *mem)
Definition: lwutil.c:242
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:266
int npoints
Definition: liblwgeom.h:370
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:707
#define POLYGONTYPE
Definition: liblwgeom.h:86
LWGEOM * lwpoly_remove_repeated_points(const LWPOLY *poly, double tolerance)
Definition: lwpoly.c:360
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
Definition: lwpoly.c:515
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1645
#define LW_SUCCESS
Definition: liblwgeom.h:79
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...
Definition: ptarray.c:420
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:171
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:152
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
Definition: lwpoly.c:225
GBOX * bbox
Definition: liblwgeom.h:452
int32_t srid
Definition: liblwgeom.h:420
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
Definition: lwpoly.c:533
LWPOLY * lwpoly_clone(const LWPOLY *g)
Definition: lwpoly.c:191
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:995
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:849
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:252
#define LW_FAILURE
Definition: liblwgeom.h:78
int lwpoly_is_closed(const LWPOLY *poly)
Definition: lwpoly.c:547
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
Definition: lwpoly.c:305
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
int ptarray_isccw(const POINTARRAY *pa)
Definition: ptarray.c:1026
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.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:76
uint8_t type
Definition: liblwgeom.h:450
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:137
POINTARRAY ** rings
Definition: liblwgeom.h:456
LWPOLY * lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed)
Definition: lwpoly.c:422
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:634
#define LW_INSIDE
Constants for point-in-polygon return values.
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
Definition: ptarray.c:1035
int nrings
Definition: liblwgeom.h:454
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
Definition: lwpoly.c:580
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:326
LWPOLY * lwpoly_clone_deep(const LWPOLY *g)
Definition: lwpoly.c:206
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
tuple x
Definition: pixval.py:53
void lwpoly_reverse(LWPOLY *poly)
Definition: lwpoly.c:272
LWPOLY * lwpoly_force_dims(const LWPOLY *poly, int hasz, int hasm)
Definition: lwpoly.c:379
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
int lwpoly_startpoint(const LWPOLY *poly, POINT4D *pt)
Definition: lwpoly.c:572
LWPOLY * lwpoly_segmentize2d(LWPOLY *poly, double dist)
Definition: lwpoly.c:281
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
Definition: ptarray.c:1826
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
Definition: ptarray.c:1673
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1554
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:147
int maxrings
Definition: liblwgeom.h:455
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:98
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:611
int32_t srid
Definition: liblwgeom.h:453
int lwpoly_count_vertices(LWPOLY *poly)
Definition: lwpoly.c:410
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:484
POINTARRAY * ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints)
Definition: ptarray.c:1437
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:150
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1843
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
void ptarray_reverse(POINTARRAY *pa)
Definition: ptarray.c:343
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:385
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...
Definition: ptarray.c:733
void lwpoly_force_clockwise(LWPOLY *poly)
Definition: lwpoly.c:246
uint8_t flags
Definition: liblwgeom.h:451
#define LW_OUTSIDE
void * lwalloc(size_t size)
Definition: lwutil.c:227
double y
Definition: liblwgeom.h:351
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:151
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:856
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
tuple y
Definition: pixval.py:54
int lwpoly_is_empty(const LWPOLY *poly)
Definition: lwpoly.c:403
#define FLAGS_SET_READONLY(flags, value)
Definition: liblwgeom.h:149
POINTARRAY * points
Definition: liblwgeom.h:421
Snap to grid.