PostGIS  2.5.0dev-r@@SVN_REVISION@@
liblwgeom.h
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 2011 Sandro Santilli <strk@kbt.io>
22  * Copyright 2011 Paul Ramsey <pramsey@cleverelephant.ca>
23  * Copyright 2007-2008 Mark Cave-Ayland
24  * Copyright 2001-2006 Refractions Research Inc.
25  *
26  **********************************************************************/
27 
28 
29 #ifndef _LIBLWGEOM_H
30 #define _LIBLWGEOM_H 1
31 
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <stdint.h>
35 #include "proj_api.h"
36 
37 #if defined(PJ_VERSION) && PJ_VERSION >= 490
38 /* Enable new geodesic functions */
39 #define PROJ_GEODESIC 1
40 #else
41 /* Use the old (pre-2.2) geodesic functions */
42 #define PROJ_GEODESIC 0
43 #endif
44 
64 #define LIBLWGEOM_VERSION "2.5.0dev"
65 #define LIBLWGEOM_VERSION_MAJOR "2"
66 #define LIBLWGEOM_VERSION_MINOR "5"
67 #define LIBLWGEOM_GEOS_VERSION "37"
68 
70 const char* lwgeom_version(void);
71 
75 #define LW_TRUE 1
76 #define LW_FALSE 0
77 #define LW_UNKNOWN 2
78 #define LW_FAILURE 0
79 #define LW_SUCCESS 1
80 
84 #define POINTTYPE 1
85 #define LINETYPE 2
86 #define POLYGONTYPE 3
87 #define MULTIPOINTTYPE 4
88 #define MULTILINETYPE 5
89 #define MULTIPOLYGONTYPE 6
90 #define COLLECTIONTYPE 7
91 #define CIRCSTRINGTYPE 8
92 #define COMPOUNDTYPE 9
93 #define CURVEPOLYTYPE 10
94 #define MULTICURVETYPE 11
95 #define MULTISURFACETYPE 12
96 #define POLYHEDRALSURFACETYPE 13
97 #define TRIANGLETYPE 14
98 #define TINTYPE 15
99 
100 #define NUMTYPES 16
101 
106 #define WKBZOFFSET 0x80000000
107 #define WKBMOFFSET 0x40000000
108 #define WKBSRIDFLAG 0x20000000
109 #define WKBBBOXFLAG 0x10000000
110 
112 typedef enum LWORD_T {
113  LWORD_X = 0,
114  LWORD_Y = 1,
115  LWORD_Z = 2,
117 } LWORD;
118 
119 /**********************************************************************
120 ** Spherical radius.
121 ** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
122 ** the XVII General Assembly of the IUGG in Canberra.
123 ** http://en.wikipedia.org/wiki/Earth_radius
124 ** http://en.wikipedia.org/wiki/World_Geodetic_System
125 */
126 
127 #define WGS84_MAJOR_AXIS 6378137.0
128 #define WGS84_INVERSE_FLATTENING 298.257223563
129 #define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
130 #define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
131 
132 
139 #define FLAGS_GET_Z(flags) ((flags) & 0x01)
140 #define FLAGS_GET_M(flags) (((flags) & 0x02)>>1)
141 #define FLAGS_GET_BBOX(flags) (((flags) & 0x04)>>2)
142 #define FLAGS_GET_GEODETIC(flags) (((flags) & 0x08)>>3)
143 #define FLAGS_GET_READONLY(flags) (((flags) & 0x10)>>4)
144 #define FLAGS_GET_SOLID(flags) (((flags) & 0x20)>>5)
145 #define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | 0x01) : ((flags) & 0xFE))
146 #define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | 0x02) : ((flags) & 0xFD))
147 #define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | 0x04) : ((flags) & 0xFB))
148 #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | 0x08) : ((flags) & 0xF7))
149 #define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | 0x10) : ((flags) & 0xEF))
150 #define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | 0x20) : ((flags) & 0xDF))
151 #define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
152 #define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
153 #define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
154 
164 #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
165 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
166 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
167 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
168 #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
169 #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
170 #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
171 #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
172 #define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
173 
178 #define SRID_MAXIMUM 999999
179 
184 #define SRID_USER_MAXIMUM 998999
185 
187 #define SRID_UNKNOWN 0
188 #define SRID_IS_UNKNOWN(x) ((int)x<=0)
189 
190 /*
191 ** EPSG WGS84 geographics, OGC standard default SRS, better be in
192 ** the SPATIAL_REF_SYS table!
193 */
194 #define SRID_DEFAULT 4326
195 
196 #ifndef __GNUC__
197 # define __attribute__(x)
198 #endif
199 
206 extern int clamp_srid(int srid);
207 
208 /* Raise an lwerror if srids do not match */
209 void error_if_srid_mismatch(int srid1, int srid2);
210 
214 typedef void* (*lwallocator)(size_t size);
215 typedef void* (*lwreallocator)(void *mem, size_t size);
216 typedef void (*lwfreeor)(void* mem);
217 typedef void (*lwreporter)(const char* fmt, va_list ap)
218  __attribute__ (( format(printf, 1, 0) ));
219 typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
220  __attribute__ (( format(printf, 2,0) ));
221 
228 extern void lwgeom_set_handlers(lwallocator allocator,
229  lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
230  lwreporter noticereporter);
231 
232 extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
233 
246 extern void lwgeom_request_interrupt(void);
247 
251 extern void lwgeom_cancel_interrupt(void);
252 
263 typedef void (lwinterrupt_callback)();
265 
266 /******************************************************************/
267 
268 typedef struct {
269  double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
270 } AFFINE;
271 
272 /******************************************************************/
273 
274 typedef struct
275 {
276  double xmin, ymin, zmin;
277  double xmax, ymax, zmax;
278  int32_t srid;
279 }
280 BOX3D;
281 
282 /******************************************************************
283 * GBOX structure.
284 * We include the flags (information about dimensinality),
285 * so we don't have to constantly pass them
286 * into functions that use the GBOX.
287 */
288 typedef struct
289 {
291  double xmin;
292  double xmax;
293  double ymin;
294  double ymax;
295  double zmin;
296  double zmax;
297  double mmin;
298  double mmax;
299 } GBOX;
300 
301 
302 /******************************************************************
303 * SPHEROID
304 *
305 * Standard definition of an ellipsoid (what wkt calls a spheroid)
306 * f = (a-b)/a
307 * e_sq = (a*a - b*b)/(a*a)
308 * b = a - fa
309 */
310 typedef struct
311 {
312  double a; /* semimajor axis */
313  double b; /* semiminor axis b = (a - fa) */
314  double f; /* flattening f = (a-b)/a */
315  double e; /* eccentricity (first) */
316  double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
317  double radius; /* spherical average radius = (2*a+b)/3 */
318  char name[20]; /* name of ellipse */
319 }
320 SPHEROID;
321 
322 /******************************************************************
323 * POINT2D, POINT3D, POINT3DM, POINT4D
324 */
325 typedef struct
326 {
327  double x, y;
328 }
329 POINT2D;
330 
331 typedef struct
332 {
333  double x, y, z;
334 }
335 POINT3DZ;
336 
337 typedef struct
338 {
339  double x, y, z;
340 }
341 POINT3D;
342 
343 typedef struct
344 {
345  double x, y, m;
346 }
347 POINT3DM;
348 
349 typedef struct
350 {
351  double x, y, z, m;
352 }
353 POINT4D;
354 
355 /******************************************************************
356 * POINTARRAY
357 * Point array abstracts a lot of the complexity of points and point lists.
358 * It handles 2d/3d translation
359 * (2d points converted to 3d will have z=0 or NaN)
360 * DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
361 */
362 typedef struct
363 {
364  /* Array of POINT 2D, 3D or 4D, possibly missaligned. */
366 
367  /* Use FLAGS_* macros to handle */
369 
370  uint32_t npoints; /* how many points we are currently storing */
371  uint32_t maxpoints; /* how many points we have space for in serialized_pointlist */
372 }
373 POINTARRAY;
374 
375 /******************************************************************
376 * GSERIALIZED
377 */
378 typedef struct
379 {
380  uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
381  uint8_t srid[3]; /* 24 bits of SRID */
382  uint8_t flags; /* HasZ, HasM, HasBBox, IsGeodetic, IsReadOnly */
383  uint8_t data[1]; /* See gserialized.txt */
384 } GSERIALIZED;
385 
386 
387 /******************************************************************
388 * LWGEOM (any geometry type)
389 *
390 * Abstract type, note that 'type', 'bbox' and 'srid' are available in
391 * all geometry variants.
392 */
393 typedef struct
394 {
398  int32_t srid;
399  void *data;
400 }
401 LWGEOM;
402 
403 /* POINTYPE */
404 typedef struct
405 {
406  uint8_t type; /* POINTTYPE */
409  int32_t srid;
410  POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
411 }
412 LWPOINT; /* "light-weight point" */
413 
414 /* LINETYPE */
415 typedef struct
416 {
417  uint8_t type; /* LINETYPE */
420  int32_t srid;
421  POINTARRAY *points; /* array of POINT3D */
422 }
423 LWLINE; /* "light-weight line" */
424 
425 /* TRIANGLE */
426 typedef struct
427 {
431  int32_t srid;
433 }
434 LWTRIANGLE;
435 
436 /* CIRCSTRINGTYPE */
437 typedef struct
438 {
439  uint8_t type; /* CIRCSTRINGTYPE */
442  int32_t srid;
443  POINTARRAY *points; /* array of POINT(3D/3DM) */
444 }
445 LWCIRCSTRING; /* "light-weight circularstring" */
446 
447 /* POLYGONTYPE */
448 typedef struct
449 {
450  uint8_t type; /* POLYGONTYPE */
453  int32_t srid;
454  uint32_t nrings; /* how many rings we are currently storing */
455  uint32_t maxrings; /* how many rings we have space for in **rings */
456  POINTARRAY **rings; /* list of rings (list of points) */
457 }
458 LWPOLY; /* "light-weight polygon" */
459 
460 /* MULTIPOINTTYPE */
461 typedef struct
462 {
466  int32_t srid;
467  uint32_t ngeoms; /* how many geometries we are currently storing */
468  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
470 }
471 LWMPOINT;
472 
473 /* MULTILINETYPE */
474 typedef struct
475 {
479  int32_t srid;
480  uint32_t ngeoms; /* how many geometries we are currently storing */
481  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
483 }
484 LWMLINE;
485 
486 /* MULTIPOLYGONTYPE */
487 typedef struct
488 {
492  int32_t srid;
493  uint32_t ngeoms; /* how many geometries we are currently storing */
494  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
496 }
497 LWMPOLY;
498 
499 /* COLLECTIONTYPE */
500 typedef struct
501 {
505  int32_t srid;
506  uint32_t ngeoms; /* how many geometries we are currently storing */
507  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
509 }
511 
512 /* COMPOUNDTYPE */
513 typedef struct
514 {
515  uint8_t type; /* COMPOUNDTYPE */
518  int32_t srid;
519  uint32_t ngeoms; /* how many geometries we are currently storing */
520  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
522 }
523 LWCOMPOUND; /* "light-weight compound line" */
524 
525 /* CURVEPOLYTYPE */
526 typedef struct
527 {
528  uint8_t type; /* CURVEPOLYTYPE */
531  int32_t srid;
532  uint32_t nrings; /* how many rings we are currently storing */
533  uint32_t maxrings; /* how many rings we have space for in **rings */
534  LWGEOM **rings; /* list of rings (list of points) */
535 }
536 LWCURVEPOLY; /* "light-weight polygon" */
537 
538 /* MULTICURVE */
539 typedef struct
540 {
544  int32_t srid;
545  uint32_t ngeoms; /* how many geometries we are currently storing */
546  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
548 }
549 LWMCURVE;
550 
551 /* MULTISURFACETYPE */
552 typedef struct
553 {
557  int32_t srid;
558  uint32_t ngeoms; /* how many geometries we are currently storing */
559  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
561 }
562 LWMSURFACE;
563 
564 /* POLYHEDRALSURFACETYPE */
565 typedef struct
566 {
570  int32_t srid;
571  uint32_t ngeoms; /* how many geometries we are currently storing */
572  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
574 }
575 LWPSURFACE;
576 
577 /* TINTYPE */
578 typedef struct
579 {
583  int32_t srid;
584  uint32_t ngeoms; /* how many geometries we are currently storing */
585  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
587 }
588 LWTIN;
589 
590 /* Casts LWGEOM->LW* (return NULL if cast is illegal) */
591 extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
592 extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
593 extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
594 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
595 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
596 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
597 extern LWPOINT *lwgeom_as_lwpoint(const LWGEOM *lwgeom);
598 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
599 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
600 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
601 extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
602 extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
603 extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
604 extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
605 extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
606 
607 /* Casts LW*->LWGEOM (always cast) */
608 extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
609 extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
610 extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
611 extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
612 extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
613 extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
614 extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
615 extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
616 extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
617 extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
618 extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
619 extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
620 extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
621 
622 
623 extern LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom);
624 extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
625 extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
626 extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
627 extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
628 extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
629 
630 
631 
632 /***********************************************************************
633 ** Utility functions for flag byte and srid_flag integer.
634 */
635 
639 extern uint8_t gflags(int hasz, int hasm, int geodetic);
640 
645 extern uint32_t gserialized_get_type(const GSERIALIZED *g);
646 
652 
657 extern uint32_t gserialized_header_size(const GSERIALIZED *gser);
658 
663 extern int32_t gserialized_get_srid(const GSERIALIZED *g);
664 
669 extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
670 
677 extern int gserialized_is_empty(const GSERIALIZED *g);
678 
682 extern int gserialized_has_bbox(const GSERIALIZED *gser);
683 
687 extern int gserialized_has_z(const GSERIALIZED *gser);
688 
692 extern int gserialized_has_m(const GSERIALIZED *gser);
693 
697 extern int gserialized_is_geodetic(const GSERIALIZED *gser);
698 
703 extern int gserialized_get_zm(const GSERIALIZED *gser);
704 
708 extern int gserialized_ndims(const GSERIALIZED *gser);
709 
719 extern int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2);
720 
727 extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
728 extern void lwgeom_drop_srid(LWGEOM *lwgeom);
729 
736 extern void lwgeom_add_bbox(LWGEOM *lwgeom);
740 extern void lwgeom_refresh_bbox(LWGEOM *lwgeom);
744 extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
745 
753 extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
754 
758 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
759 
760 /******************************************************************/
761 /* Functions that work on type numbers */
762 
766 extern int lwtype_is_collection(uint8_t type);
767 
772 
777 extern const char *lwtype_name(uint8_t type);
778 
779 
780 /******************************************************************/
781 
782 /*
783  * copies a point from the point array into the parameter point
784  * will set point's z=0 (or NaN) if pa is 2d
785  * will set point's m=0 (or NaN) if pa is 3d or 2d
786  * NOTE: point is a real POINT3D *not* a pointer
787  */
788 extern POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n);
789 
790 /*
791  * copies a point from the point array into the parameter point
792  * will set point's z=0 (or NaN) if pa is 2d
793  * will set point's m=0 (or NaN) if pa is 3d or 2d
794  * NOTE: this will modify the point4d pointed to by 'point'.
795  */
796 extern int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point);
797 
798 /*
799  * copies a point from the point array into the parameter point
800  * will set point's z=0 (or NaN) if pa is 2d
801  * NOTE: point is a real POINT3D *not* a pointer
802  */
803 extern POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n);
804 extern POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n);
805 
806 /*
807  * copies a point from the point array into the parameter point
808  * will set point's z=0 (or NaN) if pa is 2d
809  * NOTE: this will modify the point3d pointed to by 'point'.
810  */
811 extern int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point);
812 extern int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point);
813 
814 
815 /*
816  * copies a point from the point array into the parameter point
817  * z value (if present is not returned)
818  * NOTE: point is a real POINT3D *not* a pointer
819  */
820 extern POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n);
821 
822 /*
823  * copies a point from the point array into the parameter point
824  * z value (if present is not returned)
825  * NOTE: this will modify the point2d pointed to by 'point'.
826  */
827 extern int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point);
828 
835 extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, uint32_t n);
836 
843 extern const POINT3DZ* getPoint3dz_cp(const POINTARRAY *pa, uint32_t n);
844 
851 extern const POINT4D* getPoint4d_cp(const POINTARRAY *pa, uint32_t n);
852 
853 /*
854  * set point N to the given value
855  * NOTE that the pointarray can be of any
856  * dimension, the appropriate ordinate values
857  * will be extracted from it
858  *
859  * N must be a valid point index
860  */
861 extern void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d);
862 
863 /*
864  * get a pointer to nth point of a POINTARRAY
865  * You'll need to cast it to appropriate dimensioned point.
866  * Note that if you cast to a higher dimensional point you'll
867  * possibly corrupt the POINTARRAY.
868  *
869  * WARNING: Don't cast this to a POINT !
870  * it would not be reliable due to memory alignment constraints
871  */
872 extern uint8_t *getPoint_internal(const POINTARRAY *pa, uint32_t n);
873 
874 /*
875  * size of point represeneted in the POINTARRAY
876  * 16 for 2d, 24 for 3d, 32 for 4d
877  */
878 extern size_t ptarray_point_size(const POINTARRAY *pa);
879 
880 
886 extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
887 
891 extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
892 
896 extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
897 
903 extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
904 
910 extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
911 
923 extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
924 
929 extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where);
930 
935 extern int ptarray_remove_point(POINTARRAY *pa, uint32_t where);
936 
948 extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
949 
956 
963 extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
964 
965 extern int ptarray_is_closed(const POINTARRAY *pa);
966 extern int ptarray_is_closed_2d(const POINTARRAY *pa);
967 extern int ptarray_is_closed_3d(const POINTARRAY *pa);
968 extern int ptarray_is_closed_z(const POINTARRAY *pa);
970 
976 extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
977  double tolerance);
978 
979 
983 extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
984 extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
985 extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
986 extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
987 
988 extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
989 
990 /*
991  * Force to use SFS 1.1 geometry type
992  * (rather than SFS 1.2 and/or SQL/MM)
993  */
994 extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
995 
996 
997 /*--------------------------------------------------------
998  * all the base types (point/line/polygon) will have a
999  * basic constructor, basic de-serializer, basic serializer,
1000  * bounding box finder and (TODO) serialized form size finder.
1001  *--------------------------------------------------------*/
1002 
1003 /*
1004  * convenience functions to hide the POINTARRAY
1005  */
1006 extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
1007 extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
1008 extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
1009 extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
1010 
1011 /******************************************************************
1012  * LWLINE functions
1013  ******************************************************************/
1014 
1018 extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1019 
1023 extern POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat);
1024 
1025 /******************************************************************
1026  * LWPOLY functions
1027  ******************************************************************/
1028 
1033 extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1034 
1039 extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1040 
1045 extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1046 
1051 extern LWCOMPOUND* lwcompound_construct_from_lwline(const LWLINE *lwpoly);
1052 
1058 
1059 
1060 /******************************************************************
1061  * LWGEOM functions
1062  ******************************************************************/
1063 
1064 extern int lwcollection_ngeoms(const LWCOLLECTION *col);
1065 
1066 /* Given a generic geometry/collection, return the "simplest" form.
1067  * The elements of the homogenized collection are references to the
1068  * input geometry; a deep clone is not performed.
1069  * TODO: consider returning a geometry that does not reference the
1070  * input
1071  * */
1072 extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
1073 
1074 
1075 /******************************************************************
1076  * LWMULTIx and LWCOLLECTION functions
1077  ******************************************************************/
1078 
1080 
1081 /* WARNING: the output will contain references to geometries in the input, */
1082 /* so the result must be carefully released, not freed. */
1084 
1085 
1086 /******************************************************************
1087  * SERIALIZED FORM functions
1088  ******************************************************************/
1089 
1095 extern void lwgeom_set_srid(LWGEOM *geom, int srid);
1096 
1097 /*------------------------------------------------------
1098  * other stuff
1099  *
1100  * handle the double-to-float conversion. The results of this
1101  * will usually be a slightly bigger box because of the difference
1102  * between float8 and float4 representations.
1103  */
1104 
1105 extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1106 extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1107 
1108 void expand_box3d(BOX3D *box, double d);
1109 
1110 
1111 /****************************************************************
1112  * MEMORY MANAGEMENT
1113  ****************************************************************/
1114 
1115 /*
1116 * The *_free family of functions frees *all* memory associated
1117 * with the pointer. When the recursion gets to the level of the
1118 * POINTARRAY, the POINTARRAY is only freed if it is not flagged
1119 * as "read only". LWGEOMs constructed on top of GSERIALIZED
1120 * from PgSQL use read only point arrays.
1121 */
1122 
1123 extern void ptarray_free(POINTARRAY *pa);
1124 extern void lwpoint_free(LWPOINT *pt);
1125 extern void lwline_free(LWLINE *line);
1126 extern void lwpoly_free(LWPOLY *poly);
1127 extern void lwtriangle_free(LWTRIANGLE *triangle);
1128 extern void lwmpoint_free(LWMPOINT *mpt);
1129 extern void lwmline_free(LWMLINE *mline);
1130 extern void lwmpoly_free(LWMPOLY *mpoly);
1131 extern void lwpsurface_free(LWPSURFACE *psurf);
1132 extern void lwtin_free(LWTIN *tin);
1133 extern void lwcollection_free(LWCOLLECTION *col);
1134 extern void lwcircstring_free(LWCIRCSTRING *curve);
1135 extern void lwgeom_free(LWGEOM *geom);
1136 
1137 /*
1138 * The *_release family of functions frees the LWGEOM structures
1139 * surrounding the POINTARRAYs but leaves the POINTARRAYs
1140 * intact. Useful when re-shaping geometries between types,
1141 * or splicing geometries together.
1142 */
1143 
1144 extern void lwpoint_release(LWPOINT *lwpoint);
1145 extern void lwline_release(LWLINE *lwline);
1146 extern void lwpoly_release(LWPOLY *lwpoly);
1147 extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1148 extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1149 extern void lwmpoint_release(LWMPOINT *lwpoint);
1150 extern void lwmline_release(LWMLINE *lwline);
1151 extern void lwmpoly_release(LWMPOLY *lwpoly);
1152 extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1153 extern void lwtin_release(LWTIN *lwtin);
1154 extern void lwcollection_release(LWCOLLECTION *lwcollection);
1155 extern void lwgeom_release(LWGEOM *lwgeom);
1156 
1157 
1158 /****************************************************************
1159 * Utility
1160 ****************************************************************/
1161 
1162 extern void printBOX3D(BOX3D *b);
1163 extern void printPA(POINTARRAY *pa);
1164 extern void printLWPOINT(LWPOINT *point);
1165 extern void printLWLINE(LWLINE *line);
1166 extern void printLWPOLY(LWPOLY *poly);
1167 extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1168 extern void printLWPSURFACE(LWPSURFACE *psurf);
1169 extern void printLWTIN(LWTIN *tin);
1170 
1171 extern float next_float_down(double d);
1172 extern float next_float_up(double d);
1173 
1174 /* general utilities 2D */
1175 extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1176 extern double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2);
1177 extern double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1178 extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1179 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1180 extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1181 extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1182 extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1183 extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1184 extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1185 extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1186 extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1187 
1188 /* 3D */
1189 extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1190 extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1191 
1192 extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1193 extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1194 extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1195 
1196 
1197 extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1198 extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1199 extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1200 extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1201 
1202 extern double lwgeom_area(const LWGEOM *geom);
1203 extern double lwgeom_length(const LWGEOM *geom);
1204 extern double lwgeom_length_2d(const LWGEOM *geom);
1205 extern double lwgeom_perimeter(const LWGEOM *geom);
1206 extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1207 extern int lwgeom_dimension(const LWGEOM *geom);
1208 
1209 extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, uint32_t where);
1210 extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where);
1211 
1212 extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1213 extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1214 extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where);
1215 
1216 extern double ptarray_length_2d(const POINTARRAY *pts);
1217 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1218 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1219 extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1220 
1221 extern LWGEOM* lwgeom_reverse(const LWGEOM *lwgeom);
1222 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1223 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1224 extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1225 
1226 extern void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F);
1227 
1232 extern int lwgeom_is_clockwise(LWGEOM *lwgeom);
1233 
1234 
1235 extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
1236 extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1237 
1238 /****************************************************************
1239 * READ/WRITE FUNCTIONS
1240 *
1241 * Coordinate writing functions, which will alter the coordinates
1242 * and potentially the structure of the input geometry. When
1243 * called from within PostGIS, the LWGEOM argument should be built
1244 * on top of a gserialized copy, created using
1245 * PG_GETARG_GSERIALIZED_P_COPY()
1246 ****************************************************************/
1247 
1248 extern void lwgeom_reverse_in_place(LWGEOM *lwgeom);
1249 extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1250 extern void lwgeom_longitude_shift(LWGEOM *lwgeom);
1251 extern void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed);
1252 extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1253 extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1254 extern void lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance);
1255 
1256 
1269 LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1270 
1271 
1281 extern int lwgeom_needs_bbox(const LWGEOM *geom);
1282 
1286 extern uint32_t lwgeom_count_vertices(const LWGEOM *geom);
1287 
1292 extern uint32_t lwgeom_count_rings(const LWGEOM *geom);
1293 
1298 extern int lwgeom_has_srid(const LWGEOM *geom);
1299 
1304 extern int lwgeom_is_empty(const LWGEOM *geom);
1305 
1310 extern int lwgeom_is_closed(const LWGEOM *geom);
1311 
1315 extern int lwgeom_dimensionality(const LWGEOM *geom);
1316 
1317 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
1318 extern char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1319 
1320 
1328 extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1329 
1333 extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1334 extern POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1335 
1336 
1337 /*
1338 * Geometry constructors. These constructors to not copy the point arrays
1339 * passed to them, they just take references, so do not free them out
1340 * from underneath the geometries.
1341 */
1342 extern LWPOINT* lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point);
1343 extern LWMPOINT *lwmpoint_construct(int srid, const POINTARRAY *pa);
1344 extern LWLINE* lwline_construct(int srid, GBOX *bbox, POINTARRAY *points);
1345 extern LWCIRCSTRING* lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points);
1346 extern LWPOLY* lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1347 extern LWCURVEPOLY* lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1348 extern LWTRIANGLE* lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points);
1349 extern LWCOLLECTION* lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1350 /*
1351 * Empty geometry constructors.
1352 */
1353 extern LWGEOM* lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1354 extern LWPOINT* lwpoint_construct_empty(int srid, char hasz, char hasm);
1355 extern LWLINE* lwline_construct_empty(int srid, char hasz, char hasm);
1356 extern LWPOLY* lwpoly_construct_empty(int srid, char hasz, char hasm);
1357 extern LWCURVEPOLY* lwcurvepoly_construct_empty(int srid, char hasz, char hasm);
1358 extern LWCIRCSTRING* lwcircstring_construct_empty(int srid, char hasz, char hasm);
1359 extern LWCOMPOUND* lwcompound_construct_empty(int srid, char hasz, char hasm);
1360 extern LWTRIANGLE* lwtriangle_construct_empty(int srid, char hasz, char hasm);
1361 extern LWMPOINT* lwmpoint_construct_empty(int srid, char hasz, char hasm);
1362 extern LWMLINE* lwmline_construct_empty(int srid, char hasz, char hasm);
1363 extern LWMPOLY* lwmpoly_construct_empty(int srid, char hasz, char hasm);
1364 extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1365 
1366 
1367 /* Other constructors */
1368 extern LWPOINT *lwpoint_make2d(int srid, double x, double y);
1369 extern LWPOINT *lwpoint_make3dz(int srid, double x, double y, double z);
1370 extern LWPOINT *lwpoint_make3dm(int srid, double x, double y, double m);
1371 extern LWPOINT *lwpoint_make4d(int srid, double x, double y, double z, double m);
1372 extern LWPOINT *lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p);
1373 extern LWLINE *lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms);
1374 extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1375 extern LWLINE *lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint);
1376 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1377 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1378 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1379 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1380 extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1381 extern LWPOLY *lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2);
1382 extern LWPOLY *lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1383 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1384 extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1385 
1386 /* Some point accessors */
1387 extern double lwpoint_get_x(const LWPOINT *point);
1388 extern double lwpoint_get_y(const LWPOINT *point);
1389 extern double lwpoint_get_z(const LWPOINT *point);
1390 extern double lwpoint_get_m(const LWPOINT *point);
1391 
1395 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1396 
1400 extern uint32_t lwgeom_get_type(const LWGEOM *geom);
1401 
1405 extern int lwgeom_has_z(const LWGEOM *geom);
1406 
1410 extern int lwgeom_has_m(const LWGEOM *geom);
1411 
1415 extern int lwgeom_ndims(const LWGEOM *geom);
1416 
1417 /*
1418  * Given a point, returns the location of closest point on pointarray
1419  * as a fraction of total length (0: first point -- 1: last point).
1420  *
1421  * If not-null, the third argument will be set to the actual distance
1422  * of the point from the pointarray.
1423  */
1424 extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1425 
1430 extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1431 extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1432 
1437 extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1438 
1444 extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1445 
1449 extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1450 
1461 extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1462 
1468 extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1469 
1474 extern int lwgeom_is_trajectory(const LWGEOM *geom);
1475 extern int lwline_is_trajectory(const LWLINE *geom);
1476 
1477 /*
1478  * Ensure every segment is at most 'dist' long.
1479  * Returned LWGEOM might is unchanged if a POINT.
1480  */
1481 extern LWGEOM *lwgeom_segmentize2d(const LWGEOM *line, double dist);
1482 extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1483 extern LWLINE *lwline_segmentize2d(const LWLINE *line, double dist);
1484 extern LWPOLY *lwpoly_segmentize2d(const LWPOLY *line, double dist);
1485 extern LWCOLLECTION *lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist);
1486 
1487 /*
1488  * Point density functions
1489  */
1490 extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, uint32_t npoints);
1491 extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints);
1492 extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints);
1493 
1494 /*
1495  * Geometric median
1496  */
1497 extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1498 extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1499 
1503 char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1504 unsigned int geohash_point_as_int(POINT2D *pt);
1505 
1506 
1518 };
1519 
1523 int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1524 
1528 LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1529 
1535 #define LW_GML_IS_DIMS (1<<0)
1536 
1537 #define LW_GML_IS_DEGREE (1<<1)
1538 
1539 #define LW_GML_SHORTLINE (1<<2)
1540 
1541 #define LW_GML_EXTENT (1<<4)
1542 
1543 
1544 #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1545 #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1546 
1553 #define LW_X3D_FLIP_XY (1<<0)
1554 #define LW_X3D_USE_GEOCOORDS (1<<1)
1555 #define X3D_USE_GEOCOORDS(x) ((x) & LW_X3D_USE_GEOCOORDS)
1556 
1557 
1558 
1559 extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1560 extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1564 extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1565 extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1566 extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1567 extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1568 extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1569 extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1570 extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1571 
1581 extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1582 
1588 extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1589 
1593 extern void spheroid_init(SPHEROID *s, double a, double b);
1594 
1600 extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1601 
1605 extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1606 
1611 extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1612 
1616 extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1617 
1622 extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1623 
1628 extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1629 
1634 extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1635 
1640 extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1641 
1642 typedef struct {
1644  double radius;
1646 
1648 
1649 /* Calculates the minimum circle that encloses all of the points in g, using a
1650  * two-dimensional implementation of the algorithm proposed in:
1651  *
1652  * Welzl, Emo (1991), "Smallest enclosing disks (balls and elipsoids)."
1653  * New Results and Trends in Computer Science (H. Maurer, Ed.), Lecture Notes
1654  * in Computer Science, 555 (1991) 359-370.
1655  *
1656  * Available online at the time of this writing at
1657  * https://www.inf.ethz.ch/personal/emo/PublFiles/SmallEnclDisk_LNCS555_91.pdf
1658  *
1659  * Returns NULL if the circle could not be calculated.
1660  */
1661 extern LWBOUNDINGCIRCLE* lwgeom_calculate_mbc(const LWGEOM* g);
1662 
1675 extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1676 
1677 
1678 struct LWPOINTITERATOR;
1680 
1685 
1691 
1696 
1701 
1707 extern int lwpointiterator_modify_next(LWPOINTITERATOR* s, const POINT4D* p);
1708 
1716 
1722 
1723 
1727 extern uint8_t parse_hex(char *str);
1728 
1732 extern void deparse_hex(uint8_t str, char *result);
1733 
1734 
1735 
1736 /***********************************************************************
1737 ** Functions for managing serialized forms and bounding boxes.
1738 */
1739 
1746 
1753 
1758 extern char* gserialized_to_string(const GSERIALIZED *g);
1759 
1763 extern GSERIALIZED* gserialized_copy(const GSERIALIZED *g);
1764 
1768 extern int lwgeom_check_geodetic(const LWGEOM *geom);
1769 
1773 extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1774 
1778 extern int lwgeom_force_geodetic(LWGEOM *geom);
1779 
1783 extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1784 
1791 extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1792 
1798 extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1799 
1804 extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1805 
1810 extern int getPoint2d_p_ro(const POINTARRAY *pa, uint32_t n, POINT2D **point);
1811 
1815 extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1816 
1820 extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1821 
1825 void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1826 
1831 extern GBOX* gbox_new(uint8_t flags);
1832 
1837 extern void gbox_init(GBOX *gbox);
1838 
1842 extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1843 
1847 extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1848 
1852 extern void gbox_expand(GBOX *g, double d);
1853 
1857 extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
1858 
1862 extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1863 
1867 extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1868 
1872 extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1873 
1877 extern char* gbox_to_string(const GBOX *gbox);
1878 
1882 extern GBOX* gbox_copy(const GBOX *gbox);
1883 
1887 extern GBOX* gbox_from_string(const char *str);
1888 
1892 extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1893 
1897 extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1898 
1902 extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
1903 
1907 extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1908 
1913 extern size_t gbox_serialized_size(uint8_t flags);
1914 
1918 extern int gbox_same(const GBOX *g1, const GBOX *g2);
1919 
1923 extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
1924 
1929 extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
1930 
1937 extern void gbox_float_round(GBOX *gbox);
1938 
1942 extern int gbox_is_valid(const GBOX *gbox);
1943 
1948 extern uint64_t gbox_get_sortable_hash(const GBOX *g);
1949 
1954 extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
1955 
1961 extern size_t gserialized_from_lwgeom_size(const LWGEOM *geom);
1962 
1970 extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
1971 
1976 extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g);
1977 
1983 extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox);
1984 
1985 
1993 #define LW_PARSER_CHECK_MINPOINTS 1
1994 #define LW_PARSER_CHECK_ODD 2
1995 #define LW_PARSER_CHECK_CLOSURE 4
1996 #define LW_PARSER_CHECK_ZCLOSURE 8
1997 
1998 #define LW_PARSER_CHECK_NONE 0
1999 #define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
2000 
2006 {
2007  const char *wkinput; /* Copy of pointer to input WKT/WKB */
2008  uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
2009  size_t size; /* Size of serialized LWGEOM in bytes */
2010  LWGEOM *geom; /* Pointer to LWGEOM struct */
2011  const char *message; /* Error/warning message */
2012  int errcode; /* Error/warning number */
2013  int errlocation; /* Location of error */
2014  int parser_check_flags; /* Bitmask of validity checks run during this parse */
2015 }
2017 
2018 /*
2019  * Parser error messages (these must match the message array in lwgparse.c)
2020  */
2021 #define PARSER_ERROR_MOREPOINTS 1
2022 #define PARSER_ERROR_ODDPOINTS 2
2023 #define PARSER_ERROR_UNCLOSED 3
2024 #define PARSER_ERROR_MIXDIMS 4
2025 #define PARSER_ERROR_INVALIDGEOM 5
2026 #define PARSER_ERROR_INVALIDWKBTYPE 6
2027 #define PARSER_ERROR_INCONTINUOUS 7
2028 #define PARSER_ERROR_TRIANGLEPOINTS 8
2029 #define PARSER_ERROR_LESSPOINTS 9
2030 #define PARSER_ERROR_OTHER 10
2031 
2032 
2033 
2034 /*
2035  * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
2036  */
2038 {
2039  uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
2040  char *wkoutput; /* Pointer to WKT or WKB output */
2041  size_t size; /* Size of serialized LWGEOM in bytes */
2042  const char *message; /* Error/warning message */
2043  int errlocation; /* Location of error */
2044 }
2046 
2047 /*
2048  * Unparser error messages (these must match the message array in lwgunparse.c)
2049  */
2050 #define UNPARSER_ERROR_MOREPOINTS 1
2051 #define UNPARSER_ERROR_ODDPOINTS 2
2052 #define UNPARSER_ERROR_UNCLOSED 3
2053 
2054 
2055 /*
2056 ** Variants available for WKB and WKT output types
2057 */
2058 
2059 #define WKB_ISO 0x01
2060 #define WKB_SFSQL 0x02
2061 #define WKB_EXTENDED 0x04
2062 #define WKB_NDR 0x08
2063 #define WKB_XDR 0x10
2064 #define WKB_HEX 0x20
2065 #define WKB_NO_NPOINTS 0x40 /* Internal use only */
2066 #define WKB_NO_SRID 0x80 /* Internal use only */
2067 
2068 #define WKT_ISO 0x01
2069 #define WKT_SFSQL 0x02
2070 #define WKT_EXTENDED 0x04
2071 
2072 
2073 /*
2074 ** Variants available for TWKB
2075 */
2076 #define TWKB_BBOX 0x01 /* User wants bboxes */
2077 #define TWKB_SIZE 0x02 /* User wants sizes */
2078 #define TWKB_ID 0x04 /* User wants id */
2079 #define TWKB_NO_TYPE 0x10 /* No type because it is a sub geoemtry */
2080 #define TWKB_NO_ID 0x20 /* No ID because it is a subgeoemtry */
2081 #define TWKB_DEFAULT_PRECISION 0 /* Aim for 1m (or ft) rounding by default */
2082 
2083 /*
2084 ** New parsing and unparsing functions.
2085 */
2086 
2091 extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2092 
2098 extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2099 
2105 extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2106 
2110 extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2111 
2117 extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2118 
2123 extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2124 
2128 extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2129 
2130 extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2131 
2132 extern char* hexbytes_from_bytes(const uint8_t *bytes, size_t size);
2133 
2134 /*
2135 * WKT detailed parsing support
2136 */
2137 extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2138 void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
2139 void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
2140 
2141 
2142 /* Memory management */
2143 extern void *lwalloc(size_t size);
2144 extern void *lwrealloc(void *mem, size_t size);
2145 extern void lwfree(void *mem);
2146 
2147 /* Utilities */
2148 extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2149 
2150 /*
2151 * TWKB functions
2152 */
2153 
2158 extern LWGEOM* lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check);
2159 
2165 extern uint8_t* lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size);
2166 
2167 extern uint8_t* lwgeom_to_twkb_with_idlist(const LWGEOM *geom, int64_t *idlist, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size);
2168 
2169 /*******************************************************************************
2170  * SQLMM internal functions
2171  ******************************************************************************/
2172 
2173 int lwgeom_has_arc(const LWGEOM *geom);
2174 LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2175 LWGEOM *lwgeom_unstroke(const LWGEOM *geom);
2176 
2181 typedef enum {
2204 
2205 typedef enum {
2212 
2233 
2242 extern LWGEOM* lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags);
2243 
2244 /*******************************************************************************
2245  * GEOS proxy functions on LWGEOM
2246  ******************************************************************************/
2247 
2249 const char* lwgeom_geos_version(void);
2250 
2252 LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ;
2253 
2254 LWGEOM *lwgeom_normalize(const LWGEOM *geom);
2255 LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2256 LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2257 LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2258 LWGEOM *lwgeom_centroid(const LWGEOM* geom);
2259 LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2260 LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2261 LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2262 LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2263 LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices);
2264 
2274 LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
2275 
2276 /*
2277  * Return the set of paths shared between two linear geometries,
2278  * and their direction (same or opposite).
2279  *
2280  * @param geom1 a lineal geometry
2281  * @param geom2 another lineal geometry
2282  *
2283  * Requires GEOS-3.3.0+
2284  */
2285 LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
2286 
2287 /*
2288  * An offset curve against the input line.
2289  *
2290  * @param lwline a lineal geometry
2291  * @param size offset distance. Offset left if negative and right if positive
2292  * @param quadsegs number of quadrature segments in curves (try 8)
2293  * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
2294  * @param mitreLimit (try 5.0)
2295  * @return derived geometry (linestring or multilinestring)
2296  *
2297  * Requires GEOS-3.2.0+
2298  */
2299 LWGEOM* lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit);
2300 
2301 /*
2302  * Return true if the input geometry is "simple" as per OGC defn.
2303  *
2304  * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called
2305  * in that case)
2306  */
2307 int lwgeom_is_simple(const LWGEOM *lwgeom);
2308 
2309 
2310 /*******************************************************************************
2311  * PROJ4-dependent extra functions on LWGEOM
2312  ******************************************************************************/
2313 
2319 projPJ lwproj_from_string(const char* txt);
2320 
2327 int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj);
2328 int ptarray_transform(POINTARRAY *pa, projPJ inpj, projPJ outpj);
2329 
2330 
2331 /*******************************************************************************
2332  * GEOS-dependent extra functions on LWGEOM
2333  ******************************************************************************/
2334 
2342 LWGEOM* lwgeom_buildarea(const LWGEOM *geom) ;
2343 
2344 
2352 
2353 /*
2354  * Split (multi)polygon by line; (multi)line by (multi)line,
2355  * (multi)point or (multi)polygon boundary.
2356  *
2357  * Collections are accepted as first argument.
2358  * Returns all obtained pieces as a collection.
2359  */
2360 LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
2361 
2362 /*
2363  * Fully node a set of linestrings, using the least nodes preserving
2364  * all the input ones.
2365  *
2366  * Requires GEOS-3.3.0 or higher
2367  */
2368 LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2369 
2379 LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly);
2380 
2392 LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2393 
2402 int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k);
2403 
2404 
2405 #endif /* !defined _LIBLWGEOM_H */
2406 
int32_t srid
Definition: liblwgeom.h:518
POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:324
LWCOMPOUND * lwcompound_construct_empty(int srid, char hasz, char hasm)
Definition: lwcompound.c:123
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2927
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
Definition: measures3d.c:363
int32_t srid
Definition: liblwgeom.h:278
LWLINE * lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end)
Add a measure dimension to a line, interpolating linearly from the start to the end value...
Definition: lwline.c:388
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:691
LWMPOINT * lwpoly_to_points(const LWPOLY *poly, uint32_t npoints)
size_t ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
uint8_t type
Definition: liblwgeom.h:417
uint8_t flags
Definition: liblwgeom.h:568
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition: lwutil.c:347
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition: lwstroke.c:714
uint8_t flags
Definition: liblwgeom.h:542
LWGEOM * lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area)
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
Definition: lwout_gml.c:231
uint8_t type
Definition: liblwgeom.h:476
double z
Definition: liblwgeom.h:333
void lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition: lwgeom.c:1596
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
Definition: g_box.c:290
size_t gserialized_from_lwgeom_size(const LWGEOM *geom)
Calculate required memory segment to contain a serialized form of the LWGEOM.
Definition: g_serialized.c:807
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition: g_box.c:371
int lwgeom_is_closed(const LWGEOM *geom)
Return true or false depending on whether a geometry is a linear feature that closes on itself...
Definition: lwgeom.c:1034
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox)
Compute a box for geom and all sub-geometries, if not already computed.
Definition: lwgeom.c:698
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition: lwtin.c:34
GBOX * bbox
Definition: liblwgeom.h:397
uint8_t flags
Definition: liblwgeom.h:440
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
POINTARRAY * points
Definition: liblwgeom.h:432
GBOX * bbox
Definition: liblwgeom.h:465
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition: lwgeom.c:1338
void printLWPSURFACE(LWPSURFACE *psurf)
Definition: lwpsurface.c:57
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:336
int lwgeom_is_trajectory(const LWGEOM *geom)
Return LW_TRUE or LW_FALSE depending on whether or not a geometry is a linestring with measure value ...
Definition: lwgeom.c:2386
uint32_t ngeoms
Definition: liblwgeom.h:558
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
LWPOLY * lwpoly_segmentize2d(const LWPOLY *line, double dist)
Definition: lwpoly.c:310
uint8_t * serialized_pointlist
Definition: liblwgeom.h:365
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1429
uint8_t * lwgeom_to_twkb_with_idlist(const LWGEOM *geom, int64_t *idlist, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size)
Convert LWGEOM to a char* in TWKB format.
Definition: lwout_twkb.c:567
GBOX * bbox
Definition: liblwgeom.h:419
uint8_t variant
Definition: cu_in_twkb.c:26
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:54
void lwmpoly_release(LWMPOLY *lwpoly)
Definition: lwmpoly.c:34
uint32_t ngeoms
Definition: liblwgeom.h:467
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition: lwin_wkb.c:87
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1078
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point...
Definition: lwiterator.c:212
void lwtin_release(LWTIN *lwtin)
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:372
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid)
Calculate the bearing between two points on a spheroid.
Definition: lwgeodetic.c:2065
uint8_t type
Definition: liblwgeom.h:406
Tolerance expresses the maximum angle between the radii generating approximation line vertices...
Definition: liblwgeom.h:2202
int lwpointiterator_modify_next(LWPOINTITERATOR *s, const POINT4D *p)
Attempts to replace the next point int the iterator with p, and advances the iterator to the next poi...
Definition: lwiterator.c:226
char * r
Definition: cu_in_wkt.c:24
tuple data
Definition: ovdump.py:103
int gserialized_get_zm(const GSERIALIZED *gser)
Return a number indicating presence of Z and M coordinates.
Definition: g_serialized.c:55
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:675
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:36
int lwcollection_ngeoms(const LWCOLLECTION *col)
Definition: lwcollection.c:304
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:40
void lwfree(void *mem)
Definition: lwutil.c:244
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:58
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
uint8_t flags
Definition: liblwgeom.h:555
int ptarray_transform(POINTARRAY *pa, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfyllywithin calculations.
Definition: measures.c:181
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:50
LWGEOM ** rings
Definition: liblwgeom.h:534
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:213
LWGEOM * lwgeom_force_4d(const LWGEOM *geom)
Definition: lwgeom.c:795
struct struct_lwgeom_unparser_result LWGEOM_UNPARSER_RESULT
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: g_box.c:186
uint8_t type
Definition: liblwgeom.h:502
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition: lwgeom_api.c:722
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition: lwgeom_api.c:672
LWLINE * lwline_segmentize2d(const LWLINE *line, double dist)
Definition: lwline.c:141
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition: measures3d.c:352
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:113
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
Definition: lwalgorithm.c:460
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:916
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:701
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition: lwgeom.c:101
GBOX * bbox
Definition: liblwgeom.h:543
GBOX * bbox
Definition: liblwgeom.h:582
uint32_t ngeoms
Definition: liblwgeom.h:493
void lwcircstring_free(LWCIRCSTRING *curve)
Definition: lwcircstring.c:97
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition: lwpsurface.c:33
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:56
int32_t srid
Definition: liblwgeom.h:442
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2322
uint32_t maxgeoms
Definition: liblwgeom.h:585
GSERIALIZED * gserialized_copy(const GSERIALIZED *g)
Return a copy of the input serialized geometry.
Definition: g_serialized.c:141
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:2108
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
Datum area(PG_FUNCTION_ARGS)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:549
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition: lwgeom.c:783
double b
Definition: liblwgeom.h:313
void lwtin_free(LWTIN *tin)
Definition: lwtin.c:39
uint8_t flags
Definition: liblwgeom.h:396
#define __attribute__(x)
Definition: liblwgeom.h:197
double xmax
Definition: liblwgeom.h:292
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition: lwpoint.c:40
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:237
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition: lwprint.c:424
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition: lwgeom.c:304
int lwgeom_check_geodetic(const LWGEOM *geom)
Check that coordinates of LWGEOM are all within the geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3030
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
void printLWTIN(LWTIN *tin)
Definition: lwtin.c:57
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
start location (distance from start / total distance) end location (distance from start / total dist...
Definition: ptarray.c:1053
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
void lwpoint_release(LWPOINT *lwpoint)
Definition: lwpoint.c:256
LWGEOM * lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1682
tuple fmt
Definition: pixval.py:92
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:169
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:346
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:414
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:280
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:425
int32_t srid
Definition: liblwgeom.h:544
GBOX * bbox
Definition: liblwgeom.h:504
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:2013
LWMPOLY * lwmpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoly.c:40
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:248
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:714
double radius
Definition: liblwgeom.h:317
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1503
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:196
LWGEOM * lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision)
Create an LWGEOM object from an Encoded Polyline representation.
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:909
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:289
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
uint32_t maxpoints
Definition: liblwgeom.h:371
int lwline_is_trajectory(const LWLINE *geom)
Definition: lwline.c:463
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:88
LWPOINT * lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth)
Calculate the location of a point on a spheroid, give a start point, bearing and distance.
Definition: lwgeodetic.c:2008
GBOX * bbox
Definition: liblwgeom.h:430
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition: lwmpoint.c:93
void printBOX3D(BOX3D *b)
Definition: lwgeom_api.c:490
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition: lwgeom.c:646
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:885
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:3303
uint8_t type
Definition: liblwgeom.h:528
LWPOINTITERATOR * lwpointiterator_create_rw(LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM* Supports modification of coordinates during iterat...
Definition: lwiterator.c:253
LWGEOM * lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:60
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:254
LWPOLY ** geoms
Definition: liblwgeom.h:573
void( lwinterrupt_callback)()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:263
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:246
LW_LINEARIZE_TOLERANCE_TYPE
Semantic of the tolerance argument passed to lwcurve_linearize.
Definition: liblwgeom.h:2181
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
Definition: g_box.c:235
uint8_t flags
Definition: liblwgeom.h:464
uint32_t maxgeoms
Definition: liblwgeom.h:572
uint32_t ngeoms
Definition: liblwgeom.h:571
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:513
float next_float_down(double d)
Definition: lwgeom_api.c:52
GBOX * bbox
Definition: liblwgeom.h:452
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:205
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2312
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition: lwgeom.c:364
Tolerance expresses the maximum distance between an arbitrary point on the curve and the closest poin...
Definition: liblwgeom.h:2194
uint32_t maxgeoms
Definition: liblwgeom.h:546
void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F)
Find interpolation point I between point A and point B so that the len(AI) == len(AB)*F and I falls o...
Definition: lwgeom_api.c:704
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:46
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
double zoff
Definition: liblwgeom.h:269
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:160
int32_t srid
Definition: liblwgeom.h:420
LWGEOM ** geoms
Definition: liblwgeom.h:521
uint8_t flags
Definition: liblwgeom.h:516
uint32_t maxgeoms
Definition: liblwgeom.h:507
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3196
GBOX * bbox
Definition: liblwgeom.h:517
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
Definition: measures3d.c:94
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:718
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:831
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2337
uint32_t ngeoms
Definition: liblwgeom.h:506
POINTARRAY * point
Definition: liblwgeom.h:410
double lwgeom_length_2d(const LWGEOM *geom)
Definition: lwgeom.c:1939
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
Definition: lwmline.c:38
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: g_serialized.c:639
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:688
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:923
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:244
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:666
int32_t srid
Definition: liblwgeom.h:398
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:319
uint32_t maxgeoms
Definition: liblwgeom.h:481
LWGEOM * lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_twkb.c:656
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:373
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition: lwgeom.c:755
GBOX * bbox
Definition: liblwgeom.h:556
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: lwgeom.c:937
double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt)
Find the measure value at the location on the line closest to the point.
void lwgeom_longitude_shift(LWGEOM *lwgeom)
Definition: lwgeom.c:989
uint32_t nrings
Definition: liblwgeom.h:454
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition: g_box.c:87
uint8_t type
Definition: liblwgeom.h:428
uint32_t maxgeoms
Definition: liblwgeom.h:468
double lwgeom_perimeter(const LWGEOM *geom)
Definition: lwgeom.c:1873
POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:177
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition: lwtriangle.c:119
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:250
LWGEOM * lwgeom_reverse(const LWGEOM *lwgeom)
Definition: lwgeom.c:92
void * data
Definition: liblwgeom.h:399
int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
Is the closest point of approach within a distance ?
double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfullywithin calculations.
Definition: measures3d.c:326
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:368
void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1741
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:100
float next_float_up(double d)
Definition: lwgeom_api.c:68
uint8_t type
Definition: liblwgeom.h:554
LWPOINT * lwpoint_make3dm(int srid, double x, double y, double m)
Definition: lwpoint.c:184
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where)
Definition: lwcircstring.c:293
double z
Definition: liblwgeom.h:339
void lwmpoint_release(LWMPOINT *lwpoint)
Definition: lwmpoint.c:33
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
unsigned int uint32_t
Definition: uthash.h:78
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:739
void(* lwfreeor)(void *mem)
Definition: liblwgeom.h:216
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:191
uint8_t flags
Definition: liblwgeom.h:503
int lwgeom_dimensionality(const LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1451
int lwpointiterator_has_next(LWPOINTITERATOR *s)
Returns LW_TRUE if there is another point available in the iterator.
Definition: lwiterator.c:204
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1298
LWCURVEPOLY * lwcurvepoly_construct_from_lwpoly(LWPOLY *lwpoly)
Construct an equivalent curve polygon from a polygon.
Definition: lwcurvepoly.c:53
LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell)
Definition: lwtriangle.c:153
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
Definition: g_box.c:142
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
Definition: lwpoly.c:98
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
Definition: lwgeom.c:36
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Utility function to get type number from string.
Definition: g_util.c:163
LWCOLLECTION * lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset)
Determine the segments along a measured line that fall within the m-range given.
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
uint8_t flags
Definition: liblwgeom.h:477
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
Definition: ptarray.c:503
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:378
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
Definition: lwgeom_box3d.c:359
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition: lwline.c:542
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:269
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
Definition: lwhomogenize.c:209
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition: liblwgeom.h:214
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:304
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:330
double f
Definition: liblwgeom.h:314
uint8_t type
Definition: liblwgeom.h:463
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:96
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
Definition: lwout_wkb.c:764
uint8_t type
Definition: liblwgeom.h:541
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:329
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:171
double xmin
Definition: liblwgeom.h:291
LWCIRCSTRING * lwcircstring_construct_empty(int srid, char hasz, char hasm)
Definition: lwcircstring.c:79
LWCURVEPOLY * lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms)
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
int32_t srid
Definition: liblwgeom.h:531
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition: lwgeom.c:267
uint8_t type
Definition: liblwgeom.h:450
void lwcircstring_release(LWCIRCSTRING *lwcirc)
Definition: lwcircstring.c:91
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices)
Definition: lwgeom.c:2360
LW_LINEARIZE_FLAGS
Definition: liblwgeom.h:2205
uint8_t flags
Definition: liblwgeom.h:368
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
GBOX * bbox
Definition: liblwgeom.h:530
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:173
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
Definition: lwgeom_api.c:37
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
Definition: g_serialized.c:65
LWPOLY ** geoms
Definition: liblwgeom.h:495
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
Definition: liblwgeom.h:2005
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:284
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
Definition: lwpoint.c:47
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition: lwutil.c:261
uint32_t maxrings
Definition: liblwgeom.h:455
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3121
LWGEOM ** geoms
Definition: liblwgeom.h:508
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1835
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:254
LWTRIANGLE ** geoms
Definition: liblwgeom.h:586
void lwpsurface_release(LWPSURFACE *lwpsurface)
GBOX * gserialized_calculate_gbox_geocentric(const GSERIALIZED *g)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates...
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
uint8_t flags
Definition: liblwgeom.h:490
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:777
uint8_t type
Definition: liblwgeom.h:439
GBOX * bbox
Definition: liblwgeom.h:569
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Construct a new POINTARRAY, referencing to the data from ptlist.
Definition: ptarray.c:293
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
Definition: lwout_geojson.c:48
uint32_t ngeoms
Definition: liblwgeom.h:519
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:712
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition: lwgeom.c:241
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition: lwgeom.c:727
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition: ptarray.c:187
LWPOINT * lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
POINTARRAY ** rings
Definition: liblwgeom.h:456
int getPoint2d_p_ro(const POINTARRAY *pa, uint32_t n, POINT2D **point)
New function to read doubles directly from the double* coordinate array of an aligned lwgeom POINTARR...
Definition: lwgeodetic.c:2775
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1086
double e
Definition: liblwgeom.h:315
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition: lwgeom.c:314
POINTARRAY * ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist)
Construct a new POINTARRAY, copying in the data from ptlist.
Definition: ptarray.c:307
uint8_t precision
Definition: cu_in_twkb.c:25
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:173
LWPOINT ** geoms
Definition: liblwgeom.h:469
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:628
double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing max distance calculation.
Definition: measures.c:169
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
LWCURVEPOLY * lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwcurvepoly.c:36
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form...
Definition: g_box.c:446
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints)
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:187
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:39
int32_t srid
Definition: liblwgeom.h:505
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:104
double ymax
Definition: liblwgeom.h:294
int lwgeom_has_arc(const LWGEOM *geom)
Definition: lwstroke.c:54
LWGEOM * lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:48
void printLWLINE(LWLINE *line)
Definition: lwline.c:88
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:324
enum LWORD_T LWORD
Ordinate names.
char * s
Definition: cu_in_wkt.c:23
double y
Definition: liblwgeom.h:327
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
uint8_t flags
Definition: liblwgeom.h:529
void(* lwreporter)(const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:217
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:2078
LWCOLLECTION * lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset)
Given a geometry clip based on the from/to range of one of its ordinates (x, y, z, m).
double e_sq
Definition: liblwgeom.h:316
double z
Definition: liblwgeom.h:351
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:198
tuple x
Definition: pixval.py:53
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
LWCOMPOUND * lwcompound_construct_from_lwline(const LWLINE *lwpoly)
Construct an equivalent compound curve from a linestring.
Definition: lwcompound.c:204
LWMLINE * lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end)
Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure betwe...
Definition: lwmline.c:56
uint8_t type
Definition: liblwgeom.h:580
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:475
Datum distance(PG_FUNCTION_ARGS)
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:60
double y
Definition: liblwgeom.h:345
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:1940
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:945
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
int32_t srid
Definition: liblwgeom.h:409
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:50
uint8_t flags
Definition: liblwgeom.h:290
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:575
char * gserialized_to_string(const GSERIALIZED *g)
Return a WKT representation of the gserialized geometry.
Definition: g_serialized.c:192
void lwtriangle_free(LWTRIANGLE *triangle)
Definition: lwtriangle.c:69
void *(* lwreallocator)(void *mem, size_t size)
Definition: liblwgeom.h:215
void lwpsurface_free(LWPSURFACE *psurf)
Definition: lwpsurface.c:39
int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2)
Return -1 if g1 is "less than" g2, 1 if g1 is "greater than" g2 and 0 if g1 and g2 are the "same"...
Definition: g_serialized.c:293
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:789
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:178
const POINT4D * getPoint4d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT4D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:398
unsigned int geohash_point_as_int(POINT2D *pt)
Definition: lwalgorithm.c:647
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition: lwgeom.c:1113
double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist)
Find the time of closest point of approach.
LWPOINT * lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged)
int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition: lwkmeans.c:127
LWGEOM * lwgeom_locate_along(const LWGEOM *lwin, double m, double offset)
Determine the location(s) along a measured line where m occurs and return as a multipoint.
int gbox_merge(const GBOX *new_box, GBOX *merged_box)
Update the merged GBOX to be large enough to include itself and the new box.
Definition: g_box.c:264
uint8_t type
Definition: liblwgeom.h:567
LWCOLLECTION * lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist)
Definition: lwcollection.c:236
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1228
GBOX * bbox
Definition: liblwgeom.h:441
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
Symmetric linearization means that the output vertices would be the same no matter the order of the p...
Definition: liblwgeom.h:2211
POINT2D * center
Definition: liblwgeom.h:1643
POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:191
void lwcollection_release(LWCOLLECTION *lwcollection)
Definition: lwcollection.c:36
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:537
uint8_t flags
Definition: liblwgeom.h:407
uint32_t ngeoms
Definition: liblwgeom.h:480
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:213
LWLINE ** geoms
Definition: liblwgeom.h:482
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:338
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
Definition: lwgeodetic.c:2788
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition: lwgeom.c:1895
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:214
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:205
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:358
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:160
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:107
Tolerance expresses the number of segments to use for each quarter of circle (quadrant).
Definition: liblwgeom.h:2187
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
Definition: g_box.c:204
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
Definition: lwalgorithm.c:838
GBOX * bbox
Definition: liblwgeom.h:408
void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1461
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:728
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:496
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
double a
Definition: liblwgeom.h:312
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
char * hexbytes_from_bytes(const uint8_t *bytes, size_t size)
Definition: lwout_wkb.c:39
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition: lwgeom.c:749
LWGEOM * lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length)
Derive a new geometry with vertices added to ensure no vertex is more than max_seg_length (in radians...
Definition: lwgeodetic.c:1652
LWMPOINT * lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints)
LWPOINT * lwpoint_make4d(int srid, double x, double y, double z, double m)
Definition: lwpoint.c:195
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition: lwpoint.c:52
int32_t srid
Definition: liblwgeom.h:453
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition: lwgeom.c:279
uint32_t size
Definition: liblwgeom.h:380
LWGEOM ** geoms
Definition: liblwgeom.h:560
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:219
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:223
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1850
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: g_box.c:194
int lwgeom_dimension(const LWGEOM *geom)
For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension...
Definition: lwgeom.c:1280
double mmin
Definition: liblwgeom.h:297
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
Definition: measures3d.c:792
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:678
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:440
double zmin
Definition: liblwgeom.h:295
int lwgeom_is_simple(const LWGEOM *lwgeom)
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:116
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1743
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:879
void(*) typedef void(*) voi lwgeom_set_handlers)(lwallocator allocator, lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, lwreporter noticereporter)
Install custom memory management and error handling functions you want your application to use...
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
LWGEOM ** geoms
Definition: liblwgeom.h:547
double lwgeom_length(const LWGEOM *geom)
Definition: lwgeom.c:1917
uint32_t maxgeoms
Definition: liblwgeom.h:559
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:261
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:159
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:232
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:679
void printLWPOINT(LWPOINT *point)
Definition: lwpoint.c:224
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing min distance calculation.
Definition: measures.c:202
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition: lwgeom.c:259
Retain angle instructs the engine to try its best to retain the requested angle between generating ra...
Definition: liblwgeom.h:2231
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:542
int32_t srid
Definition: liblwgeom.h:557
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:452
uint64_t gbox_get_sortable_hash(const GBOX *g)
Return a sortable key based on the center point of the GBOX.
Definition: g_serialized.c:258
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
uint8_t type
Definition: liblwgeom.h:395
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
Definition: ptarray.c:96
uint8_t type
Definition: liblwgeom.h:515
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: g_serialized.c:60
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:72
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
double mmax
Definition: liblwgeom.h:298
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:342
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:334
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition: lwutil.c:171
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition: lwgeom.c:274
POINTARRAY * points
Definition: liblwgeom.h:443
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
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...
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom)
Definition: lwgeom.c:789
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:642
CG_LINE_CROSS_TYPE
The return values of lwline_crossing_direction()
Definition: liblwgeom.h:1510
uint32_t nrings
Definition: liblwgeom.h:532
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition: lwgeom.c:1496
double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d max distance calculation.
Definition: measures3d.c:314
LWGEOM * lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj)
Definition: lwgeom.c:309
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:42
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:245
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Definition: lwgeodetic.c:2096
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2322
LWORD_T
Ordinate names.
Definition: liblwgeom.h:112
uint32_t gserialized_header_size(const GSERIALIZED *gser)
Returns the size in bytes of the header, from the start of the object up to the type number...
Definition: g_serialized.c:76
uint8_t flags
Definition: liblwgeom.h:451
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:404
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:64
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition: ptarray.c:555
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:717
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void * lwalloc(size_t size)
Definition: lwutil.c:229
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1386
uint8_t flags
Definition: liblwgeom.h:581
uint32_t ngeoms
Definition: liblwgeom.h:545
void lwmline_release(LWMLINE *lwline)
Definition: lwmline.c:32
LWGEOM * lwgeom_unstroke(const LWGEOM *geom)
Definition: lwstroke.c:1086
GBOX * bbox
Definition: liblwgeom.h:491
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_wkb.c:770
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
Definition: g_box.c:122
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2386
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
uint32_t ngeoms
Definition: liblwgeom.h:584
uint32_t gserialized_max_header_size(void)
Returns the size in bytes to read from toast to get the basic information from a geometry: GSERIALIZE...
Definition: g_serialized.c:70
uint8_t flags
Definition: liblwgeom.h:418
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2422
LWGEOM * lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags)
Definition: lwstroke.c:681
int32_t srid
Definition: liblwgeom.h:570
int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point)
Definition: lwgeom_api.c:257
uint8_t * lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size)
Definition: lwout_twkb.c:614
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:356
void lwline_release(LWLINE *lwline)
Definition: lwline.c:134
unsigned char uint8_t
Definition: uthash.h:79
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:39
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:158
int32_t srid
Definition: liblwgeom.h:466
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:930
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
uint32_t maxgeoms
Definition: liblwgeom.h:494
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1190
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:284
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:47
int lwpointiterator_peek(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assigns the next point in the iterator to p.
Definition: lwiterator.c:195
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:89
int32_t srid
Definition: liblwgeom.h:583
int gserialized_calculate_gbox_geocentric_p(const GSERIALIZED *g, GBOX *g_box)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates...
int32_t srid
Definition: liblwgeom.h:492
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:213
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
tuple y
Definition: pixval.py:54
int32_t srid
Definition: liblwgeom.h:431
uint32_t maxrings
Definition: liblwgeom.h:533
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:399
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
GBOX * bbox
Definition: liblwgeom.h:478
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition: lwcompound.c:88
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:674
uint8_t type
Definition: liblwgeom.h:489
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1962
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:43
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
uint8_t flags
Definition: liblwgeom.h:382
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:318
double zmax
Definition: liblwgeom.h:277
int32_t srid
Definition: liblwgeom.h:479
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition: lwtriangle.c:82
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
uint8_t flags
Definition: liblwgeom.h:429
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:99
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
POINTARRAY * points
Definition: liblwgeom.h:421
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:532
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:299
double zmin
Definition: liblwgeom.h:276
uint32_t maxgeoms
Definition: liblwgeom.h:520
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:294
uint32_t npoints
Definition: liblwgeom.h:370
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition: ptarray.c:597