PostGIS  2.5.7dev-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 #define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1
36 #include "proj_api.h"
37 
38 #if defined(PJ_VERSION) && PJ_VERSION >= 490
39 /* Enable new geodesic functions */
40 #define PROJ_GEODESIC 1
41 #else
42 /* Use the old (pre-2.2) geodesic functions */
43 #define PROJ_GEODESIC 0
44 #endif
45 
65 #define LIBLWGEOM_VERSION "2.5.9"
66 #define LIBLWGEOM_VERSION_MAJOR "2"
67 #define LIBLWGEOM_VERSION_MINOR "5"
68 #define LIBLWGEOM_GEOS_VERSION "38"
69 
71 const char* lwgeom_version(void);
72 
76 #define LW_TRUE 1
77 #define LW_FALSE 0
78 #define LW_UNKNOWN 2
79 #define LW_FAILURE 0
80 #define LW_SUCCESS 1
81 
85 #define POINTTYPE 1
86 #define LINETYPE 2
87 #define POLYGONTYPE 3
88 #define MULTIPOINTTYPE 4
89 #define MULTILINETYPE 5
90 #define MULTIPOLYGONTYPE 6
91 #define COLLECTIONTYPE 7
92 #define CIRCSTRINGTYPE 8
93 #define COMPOUNDTYPE 9
94 #define CURVEPOLYTYPE 10
95 #define MULTICURVETYPE 11
96 #define MULTISURFACETYPE 12
97 #define POLYHEDRALSURFACETYPE 13
98 #define TRIANGLETYPE 14
99 #define TINTYPE 15
100 
101 #define NUMTYPES 16
102 
107 #define WKBZOFFSET 0x80000000
108 #define WKBMOFFSET 0x40000000
109 #define WKBSRIDFLAG 0x20000000
110 #define WKBBBOXFLAG 0x10000000
111 
113 typedef enum LWORD_T {
114  LWORD_X = 0,
115  LWORD_Y = 1,
116  LWORD_Z = 2,
117  LWORD_M = 3
119 
120 /**********************************************************************
121 ** Spherical radius.
122 ** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
123 ** the XVII General Assembly of the IUGG in Canberra.
124 ** http://en.wikipedia.org/wiki/Earth_radius
125 ** http://en.wikipedia.org/wiki/World_Geodetic_System
126 */
127 
128 #define WGS84_MAJOR_AXIS 6378137.0
129 #define WGS84_INVERSE_FLATTENING 298.257223563
130 #define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
131 #define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
132 
133 
140 #define FLAGS_GET_Z(flags) ((flags) & 0x01)
141 #define FLAGS_GET_M(flags) (((flags) & 0x02)>>1)
142 #define FLAGS_GET_BBOX(flags) (((flags) & 0x04)>>2)
143 #define FLAGS_GET_GEODETIC(flags) (((flags) & 0x08)>>3)
144 #define FLAGS_GET_READONLY(flags) (((flags) & 0x10)>>4)
145 #define FLAGS_GET_SOLID(flags) (((flags) & 0x20)>>5)
146 #define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | 0x01) : ((flags) & 0xFE))
147 #define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | 0x02) : ((flags) & 0xFD))
148 #define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | 0x04) : ((flags) & 0xFB))
149 #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | 0x08) : ((flags) & 0xF7))
150 #define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | 0x10) : ((flags) & 0xEF))
151 #define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | 0x20) : ((flags) & 0xDF))
152 #define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
153 #define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
154 #define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
155 
165 #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
166 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
167 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
168 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
169 #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
170 #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
171 #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
172 #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
173 #define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
174 
179 #define SRID_MAXIMUM 999999
180 
185 #define SRID_USER_MAXIMUM 998999
186 
188 #define SRID_UNKNOWN 0
189 #define SRID_IS_UNKNOWN(x) ((int)x<=0)
190 
191 /* Invalid SRID value, for internal use */
192 #define SRID_INVALID (999999 + 2)
193 
194 /*
195 ** EPSG WGS84 geographics, OGC standard default SRS, better be in
196 ** the SPATIAL_REF_SYS table!
197 */
198 #define SRID_DEFAULT 4326
199 
200 #ifndef __GNUC__
201 # define __attribute__(x)
202 #endif
203 
210 extern int clamp_srid(int srid);
211 
212 /* Raise an lwerror if srids do not match */
213 void error_if_srid_mismatch(int srid1, int srid2);
214 
218 typedef void* (*lwallocator)(size_t size);
219 typedef void* (*lwreallocator)(void *mem, size_t size);
220 typedef void (*lwfreeor)(void* mem);
221 typedef void (*lwreporter)(const char* fmt, va_list ap)
222  __attribute__ (( format(printf, 1, 0) ));
223 typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
224  __attribute__ (( format(printf, 2,0) ));
225 
232 extern void lwgeom_set_handlers(lwallocator allocator,
233  lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
234  lwreporter noticereporter);
235 
236 extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
237 
250 extern void lwgeom_request_interrupt(void);
251 
255 extern void lwgeom_cancel_interrupt(void);
256 
267 typedef void (lwinterrupt_callback)();
269 
270 /******************************************************************/
271 
272 typedef struct {
273  double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
274 } AFFINE;
275 
276 /******************************************************************/
277 
278 typedef struct
279 {
280  double xmin, ymin, zmin;
281  double xmax, ymax, zmax;
282  int32_t srid;
283 }
284 BOX3D;
285 
286 /******************************************************************
287 * GBOX structure.
288 * We include the flags (information about dimensionality),
289 * so we don't have to constantly pass them
290 * into functions that use the GBOX.
291 */
292 typedef struct
293 {
295  double xmin;
296  double xmax;
297  double ymin;
298  double ymax;
299  double zmin;
300  double zmax;
301  double mmin;
302  double mmax;
303 } GBOX;
304 
305 
306 /******************************************************************
307 * SPHEROID
308 *
309 * Standard definition of an ellipsoid (what wkt calls a spheroid)
310 * f = (a-b)/a
311 * e_sq = (a*a - b*b)/(a*a)
312 * b = a - fa
313 */
314 typedef struct
315 {
316  double a; /* semimajor axis */
317  double b; /* semiminor axis b = (a - fa) */
318  double f; /* flattening f = (a-b)/a */
319  double e; /* eccentricity (first) */
320  double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
321  double radius; /* spherical average radius = (2*a+b)/3 */
322  char name[20]; /* name of ellipse */
323 }
324 SPHEROID;
325 
326 /******************************************************************
327 * POINT2D, POINT3D, POINT3DM, POINT4D
328 */
329 typedef struct
330 {
331  double x, y;
332 }
333 POINT2D;
334 
335 typedef struct
336 {
337  double x, y, z;
338 }
339 POINT3DZ;
340 
341 typedef struct
342 {
343  double x, y, z;
344 }
345 POINT3D;
346 
347 typedef struct
348 {
349  double x, y, m;
350 }
351 POINT3DM;
352 
353 typedef struct
354 {
355  double x, y, z, m;
356 }
357 POINT4D;
358 
359 /******************************************************************
360 * POINTARRAY
361 * Point array abstracts a lot of the complexity of points and point lists.
362 * It handles 2d/3d translation
363 * (2d points converted to 3d will have z=0 or NaN)
364 * DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
365 */
366 typedef struct
367 {
368  /* Array of POINT 2D, 3D or 4D, possibly misaligned. */
370 
371  /* Use FLAGS_* macros to handle */
373 
374  uint32_t npoints; /* how many points we are currently storing */
375  uint32_t maxpoints; /* how many points we have space for in serialized_pointlist */
376 }
377 POINTARRAY;
378 
379 /******************************************************************
380 * GSERIALIZED
381 */
382 typedef struct
383 {
384  uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
385  uint8_t srid[3]; /* 24 bits of SRID */
386  uint8_t flags; /* HasZ, HasM, HasBBox, IsGeodetic, IsReadOnly */
387  uint8_t data[1]; /* See gserialized.txt */
388 } GSERIALIZED;
389 
390 
391 /******************************************************************
392 * LWGEOM (any geometry type)
393 *
394 * Abstract type, note that 'type', 'bbox' and 'srid' are available in
395 * all geometry variants.
396 */
397 typedef struct
398 {
402  int32_t srid;
403  void *data;
404 }
405 LWGEOM;
406 
407 /* POINTYPE */
408 typedef struct
409 {
410  uint8_t type; /* POINTTYPE */
413  int32_t srid;
414  POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
415 }
416 LWPOINT; /* "light-weight point" */
417 
418 /* LINETYPE */
419 typedef struct
420 {
421  uint8_t type; /* LINETYPE */
424  int32_t srid;
425  POINTARRAY *points; /* array of POINT3D */
426 }
427 LWLINE; /* "light-weight line" */
428 
429 /* TRIANGLE */
430 typedef struct
431 {
435  int32_t srid;
437 }
438 LWTRIANGLE;
439 
440 /* CIRCSTRINGTYPE */
441 typedef struct
442 {
443  uint8_t type; /* CIRCSTRINGTYPE */
446  int32_t srid;
447  POINTARRAY *points; /* array of POINT(3D/3DM) */
448 }
449 LWCIRCSTRING; /* "light-weight circularstring" */
450 
451 /* POLYGONTYPE */
452 typedef struct
453 {
454  uint8_t type; /* POLYGONTYPE */
457  int32_t srid;
458  uint32_t nrings; /* how many rings we are currently storing */
459  uint32_t maxrings; /* how many rings we have space for in **rings */
460  POINTARRAY **rings; /* list of rings (list of points) */
461 }
462 LWPOLY; /* "light-weight polygon" */
463 
464 /* MULTIPOINTTYPE */
465 typedef struct
466 {
470  int32_t srid;
471  uint32_t ngeoms; /* how many geometries we are currently storing */
472  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
474 }
475 LWMPOINT;
476 
477 /* MULTILINETYPE */
478 typedef struct
479 {
483  int32_t srid;
484  uint32_t ngeoms; /* how many geometries we are currently storing */
485  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
487 }
488 LWMLINE;
489 
490 /* MULTIPOLYGONTYPE */
491 typedef struct
492 {
496  int32_t srid;
497  uint32_t ngeoms; /* how many geometries we are currently storing */
498  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
500 }
501 LWMPOLY;
502 
503 /* COLLECTIONTYPE */
504 typedef struct
505 {
509  int32_t srid;
510  uint32_t ngeoms; /* how many geometries we are currently storing */
511  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
513 }
515 
516 /* COMPOUNDTYPE */
517 typedef struct
518 {
519  uint8_t type; /* COMPOUNDTYPE */
522  int32_t srid;
523  uint32_t ngeoms; /* how many geometries we are currently storing */
524  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
526 }
527 LWCOMPOUND; /* "light-weight compound line" */
528 
529 /* CURVEPOLYTYPE */
530 typedef struct
531 {
532  uint8_t type; /* CURVEPOLYTYPE */
535  int32_t srid;
536  uint32_t nrings; /* how many rings we are currently storing */
537  uint32_t maxrings; /* how many rings we have space for in **rings */
538  LWGEOM **rings; /* list of rings (list of points) */
539 }
540 LWCURVEPOLY; /* "light-weight polygon" */
541 
542 /* MULTICURVE */
543 typedef struct
544 {
548  int32_t srid;
549  uint32_t ngeoms; /* how many geometries we are currently storing */
550  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
552 }
553 LWMCURVE;
554 
555 /* MULTISURFACETYPE */
556 typedef struct
557 {
561  int32_t srid;
562  uint32_t ngeoms; /* how many geometries we are currently storing */
563  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
565 }
566 LWMSURFACE;
567 
568 /* POLYHEDRALSURFACETYPE */
569 typedef struct
570 {
574  int32_t srid;
575  uint32_t ngeoms; /* how many geometries we are currently storing */
576  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
578 }
579 LWPSURFACE;
580 
581 /* TINTYPE */
582 typedef struct
583 {
587  int32_t srid;
588  uint32_t ngeoms; /* how many geometries we are currently storing */
589  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
591 }
592 LWTIN;
593 
594 /* Casts LWGEOM->LW* (return NULL if cast is illegal) */
595 extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
596 extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
597 extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
598 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
599 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
600 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
601 extern LWPOINT *lwgeom_as_lwpoint(const LWGEOM *lwgeom);
602 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
603 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
604 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
605 extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
606 extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
607 extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
608 extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
609 extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
610 
611 /* Casts LW*->LWGEOM (always cast) */
612 extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
613 extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
614 extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
615 extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
616 extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
617 extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
618 extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
619 extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
620 extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
621 extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
622 extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
623 extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
624 extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
625 
626 
627 extern LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom);
628 extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
629 extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
630 extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
631 extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
632 extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
633 
635 
636 
637 /***********************************************************************
638 ** Utility functions for flag byte and srid_flag integer.
639 */
640 
644 extern uint8_t gflags(int hasz, int hasm, int geodetic);
645 
650 extern uint32_t gserialized_get_type(const GSERIALIZED *g);
651 
657 
662 extern uint32_t gserialized_header_size(const GSERIALIZED *gser);
663 
668 extern int32_t gserialized_get_srid(const GSERIALIZED *g);
669 
674 extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
675 
682 extern int gserialized_is_empty(const GSERIALIZED *g);
683 
687 extern int gserialized_has_bbox(const GSERIALIZED *gser);
688 
692 extern int gserialized_has_z(const GSERIALIZED *gser);
693 
697 extern int gserialized_has_m(const GSERIALIZED *gser);
698 
702 extern int gserialized_is_geodetic(const GSERIALIZED *gser);
703 
708 extern int gserialized_get_zm(const GSERIALIZED *gser);
709 
713 extern int gserialized_ndims(const GSERIALIZED *gser);
714 
724 extern int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2);
725 
732 extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
733 extern void lwgeom_drop_srid(LWGEOM *lwgeom);
734 
741 extern void lwgeom_add_bbox(LWGEOM *lwgeom);
745 extern void lwgeom_refresh_bbox(LWGEOM *lwgeom);
749 extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
750 
758 extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
759 
763 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
764 
765 /******************************************************************/
766 /* Functions that work on type numbers */
767 
771 extern int lwtype_is_collection(uint8_t type);
772 
777 
782 extern const char *lwtype_name(uint8_t type);
784 
785 /******************************************************************/
786 
787 /*
788  * copies a point from the point array into the parameter point
789  * will set point's z=0 (or NaN) if pa is 2d
790  * will set point's m=0 (or NaN) if pa is 3d or 2d
791  * NOTE: point is a real POINT3D *not* a pointer
792  */
793 extern POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n);
794 
795 /*
796  * copies a point from the point array into the parameter point
797  * will set point's z=0 (or NaN) if pa is 2d
798  * will set point's m=0 (or NaN) if pa is 3d or 2d
799  * NOTE: this will modify the point4d pointed to by 'point'.
800  */
801 extern int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point);
802 
803 /*
804  * copies a point from the point array into the parameter point
805  * will set point's z=0 (or NaN) if pa is 2d
806  * NOTE: point is a real POINT3D *not* a pointer
807  */
808 extern POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n);
809 extern POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n);
810 
811 /*
812  * copies a point from the point array into the parameter point
813  * will set point's z=0 (or NaN) if pa is 2d
814  * NOTE: this will modify the point3d pointed to by 'point'.
815  */
816 extern int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point);
817 extern int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point);
818 
819 
820 /*
821  * copies a point from the point array into the parameter point
822  * z value (if present is not returned)
823  * NOTE: point is a real POINT3D *not* a pointer
824  */
825 extern POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n);
826 
827 /*
828  * copies a point from the point array into the parameter point
829  * z value (if present is not returned)
830  * NOTE: this will modify the point2d pointed to by 'point'.
831  */
832 extern int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point);
833 
840 extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, uint32_t n);
841 
848 extern const POINT3DZ* getPoint3dz_cp(const POINTARRAY *pa, uint32_t n);
849 
856 extern const POINT4D* getPoint4d_cp(const POINTARRAY *pa, uint32_t n);
857 
858 /*
859  * set point N to the given value
860  * NOTE that the pointarray can be of any
861  * dimension, the appropriate ordinate values
862  * will be extracted from it
863  *
864  * N must be a valid point index
865  */
866 extern void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d);
867 
868 /*
869  * get a pointer to nth point of a POINTARRAY
870  * You'll need to cast it to appropriate dimensioned point.
871  * Note that if you cast to a higher dimensional point you'll
872  * possibly corrupt the POINTARRAY.
873  *
874  * WARNING: Don't cast this to a POINT !
875  * it would not be reliable due to memory alignment constraints
876  */
877 extern uint8_t *getPoint_internal(const POINTARRAY *pa, uint32_t n);
878 
879 /*
880  * size of point represeneted in the POINTARRAY
881  * 16 for 2d, 24 for 3d, 32 for 4d
882  */
883 extern size_t ptarray_point_size(const POINTARRAY *pa);
884 
885 
891 extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
892 
896 extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
897 
901 extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
902 
908 extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
909 
915 extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
916 
928 extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
929 
934 extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where);
935 
940 extern int ptarray_remove_point(POINTARRAY *pa, uint32_t where);
941 
953 extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
954 
961 
968 extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
969 
970 extern int ptarray_is_closed(const POINTARRAY *pa);
971 extern int ptarray_is_closed_2d(const POINTARRAY *pa);
972 extern int ptarray_is_closed_3d(const POINTARRAY *pa);
973 extern int ptarray_is_closed_z(const POINTARRAY *pa);
975 
981 extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
982  double tolerance);
983 
984 
988 extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
989 extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
990 extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
991 extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
992 
993 extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
994 extern LWGEOM* lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint);
995 extern LWGEOM* lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm);
996 
997 /*
998  * Force to use SFS 1.1 geometry type
999  * (rather than SFS 1.2 and/or SQL/MM)
1000  */
1001 extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
1002 
1003 
1004 /*--------------------------------------------------------
1005  * all the base types (point/line/polygon) will have a
1006  * basic constructor, basic de-serializer, basic serializer,
1007  * bounding box finder and (TODO) serialized form size finder.
1008  *--------------------------------------------------------*/
1009 
1010 /*
1011  * convenience functions to hide the POINTARRAY
1012  */
1013 extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
1014 extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
1015 extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
1016 extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
1017 
1018 /******************************************************************
1019  * LWLINE functions
1020  ******************************************************************/
1021 
1025 extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1026 
1030 extern POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat);
1031 
1032 /******************************************************************
1033  * LWPOLY functions
1034  ******************************************************************/
1035 
1040 extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1041 
1046 extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1047 
1052 extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1053 
1058 extern LWCOMPOUND* lwcompound_construct_from_lwline(const LWLINE *lwpoly);
1059 
1065 
1066 
1067 /******************************************************************
1068  * LWGEOM functions
1069  ******************************************************************/
1070 
1071 extern int lwcollection_ngeoms(const LWCOLLECTION *col);
1072 
1073 /* Given a generic geometry/collection, return the "simplest" form.
1074  * The elements of the homogenized collection are references to the
1075  * input geometry; a deep clone is not performed.
1076  * TODO: consider returning a geometry that does not reference the
1077  * input
1078  * */
1079 extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
1080 
1081 
1082 /******************************************************************
1083  * LWMULTIx and LWCOLLECTION functions
1084  ******************************************************************/
1085 
1087 
1088 /* WARNING: the output will contain references to geometries in the input, */
1089 /* so the result must be carefully released, not freed. */
1091 
1092 
1093 /******************************************************************
1094  * SERIALIZED FORM functions
1095  ******************************************************************/
1096 
1102 extern void lwgeom_set_srid(LWGEOM *geom, int srid);
1103 
1104 /*------------------------------------------------------
1105  * other stuff
1106  *
1107  * handle the double-to-float conversion. The results of this
1108  * will usually be a slightly bigger box because of the difference
1109  * between float8 and float4 representations.
1110  */
1111 
1112 extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1113 extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1114 
1115 void expand_box3d(BOX3D *box, double d);
1116 
1117 
1118 /****************************************************************
1119  * MEMORY MANAGEMENT
1120  ****************************************************************/
1121 
1122 /*
1123 * The *_free family of functions frees *all* memory associated
1124 * with the pointer. When the recursion gets to the level of the
1125 * POINTARRAY, the POINTARRAY is only freed if it is not flagged
1126 * as "read only". LWGEOMs constructed on top of GSERIALIZED
1127 * from PgSQL use read only point arrays.
1128 */
1129 
1130 extern void ptarray_free(POINTARRAY *pa);
1131 extern void lwpoint_free(LWPOINT *pt);
1132 extern void lwline_free(LWLINE *line);
1133 extern void lwpoly_free(LWPOLY *poly);
1134 extern void lwtriangle_free(LWTRIANGLE *triangle);
1135 extern void lwmpoint_free(LWMPOINT *mpt);
1136 extern void lwmline_free(LWMLINE *mline);
1137 extern void lwmpoly_free(LWMPOLY *mpoly);
1138 extern void lwpsurface_free(LWPSURFACE *psurf);
1139 extern void lwtin_free(LWTIN *tin);
1140 extern void lwcollection_free(LWCOLLECTION *col);
1141 extern void lwcircstring_free(LWCIRCSTRING *curve);
1142 extern void lwgeom_free(LWGEOM *geom);
1143 
1144 /*
1145 * The *_release family of functions frees the LWGEOM structures
1146 * surrounding the POINTARRAYs but leaves the POINTARRAYs
1147 * intact. Useful when re-shaping geometries between types,
1148 * or splicing geometries together.
1149 */
1150 
1151 extern void lwpoint_release(LWPOINT *lwpoint);
1152 extern void lwline_release(LWLINE *lwline);
1153 extern void lwpoly_release(LWPOLY *lwpoly);
1154 extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1155 extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1156 extern void lwmpoint_release(LWMPOINT *lwpoint);
1157 extern void lwmline_release(LWMLINE *lwline);
1158 extern void lwmpoly_release(LWMPOLY *lwpoly);
1159 extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1160 extern void lwtin_release(LWTIN *lwtin);
1161 extern void lwcollection_release(LWCOLLECTION *lwcollection);
1162 extern void lwgeom_release(LWGEOM *lwgeom);
1163 
1164 
1165 /****************************************************************
1166 * Utility
1167 ****************************************************************/
1168 
1169 extern void printBOX3D(BOX3D *b);
1170 extern void printPA(POINTARRAY *pa);
1171 extern void printLWPOINT(LWPOINT *point);
1172 extern void printLWLINE(LWLINE *line);
1173 extern void printLWPOLY(LWPOLY *poly);
1174 extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1175 extern void printLWPSURFACE(LWPSURFACE *psurf);
1176 extern void printLWTIN(LWTIN *tin);
1177 
1178 extern float next_float_down(double d);
1179 extern float next_float_up(double d);
1180 
1181 /* general utilities 2D */
1182 extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1183 extern double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2);
1184 extern double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1185 extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1186 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1187 extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1188 extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1189 extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1190 extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1191 extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1192 extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1193 extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1194 
1195 /* 3D */
1196 extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1197 extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1198 
1199 extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1200 extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1201 extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1202 
1203 
1204 extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1205 extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1206 extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1207 extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1208 
1209 extern double lwgeom_area(const LWGEOM *geom);
1210 extern double lwgeom_length(const LWGEOM *geom);
1211 extern double lwgeom_length_2d(const LWGEOM *geom);
1212 extern double lwgeom_perimeter(const LWGEOM *geom);
1213 extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1214 extern int lwgeom_dimension(const LWGEOM *geom);
1215 
1216 extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, uint32_t where);
1217 extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where);
1218 
1219 extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1220 extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1221 extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where);
1222 
1223 extern double ptarray_length_2d(const POINTARRAY *pts);
1224 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1225 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1226 extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1227 
1228 extern LWGEOM* lwgeom_reverse(const LWGEOM *lwgeom);
1229 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1230 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1231 extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1232 
1233 extern void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F);
1234 
1239 extern int lwgeom_is_clockwise(LWGEOM *lwgeom);
1240 
1241 
1242 extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
1243 extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1244 
1245 /****************************************************************
1246 * READ/WRITE FUNCTIONS
1247 *
1248 * Coordinate writing functions, which will alter the coordinates
1249 * and potentially the structure of the input geometry. When
1250 * called from within PostGIS, the LWGEOM argument should be built
1251 * on top of a gserialized copy, created using
1252 * PG_GETARG_GSERIALIZED_P_COPY()
1253 ****************************************************************/
1254 
1255 extern void lwgeom_reverse_in_place(LWGEOM *lwgeom);
1256 extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1257 extern void lwgeom_longitude_shift(LWGEOM *lwgeom);
1258 extern void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed);
1259 extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1260 extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1261 extern void lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance);
1262 
1263 
1276 LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1277 
1278 
1288 extern int lwgeom_needs_bbox(const LWGEOM *geom);
1289 
1293 extern uint32_t lwgeom_count_vertices(const LWGEOM *geom);
1294 
1299 extern uint32_t lwgeom_count_rings(const LWGEOM *geom);
1300 
1305 extern int lwgeom_has_srid(const LWGEOM *geom);
1306 
1311 extern int lwgeom_is_empty(const LWGEOM *geom);
1312 
1317 extern int lwgeom_is_closed(const LWGEOM *geom);
1318 
1322 extern int lwgeom_dimensionality(const LWGEOM *geom);
1323 
1324 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
1325 extern char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1326 
1327 
1335 extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1336 
1340 extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1341 extern POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1342 
1343 
1344 /*
1345 * Geometry constructors. These constructors to not copy the point arrays
1346 * passed to them, they just take references, so do not free them out
1347 * from underneath the geometries.
1348 */
1349 extern LWPOINT* lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point);
1350 extern LWMPOINT *lwmpoint_construct(int srid, const POINTARRAY *pa);
1351 extern LWLINE* lwline_construct(int srid, GBOX *bbox, POINTARRAY *points);
1352 extern LWCIRCSTRING* lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points);
1353 extern LWPOLY* lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1354 extern LWCURVEPOLY* lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1355 extern LWTRIANGLE* lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points);
1356 extern LWCOLLECTION* lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1357 /*
1358 * Empty geometry constructors.
1359 */
1360 extern LWGEOM* lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1361 extern LWPOINT* lwpoint_construct_empty(int srid, char hasz, char hasm);
1362 extern LWLINE* lwline_construct_empty(int srid, char hasz, char hasm);
1363 extern LWPOLY* lwpoly_construct_empty(int srid, char hasz, char hasm);
1364 extern LWCURVEPOLY* lwcurvepoly_construct_empty(int srid, char hasz, char hasm);
1365 extern LWCIRCSTRING* lwcircstring_construct_empty(int srid, char hasz, char hasm);
1366 extern LWCOMPOUND* lwcompound_construct_empty(int srid, char hasz, char hasm);
1367 extern LWTRIANGLE* lwtriangle_construct_empty(int srid, char hasz, char hasm);
1368 extern LWMPOINT* lwmpoint_construct_empty(int srid, char hasz, char hasm);
1369 extern LWMLINE* lwmline_construct_empty(int srid, char hasz, char hasm);
1370 extern LWMPOLY* lwmpoly_construct_empty(int srid, char hasz, char hasm);
1371 extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1372 
1373 
1374 /* Other constructors */
1375 extern LWPOINT *lwpoint_make2d(int srid, double x, double y);
1376 extern LWPOINT *lwpoint_make3dz(int srid, double x, double y, double z);
1377 extern LWPOINT *lwpoint_make3dm(int srid, double x, double y, double m);
1378 extern LWPOINT *lwpoint_make4d(int srid, double x, double y, double z, double m);
1379 extern LWPOINT *lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p);
1380 extern LWLINE *lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms);
1381 extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1382 extern LWLINE *lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint);
1383 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1384 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1385 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1386 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1387 extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1388 extern LWPOLY *lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2);
1389 extern LWPOLY *lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1390 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1391 extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1392 
1393 /* Some point accessors */
1394 extern double lwpoint_get_x(const LWPOINT *point);
1395 extern double lwpoint_get_y(const LWPOINT *point);
1396 extern double lwpoint_get_z(const LWPOINT *point);
1397 extern double lwpoint_get_m(const LWPOINT *point);
1398 
1402 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1403 
1407 extern uint32_t lwgeom_get_type(const LWGEOM *geom);
1408 
1412 extern int lwgeom_has_z(const LWGEOM *geom);
1413 
1417 extern int lwgeom_has_m(const LWGEOM *geom);
1418 
1422 extern int lwgeom_ndims(const LWGEOM *geom);
1423 
1424 /*
1425  * Given a point, returns the location of closest point on pointarray
1426  * as a fraction of total length (0: first point -- 1: last point).
1427  *
1428  * If not-null, the third argument will be set to the actual distance
1429  * of the point from the pointarray.
1430  */
1431 extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1432 
1437 extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1438 extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1439 
1444 extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1445 
1451 extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1452 
1456 extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1457 
1468 extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1469 
1475 extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1476 
1481 extern int lwgeom_is_trajectory(const LWGEOM *geom);
1482 extern int lwline_is_trajectory(const LWLINE *geom);
1483 
1484 /*
1485  * Ensure every segment is at most 'dist' long.
1486  * Returned LWGEOM might is unchanged if a POINT.
1487  */
1488 extern LWGEOM *lwgeom_segmentize2d(const LWGEOM *line, double dist);
1489 extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1490 extern LWLINE *lwline_segmentize2d(const LWLINE *line, double dist);
1491 extern LWPOLY *lwpoly_segmentize2d(const LWPOLY *line, double dist);
1492 extern LWCOLLECTION *lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist);
1493 
1494 /*
1495  * Point density functions
1496  */
1497 extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, uint32_t npoints);
1498 extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints);
1499 extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints);
1500 
1501 /*
1502  * Geometric median
1503  */
1504 extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1505 extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1506 
1510 char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1511 unsigned int geohash_point_as_int(POINT2D *pt);
1512 
1513 
1525 };
1526 
1530 int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1531 
1535 LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1536 
1542 #define LW_GML_IS_DIMS (1<<0)
1544 #define LW_GML_IS_DEGREE (1<<1)
1546 #define LW_GML_SHORTLINE (1<<2)
1548 #define LW_GML_EXTENT (1<<4)
1549 
1550 
1551 #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1552 #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1560 #define LW_X3D_FLIP_XY (1<<0)
1561 #define LW_X3D_USE_GEOCOORDS (1<<1)
1562 #define X3D_USE_GEOCOORDS(x) ((x) & LW_X3D_USE_GEOCOORDS)
1563 
1564 
1565 
1566 extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1567 extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1571 extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1572 extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1573 extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1574 extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1575 extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1576 extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1577 extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1578 
1588 extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1589 
1595 extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1596 
1600 extern void spheroid_init(SPHEROID *s, double a, double b);
1601 
1607 extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1608 
1612 extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1613 
1618 extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1619 
1623 extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1624 
1629 extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1630 
1635 extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1636 
1641 extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1642 
1647 extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1648 
1649 typedef struct {
1651  double radius;
1653 
1655 
1656 /* Calculates the minimum circle that encloses all of the points in g, using a
1657  * two-dimensional implementation of the algorithm proposed in:
1658  *
1659  * Welzl, Emo (1991), "Smallest enclosing disks (balls and elipsoids)."
1660  * New Results and Trends in Computer Science (H. Maurer, Ed.), Lecture Notes
1661  * in Computer Science, 555 (1991) 359-370.
1662  *
1663  * Available online at the time of this writing at
1664  * https://www.inf.ethz.ch/personal/emo/PublFiles/SmallEnclDisk_LNCS555_91.pdf
1665  *
1666  * Returns NULL if the circle could not be calculated.
1667  */
1668 extern LWBOUNDINGCIRCLE* lwgeom_calculate_mbc(const LWGEOM* g);
1669 
1682 extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1683 
1684 
1685 struct LWPOINTITERATOR;
1686 typedef struct LWPOINTITERATOR LWPOINTITERATOR;
1687 
1692 
1698 
1703 
1708 
1714 extern int lwpointiterator_modify_next(LWPOINTITERATOR* s, const POINT4D* p);
1715 
1723 
1729 
1730 
1734 extern uint8_t parse_hex(char *str);
1735 
1739 extern void deparse_hex(uint8_t str, char *result);
1740 
1741 
1742 
1743 /***********************************************************************
1744 ** Functions for managing serialized forms and bounding boxes.
1745 */
1746 
1753 
1760 
1765 extern char* gserialized_to_string(const GSERIALIZED *g);
1766 
1770 extern GSERIALIZED* gserialized_copy(const GSERIALIZED *g);
1771 
1775 extern int lwgeom_check_geodetic(const LWGEOM *geom);
1776 
1780 extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1781 
1785 extern int lwgeom_force_geodetic(LWGEOM *geom);
1786 
1790 extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1791 
1798 extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1799 
1805 extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1806 
1811 extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1812 
1817 extern int getPoint2d_p_ro(const POINTARRAY *pa, uint32_t n, POINT2D **point);
1818 
1822 extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1823 
1827 extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1828 
1832 int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1833 
1838 extern GBOX* gbox_new(uint8_t flags);
1839 
1844 extern void gbox_init(GBOX *gbox);
1845 
1849 extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1850 
1854 extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1855 
1859 extern void gbox_expand(GBOX *g, double d);
1860 
1864 extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
1865 
1869 extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1870 
1874 extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1875 
1879 extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1880 
1884 extern char* gbox_to_string(const GBOX *gbox);
1885 
1889 extern GBOX* gbox_copy(const GBOX *gbox);
1890 
1894 extern GBOX* gbox_from_string(const char *str);
1895 
1899 extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1900 
1904 extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1905 
1909 extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
1910 
1914 extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1915 
1920 extern size_t gbox_serialized_size(uint8_t flags);
1921 
1925 extern int gbox_same(const GBOX *g1, const GBOX *g2);
1926 
1930 extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
1931 
1936 extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
1937 
1944 extern void gbox_float_round(GBOX *gbox);
1945 
1949 extern int gbox_is_valid(const GBOX *gbox);
1950 
1955 extern uint64_t gbox_get_sortable_hash(const GBOX *g);
1956 
1961 extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
1962 
1968 extern size_t gserialized_from_lwgeom_size(const LWGEOM *geom);
1969 
1977 extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
1978 
1983 extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g);
1984 
1990 extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox);
1991 
1992 
2000 #define LW_PARSER_CHECK_MINPOINTS 1
2001 #define LW_PARSER_CHECK_ODD 2
2002 #define LW_PARSER_CHECK_CLOSURE 4
2003 #define LW_PARSER_CHECK_ZCLOSURE 8
2004 
2005 #define LW_PARSER_CHECK_NONE 0
2006 #define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
2007 
2013 {
2014  const char *wkinput; /* Copy of pointer to input WKT/WKB */
2015  uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
2016  size_t size; /* Size of serialized LWGEOM in bytes */
2017  LWGEOM *geom; /* Pointer to LWGEOM struct */
2018  const char *message; /* Error/warning message */
2019  int errcode; /* Error/warning number */
2020  int errlocation; /* Location of error */
2021  int parser_check_flags; /* Bitmask of validity checks run during this parse */
2022 }
2024 
2025 /*
2026  * Parser error messages (these must match the message array in lwgparse.c)
2027  */
2028 #define PARSER_ERROR_MOREPOINTS 1
2029 #define PARSER_ERROR_ODDPOINTS 2
2030 #define PARSER_ERROR_UNCLOSED 3
2031 #define PARSER_ERROR_MIXDIMS 4
2032 #define PARSER_ERROR_INVALIDGEOM 5
2033 #define PARSER_ERROR_INVALIDWKBTYPE 6
2034 #define PARSER_ERROR_INCONTINUOUS 7
2035 #define PARSER_ERROR_TRIANGLEPOINTS 8
2036 #define PARSER_ERROR_LESSPOINTS 9
2037 #define PARSER_ERROR_OTHER 10
2038 
2039 
2040 
2041 /*
2042  * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
2043  */
2045 {
2046  uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
2047  char *wkoutput; /* Pointer to WKT or WKB output */
2048  size_t size; /* Size of serialized LWGEOM in bytes */
2049  const char *message; /* Error/warning message */
2050  int errlocation; /* Location of error */
2051 }
2053 
2054 /*
2055  * Unparser error messages (these must match the message array in lwgunparse.c)
2056  */
2057 #define UNPARSER_ERROR_MOREPOINTS 1
2058 #define UNPARSER_ERROR_ODDPOINTS 2
2059 #define UNPARSER_ERROR_UNCLOSED 3
2060 
2061 
2062 /*
2063 ** Variants available for WKB and WKT output types
2064 */
2065 
2066 #define WKB_ISO 0x01
2067 #define WKB_SFSQL 0x02
2068 #define WKB_EXTENDED 0x04
2069 #define WKB_NDR 0x08
2070 #define WKB_XDR 0x10
2071 #define WKB_HEX 0x20
2072 #define WKB_NO_NPOINTS 0x40 /* Internal use only */
2073 #define WKB_NO_SRID 0x80 /* Internal use only */
2074 
2075 #define WKT_ISO 0x01
2076 #define WKT_SFSQL 0x02
2077 #define WKT_EXTENDED 0x04
2078 
2079 
2080 /*
2081 ** Variants available for TWKB
2082 */
2083 #define TWKB_BBOX 0x01 /* User wants bboxes */
2084 #define TWKB_SIZE 0x02 /* User wants sizes */
2085 #define TWKB_ID 0x04 /* User wants id */
2086 #define TWKB_NO_TYPE 0x10 /* No type because it is a sub geoemtry */
2087 #define TWKB_NO_ID 0x20 /* No ID because it is a subgeoemtry */
2088 #define TWKB_DEFAULT_PRECISION 0 /* Aim for 1m (or ft) rounding by default */
2089 
2090 /*
2091 ** New parsing and unparsing functions.
2092 */
2093 
2098 extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2099 
2105 extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2106 
2112 extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2113 
2117 extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2118 
2124 extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2125 
2130 extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2131 
2135 extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2136 
2137 extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2138 
2139 extern char* hexbytes_from_bytes(const uint8_t *bytes, size_t size);
2140 
2141 /*
2142 * WKT detailed parsing support
2143 */
2144 extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2145 void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
2146 void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
2147 
2148 
2149 /* Memory management */
2150 extern void *lwalloc(size_t size);
2151 extern void *lwrealloc(void *mem, size_t size);
2152 extern void lwfree(void *mem);
2153 
2154 /* Utilities */
2155 extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2156 
2157 /*
2158 * TWKB functions
2159 */
2160 
2165 extern LWGEOM* lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check);
2166 
2172 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);
2173 
2174 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);
2175 
2188 extern void lwgeom_trim_bits_in_place(LWGEOM *geom, int32_t prec_x, int32_t prec_y, int32_t prec_z, int32_t prec_m);
2189 
2190 /*******************************************************************************
2191  * SQLMM internal functions
2192  ******************************************************************************/
2193 
2194 int lwgeom_has_arc(const LWGEOM *geom);
2195 LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2196 LWGEOM *lwgeom_unstroke(const LWGEOM *geom);
2197 
2202 typedef enum {
2225 
2226 typedef enum {
2233 
2254 
2263 extern LWGEOM* lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags);
2264 
2265 /*******************************************************************************
2266  * GEOS proxy functions on LWGEOM
2267  ******************************************************************************/
2268 
2270 const char* lwgeom_geos_version(void);
2271 
2273 LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ;
2274 
2275 LWGEOM *lwgeom_normalize(const LWGEOM *geom);
2276 LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2277 LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2278 LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2279 LWGEOM *lwgeom_pointonsurface(const LWGEOM* geom);
2280 LWGEOM *lwgeom_centroid(const LWGEOM* geom);
2281 LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2282 LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2283 LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2284 LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2285 LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices);
2286 
2296 LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
2297 
2298 /*
2299  * Return the set of paths shared between two linear geometries,
2300  * and their direction (same or opposite).
2301  *
2302  * @param geom1 a lineal geometry
2303  * @param geom2 another lineal geometry
2304  *
2305  * Requires GEOS-3.3.0+
2306  */
2307 LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
2308 
2309 /*
2310  * An offset curve against the input line.
2311  *
2312  * @param geom a lineal geometry or collection of them
2313  * @param size offset distance. Offset left if negative and right if positive
2314  * @param quadsegs number of quadrature segments in curves (try 8)
2315  * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
2316  * @param mitreLimit (try 5.0)
2317  * @return derived geometry (linestring or multilinestring)
2318  *
2319  */
2320 LWGEOM* lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit);
2321 
2322 /*
2323  * Return true if the input geometry is "simple" as per OGC defn.
2324  *
2325  * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called
2326  * in that case)
2327  */
2328 int lwgeom_is_simple(const LWGEOM *lwgeom);
2329 
2330 
2331 /*******************************************************************************
2332  * PROJ4-dependent extra functions on LWGEOM
2333  ******************************************************************************/
2334 
2340 projPJ lwproj_from_string(const char* txt);
2341 
2348 int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj);
2349 int ptarray_transform(POINTARRAY *pa, projPJ inpj, projPJ outpj);
2350 
2351 
2352 /*******************************************************************************
2353  * GEOS-dependent extra functions on LWGEOM
2354  ******************************************************************************/
2355 
2363 LWGEOM* lwgeom_buildarea(const LWGEOM *geom) ;
2364 
2369 
2370 /*
2371  * Split (multi)polygon by line; (multi)line by (multi)line,
2372  * (multi)point or (multi)polygon boundary.
2373  *
2374  * Collections are accepted as first argument.
2375  * Returns all obtained pieces as a collection.
2376  */
2377 LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
2378 
2379 /*
2380  * Fully node a set of linestrings, using the least nodes preserving
2381  * all the input ones.
2382  */
2383 LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2384 
2394 LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly);
2395 
2405 LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2406 
2415 int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k);
2416 
2417 #endif /* !defined _LIBLWGEOM_H */
2418 
static uint8_t variant
Definition: cu_in_twkb.c:26
static uint8_t precision
Definition: cu_in_twkb.c:25
char * s
Definition: cu_in_wkt.c:23
char * r
Definition: cu_in_wkt.c:24
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition: lwgeom_api.c:682
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:1041
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:808
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
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:261
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:698
LW_LINEARIZE_TOLERANCE_TYPE
Semantic of the tolerance argument passed to lwcurve_linearize.
Definition: liblwgeom.h:2202
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_ANGLE
Tolerance expresses the maximum angle between the radii generating approximation line vertices,...
Definition: liblwgeom.h:2223
@ LW_LINEARIZE_TOLERANCE_TYPE_SEGS_PER_QUAD
Tolerance expresses the number of segments to use for each quarter of circle (quadrant).
Definition: liblwgeom.h:2208
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_DEVIATION
Tolerance expresses the maximum distance between an arbitrary point on the curve and the closest poin...
Definition: liblwgeom.h:2215
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:56
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition: lwgeom.c:315
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where)
Definition: lwcircstring.c:293
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:952
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
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:106
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1857
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:582
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:171
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
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:728
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: lwgeom.c:944
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition: lwgeom.c:1120
LWORD_T
Ordinate names.
Definition: liblwgeom.h:113
@ LWORD_Z
Definition: liblwgeom.h:116
@ LWORD_M
Definition: liblwgeom.h:117
@ LWORD_Y
Definition: liblwgeom.h:115
@ LWORD_X
Definition: liblwgeom.h:114
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition: lwgeom_api.c:732
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 * lwpoly_to_points(const LWPOLY *poly, uint32_t npoints)
void lwmpoly_release(LWMPOLY *lwpoly)
Definition: lwmpoly.c:34
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:916
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:223
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:440
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:539
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.
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2314
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:54
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing max distance calculation.
Definition: measures.c:169
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
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:2122
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:681
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2417
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition: g_box.c:87
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:2099
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:267
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
LWCIRCSTRING * lwcircstring_construct_empty(int srid, char hasz, char hasm)
Definition: lwcircstring.c:79
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
struct struct_lwgeom_unparser_result LWGEOM_UNPARSER_RESULT
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
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:571
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
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:1743
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:244
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
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:254
LWGEOM * lwgeom_force_4d(const LWGEOM *geom)
Definition: lwgeom.c:802
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:809
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:100
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:233
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:107
void lwgeom_trim_bits_in_place(LWGEOM *geom, int32_t prec_x, int32_t prec_y, int32_t prec_z, int32_t prec_m)
Trim the bits of an LWGEOM in place, to optimize it for compression.
Definition: lwgeom.c:2518
LWLINE * lwline_segmentize2d(const LWLINE *line, double dist)
Definition: lwline.c:141
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
LWMPOLY * lwmpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoly.c:40
void lwgeom_longitude_shift(LWGEOM *lwgeom)
Definition: lwgeom.c:996
LWCURVEPOLY * lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwcurvepoly.c:36
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:2187
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:712
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
@d1 start location (distance from start / total distance) @d2 end location (distance from start / tot...
Definition: ptarray.c:1060
LWCOLLECTION * lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist)
Definition: lwcollection.c:250
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
void lwpoint_release(LWPOINT *lwpoint)
Definition: lwpoint.c:256
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:708
LWGEOM * lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags)
Definition: lwstroke.c:735
char * hexbytes_from_bytes(const uint8_t *bytes, size_t size)
Definition: lwout_wkb.c:39
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.
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
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1552
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
LWGEOM * lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm)
Definition: lwmval.c:221
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2323
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:39
void(* lwfreeor)(void *mem)
Definition: liblwgeom.h:220
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition: lwgeom.c:371
LWCURVEPOLY * lwcurvepoly_construct_from_lwpoly(LWPOLY *lwpoly)
Construct an equivalent curve polygon from a polygon.
Definition: lwcurvepoly.c:53
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition: lwtin.c:34
LWGEOM * lwgeom_unstroke(const LWGEOM *geom)
Definition: lwstroke.c:1168
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition: lwgeom.c:1917
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
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:213
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition: lwgeom.c:653
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
Definition: lwmline.c:38
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
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:714
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:640
void lwtin_free(LWTIN *tin)
Definition: lwtin.c:39
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
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:113
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition: ptarray.c:555
int ptarray_transform(POINTARRAY *pa, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition: lwpoint.c:52
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:193
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1750
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:290
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition: lwgeom.c:762
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition: lwutil.c:171
double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt)
Find the measure value at the location on the line closest to the point.
POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:201
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:3028
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
void lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition: lwgeom.c:1603
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
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
Definition: measures3d.c:94
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:100
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:60
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
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:408
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:295
unsigned int geohash_point_as_int(POINT2D *pt)
Definition: lwalgorithm.c:657
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:320
void lwline_release(LWLINE *lwline)
Definition: lwline.c:134
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:647
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition: lwstroke.c:768
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:678
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
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:2472
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
Definition: g_box.c:290
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:36
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:879
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:838
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition: lwutil.c:261
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
LWGEOM * lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:60
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
Definition: lwalgorithm.c:461
int lwgeom_is_simple(const LWGEOM *lwgeom)
void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1750
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
int lwpointiterator_peek(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assigns the next point in the iterator to p.
Definition: lwiterator.c:195
void lwtin_release(LWTIN *lwtin)
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:628
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:43
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:506
int gserialized_get_zm(const GSERIALIZED *gser)
Return a number indicating presence of Z and M coordinates.
Definition: g_serialized.c:55
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:923
LWGEOM * lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision)
Create an LWGEOM object from an Encoded Polyline representation.
int lwgeom_check_geodetic(const LWGEOM *geom)
Check that coordinates of LWGEOM are all within the geodetic range (-180, -90, 180,...
Definition: lwgeodetic.c:3131
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:520
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
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition: lwin_wkb.c:91
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:46
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:269
char * gserialized_to_string(const GSERIALIZED *g)
Return a WKT representation of the gserialized geometry.
Definition: g_serialized.c:193
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
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:247
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1305
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:251
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:388
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:348
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1436
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
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
double lwgeom_length(const LWGEOM *geom)
Definition: lwgeom.c:1939
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition: lwgeom.c:1503
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
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
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
Definition: lwgeom_api.c:37
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:117
GSERIALIZED * gserialized_copy(const GSERIALIZED *g)
Return a copy of the input serialized geometry.
Definition: g_serialized.c:142
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1197
LWGEOM * lwgeom_reverse(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1689
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition: lwgeom.c:280
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2413
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:285
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1093
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
void printBOX3D(BOX3D *b)
Definition: lwgeom_api.c:500
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:673
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:248
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
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:2038
LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell)
Definition: lwtriangle.c:153
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:158
double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist)
Find the time of closest point of approach.
void lwmline_release(LWMLINE *lwline)
Definition: lwmline.c:32
LWGEOM * lwgeom_pointonsurface(const LWGEOM *geom)
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:246
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
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
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:281
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
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
void(* lwreporter)(const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:221
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1872
LWCURVEPOLY * lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms)
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition: lwgeom.c:242
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:47
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.
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
Definition: ptarray.c:96
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition: lwpsurface.c:33
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
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2332
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1235
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
Definition: lwalgorithm.c:856
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
Definition: g_serialized.c:65
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:542
void printLWTIN(LWTIN *tin)
Definition: lwtin.c:57
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:213
LW_LINEARIZE_FLAGS
Definition: liblwgeom.h:2226
@ LW_LINEARIZE_FLAG_SYMMETRIC
Symmetric linearization means that the output vertices would be the same no matter the order of the p...
Definition: liblwgeom.h:2232
@ LW_LINEARIZE_FLAG_RETAIN_ANGLE
Retain angle instructs the engine to try its best to retain the requested angle between generating ra...
Definition: liblwgeom.h:2252
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
Definition: measures3d.c:815
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:215
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
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition: lwline.c:542
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:1287
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices)
Definition: lwgeom.c:2448
LWGEOM * lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint)
Definition: lwchaikins.c:182
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints)
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
Definition: lwpoint.c:47
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
Definition: lwhomogenize.c:211
void lwfree(void *mem)
Definition: lwutil.c:244
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:213
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
size_t ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:411
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
Definition: lwgeodetic.c:2889
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1085
void lwcircstring_free(LWCIRCSTRING *curve)
Definition: lwcircstring.c:97
LWPOINT * lwpoint_make3dm(int srid, double x, double y, double m)
Definition: lwpoint.c:184
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
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1510
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1984
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,...
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: g_serialized.c:60
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:42
uint8_t lwtype_multitype(uint8_t type)
Definition: lwgeom.c:361
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
#define __attribute__(x)
Definition: liblwgeom.h:201
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
void lwtriangle_free(LWTRIANGLE *triangle)
Definition: lwtriangle.c:69
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:72
void *(* lwreallocator)(void *mem, size_t size)
Definition: liblwgeom.h:219
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:197
LWPOINTITERATOR * lwpointiterator_create_rw(LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM* Supports modification of coordinates during iterat...
Definition: lwiterator.c:253
CG_LINE_CROSS_TYPE
The return values of lwline_crossing_direction()
Definition: liblwgeom.h:1517
@ LINE_MULTICROSS_END_RIGHT
Definition: liblwgeom.h:1522
@ LINE_MULTICROSS_END_SAME_FIRST_LEFT
Definition: liblwgeom.h:1523
@ LINE_MULTICROSS_END_LEFT
Definition: liblwgeom.h:1521
@ LINE_CROSS_LEFT
Definition: liblwgeom.h:1519
@ LINE_MULTICROSS_END_SAME_FIRST_RIGHT
Definition: liblwgeom.h:1524
@ LINE_CROSS_RIGHT
Definition: liblwgeom.h:1520
@ LINE_NO_CROSS
Definition: liblwgeom.h:1518
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition: liblwgeom.h:218
void lwcollection_release(LWCOLLECTION *lwcollection)
Definition: lwcollection.c:36
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
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:50
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:50
double lwgeom_length_2d(const LWGEOM *geom)
Definition: lwgeom.c:1961
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition: lwgeom.c:1345
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3222
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
Definition: measures.c:202
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:721
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
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition: lwprint.c:426
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:187
GBOX * gserialized_calculate_gbox_geocentric(const GSERIALIZED *g)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates.
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:284
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
Definition: lwgeom.c:37
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:40
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
void printLWLINE(LWLINE *line)
Definition: lwline.c:88
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
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_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
int lwcollection_ngeoms(const LWCOLLECTION *col)
Definition: lwcollection.c:318
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2381
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.
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:3404
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom)
Definition: lwgeom.c:796
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
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:734
void lwcircstring_release(LWCIRCSTRING *lwcirc)
Definition: lwcircstring.c:91
LWGEOM * lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition: lwgeom.c:275
LWPOLY * lwpoly_segmentize2d(const LWPOLY *line, double dist)
Definition: lwpoly.c:312
POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:334
LWGEOM * lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj)
Definition: lwgeom.c:310
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition: lwgeom.c:268
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:306
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:482
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:746
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition: lwgeom.c:305
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:198
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition: lwgeom.c:260
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:373
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
LWCOLLECTION * lwcollection_concat_in_place(LWCOLLECTION *col1, const LWCOLLECTION *col2)
Appends all geometries from col2 to col1 in place.
Definition: lwcollection.c:240
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,...
Definition: ptarray.c:156
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition: lwmpoint.c:93
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:386
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
Definition: lwgeom_box3d.c:336
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:705
int lwpointiterator_has_next(LWPOINTITERATOR *s)
Returns LW_TRUE if there is another point available in the iterator.
Definition: lwiterator.c:204
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3297
LWPOINT * lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged)
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
LWGEOM * lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:48
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:39
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
void printLWPOINT(LWPOINT *point)
Definition: lwpoint.c:224
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:237
void * lwalloc(size_t size)
Definition: lwutil.c:229
int lwgeom_dimensionality(const LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1458
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:547
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:173
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition: lwcompound.c:88
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:695
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfullywithin calculations.
Definition: measures.c:181
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
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
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:325
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:169
void lwpsurface_free(LWPSURFACE *psurf)
Definition: lwpsurface.c:39
float next_float_up(double d)
Definition: lwgeom_api.c:73
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:175
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:89
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
void lwpsurface_release(LWPSURFACE *lwpsurface)
int lwline_is_trajectory(const LWLINE *geom)
Definition: lwline.c:463
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition: lwtriangle.c:82
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point)
Definition: lwgeom_api.c:267
double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d max distance calculation.
Definition: measures3d.c:314
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
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
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
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:459
double lwgeom_perimeter(const LWGEOM *geom)
Definition: lwgeom.c:1895
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
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:360
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:789
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
Definition: g_box.c:204
LWCOMPOUND * lwcompound_construct_from_lwline(const LWLINE *lwpoly)
Construct an equivalent compound curve from a linestring.
Definition: lwcompound.c:204
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:2156
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
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...
LWCOMPOUND * lwcompound_construct_empty(int srid, char hasz, char hasm)
Definition: lwcompound.c:123
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:259
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition: lwgeom.c:790
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:65
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:435
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:356
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition: ptarray.c:597
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition: lwpoint.c:40
LWPOINT * lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:2092
LWPOINT * lwpoint_make4d(int srid, double x, double y, double z, double m)
Definition: lwpoint.c:195
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:686
float next_float_down(double d)
Definition: lwgeom_api.c:52
void lwline_free(LWLINE *line)
Definition: lwline.c:76
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:294
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:368
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:885
LWMPOINT * lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints)
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
Definition: lwpoly.c:98
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:58
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
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 lwgeom_has_arc(const LWGEOM *geom)
Definition: lwstroke.c:55
void lwmpoint_release(LWMPOINT *lwpoint)
Definition: lwmpoint.c:33
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:399
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:160
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:254
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition: lwtriangle.c:119
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:2031
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:240
void printLWPSURFACE(LWPSURFACE *psurf)
Definition: lwpsurface.c:57
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:88
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:784
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:336
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:2875
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition: lwgeom.c:756
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:374
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:738
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition: lwgeom.c:102
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:618
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition: measures3d.c:352
int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
Is the closest point of approach within a distance ?
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
enum LWORD_T LWORD
Ordinate names.
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:188
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:318
Datum distance(PG_FUNCTION_ARGS)
Datum area(PG_FUNCTION_ARGS)
int value
Definition: genraster.py:61
opts
Definition: ovdump.py:44
type
Definition: ovdump.py:41
data
Definition: ovdump.py:103
def fmt
Definition: pixval.py:92
double afac
Definition: liblwgeom.h:273
double xmax
Definition: liblwgeom.h:281
double xmin
Definition: liblwgeom.h:280
int32_t srid
Definition: liblwgeom.h:282
double ymax
Definition: liblwgeom.h:298
double zmax
Definition: liblwgeom.h:300
double xmax
Definition: liblwgeom.h:296
double zmin
Definition: liblwgeom.h:299
double mmax
Definition: liblwgeom.h:302
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
double mmin
Definition: liblwgeom.h:301
uint8_t flags
Definition: liblwgeom.h:294
uint8_t flags
Definition: liblwgeom.h:386
uint32_t size
Definition: liblwgeom.h:384
POINT2D * center
Definition: liblwgeom.h:1650
uint8_t type
Definition: liblwgeom.h:443
uint8_t flags
Definition: liblwgeom.h:444
int32_t srid
Definition: liblwgeom.h:446
POINTARRAY * points
Definition: liblwgeom.h:447
GBOX * bbox
Definition: liblwgeom.h:445
uint32_t ngeoms
Definition: liblwgeom.h:510
uint32_t maxgeoms
Definition: liblwgeom.h:511
uint8_t type
Definition: liblwgeom.h:506
GBOX * bbox
Definition: liblwgeom.h:508
uint8_t flags
Definition: liblwgeom.h:507
LWGEOM ** geoms
Definition: liblwgeom.h:512
int32_t srid
Definition: liblwgeom.h:509
uint32_t maxgeoms
Definition: liblwgeom.h:524
uint8_t flags
Definition: liblwgeom.h:520
int32_t srid
Definition: liblwgeom.h:522
GBOX * bbox
Definition: liblwgeom.h:521
uint32_t ngeoms
Definition: liblwgeom.h:523
uint8_t type
Definition: liblwgeom.h:519
LWGEOM ** geoms
Definition: liblwgeom.h:525
int32_t srid
Definition: liblwgeom.h:535
GBOX * bbox
Definition: liblwgeom.h:534
uint8_t type
Definition: liblwgeom.h:532
LWGEOM ** rings
Definition: liblwgeom.h:538
uint8_t flags
Definition: liblwgeom.h:533
uint32_t nrings
Definition: liblwgeom.h:536
uint32_t maxrings
Definition: liblwgeom.h:537
void * data
Definition: liblwgeom.h:403
uint8_t type
Definition: liblwgeom.h:399
GBOX * bbox
Definition: liblwgeom.h:401
uint8_t flags
Definition: liblwgeom.h:400
int32_t srid
Definition: liblwgeom.h:402
GBOX * bbox
Definition: liblwgeom.h:423
uint8_t flags
Definition: liblwgeom.h:422
POINTARRAY * points
Definition: liblwgeom.h:425
uint8_t type
Definition: liblwgeom.h:421
int32_t srid
Definition: liblwgeom.h:424
uint32_t maxgeoms
Definition: liblwgeom.h:550
LWGEOM ** geoms
Definition: liblwgeom.h:551
GBOX * bbox
Definition: liblwgeom.h:547
uint8_t flags
Definition: liblwgeom.h:546
uint32_t ngeoms
Definition: liblwgeom.h:549
int32_t srid
Definition: liblwgeom.h:548
uint8_t type
Definition: liblwgeom.h:545
uint32_t maxgeoms
Definition: liblwgeom.h:485
GBOX * bbox
Definition: liblwgeom.h:482
int32_t srid
Definition: liblwgeom.h:483
LWLINE ** geoms
Definition: liblwgeom.h:486
uint8_t type
Definition: liblwgeom.h:480
uint32_t ngeoms
Definition: liblwgeom.h:484
uint8_t flags
Definition: liblwgeom.h:481
uint32_t maxgeoms
Definition: liblwgeom.h:472
int32_t srid
Definition: liblwgeom.h:470
GBOX * bbox
Definition: liblwgeom.h:469
uint8_t flags
Definition: liblwgeom.h:468
uint32_t ngeoms
Definition: liblwgeom.h:471
LWPOINT ** geoms
Definition: liblwgeom.h:473
uint8_t type
Definition: liblwgeom.h:467
uint8_t flags
Definition: liblwgeom.h:494
uint8_t type
Definition: liblwgeom.h:493
GBOX * bbox
Definition: liblwgeom.h:495
uint32_t maxgeoms
Definition: liblwgeom.h:498
uint32_t ngeoms
Definition: liblwgeom.h:497
LWPOLY ** geoms
Definition: liblwgeom.h:499
int32_t srid
Definition: liblwgeom.h:496
uint8_t flags
Definition: liblwgeom.h:559
uint8_t type
Definition: liblwgeom.h:558
int32_t srid
Definition: liblwgeom.h:561
uint32_t maxgeoms
Definition: liblwgeom.h:563
GBOX * bbox
Definition: liblwgeom.h:560
uint32_t ngeoms
Definition: liblwgeom.h:562
LWGEOM ** geoms
Definition: liblwgeom.h:564
POINTARRAY * point
Definition: liblwgeom.h:414
uint8_t type
Definition: liblwgeom.h:410
GBOX * bbox
Definition: liblwgeom.h:412
uint8_t flags
Definition: liblwgeom.h:411
int32_t srid
Definition: liblwgeom.h:413
POINTARRAY ** rings
Definition: liblwgeom.h:460
uint8_t type
Definition: liblwgeom.h:454
uint32_t maxrings
Definition: liblwgeom.h:459
uint32_t nrings
Definition: liblwgeom.h:458
uint8_t flags
Definition: liblwgeom.h:455
GBOX * bbox
Definition: liblwgeom.h:456
int32_t srid
Definition: liblwgeom.h:457
uint32_t maxgeoms
Definition: liblwgeom.h:576
LWPOLY ** geoms
Definition: liblwgeom.h:577
uint32_t ngeoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:571
int32_t srid
Definition: liblwgeom.h:574
GBOX * bbox
Definition: liblwgeom.h:573
uint8_t flags
Definition: liblwgeom.h:572
uint32_t ngeoms
Definition: liblwgeom.h:588
int32_t srid
Definition: liblwgeom.h:587
uint8_t flags
Definition: liblwgeom.h:585
uint8_t type
Definition: liblwgeom.h:584
LWTRIANGLE ** geoms
Definition: liblwgeom.h:590
uint32_t maxgeoms
Definition: liblwgeom.h:589
GBOX * bbox
Definition: liblwgeom.h:586
int32_t srid
Definition: liblwgeom.h:435
uint8_t type
Definition: liblwgeom.h:432
GBOX * bbox
Definition: liblwgeom.h:434
POINTARRAY * points
Definition: liblwgeom.h:436
uint8_t flags
Definition: liblwgeom.h:433
double x
Definition: liblwgeom.h:331
double m
Definition: liblwgeom.h:349
double x
Definition: liblwgeom.h:337
double x
Definition: liblwgeom.h:343
double m
Definition: liblwgeom.h:355
uint32_t maxpoints
Definition: liblwgeom.h:375
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t * serialized_pointlist
Definition: liblwgeom.h:369
uint8_t flags
Definition: liblwgeom.h:372
double e_sq
Definition: liblwgeom.h:320
double e
Definition: liblwgeom.h:319
double radius
Definition: liblwgeom.h:321
double a
Definition: liblwgeom.h:316
double b
Definition: liblwgeom.h:317
double f
Definition: liblwgeom.h:318
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
Definition: liblwgeom.h:2013
unsigned int uint32_t
Definition: uthash.h:78
unsigned char uint8_t
Definition: uthash.h:79