PostGIS  2.4.9dev-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.4.9dev"
66 #define LIBLWGEOM_VERSION_MAJOR "2"
67 #define LIBLWGEOM_VERSION_MINOR "4"
68 #define LIBLWGEOM_GEOS_VERSION "37"
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,
118 } LWORD;
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 /*
192 ** EPSG WGS84 geographics, OGC standard default SRS, better be in
193 ** the SPATIAL_REF_SYS table!
194 */
195 #define SRID_DEFAULT 4326
196 
197 #ifndef __GNUC__
198 # define __attribute__(x)
199 #endif
200 
207 extern int clamp_srid(int srid);
208 
209 /* Raise an lwerror if srids do not match */
210 void error_if_srid_mismatch(int srid1, int srid2);
211 
215 typedef void* (*lwallocator)(size_t size);
216 typedef void* (*lwreallocator)(void *mem, size_t size);
217 typedef void (*lwfreeor)(void* mem);
218 typedef void (*lwreporter)(const char* fmt, va_list ap)
219  __attribute__ (( format(printf, 1, 0) ));
220 typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
221  __attribute__ (( format(printf, 2,0) ));
222 
229 extern void lwgeom_set_handlers(lwallocator allocator,
230  lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
231  lwreporter noticereporter);
232 
233 extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
234 
247 extern void lwgeom_request_interrupt(void);
248 
252 extern void lwgeom_cancel_interrupt(void);
253 
264 typedef void (lwinterrupt_callback)();
266 
267 /******************************************************************/
268 
269 typedef struct {
270  double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
271 } AFFINE;
272 
273 /******************************************************************/
274 
275 typedef struct
276 {
277  double xmin, ymin, zmin;
278  double xmax, ymax, zmax;
279  int32_t srid;
280 }
281 BOX3D;
282 
283 /******************************************************************
284 * GBOX structure.
285 * We include the flags (information about dimensinality),
286 * so we don't have to constantly pass them
287 * into functions that use the GBOX.
288 */
289 typedef struct
290 {
292  double xmin;
293  double xmax;
294  double ymin;
295  double ymax;
296  double zmin;
297  double zmax;
298  double mmin;
299  double mmax;
300 } GBOX;
301 
302 
303 /******************************************************************
304 * SPHEROID
305 *
306 * Standard definition of an ellipsoid (what wkt calls a spheroid)
307 * f = (a-b)/a
308 * e_sq = (a*a - b*b)/(a*a)
309 * b = a - fa
310 */
311 typedef struct
312 {
313  double a; /* semimajor axis */
314  double b; /* semiminor axis b = (a - fa) */
315  double f; /* flattening f = (a-b)/a */
316  double e; /* eccentricity (first) */
317  double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
318  double radius; /* spherical average radius = (2*a+b)/3 */
319  char name[20]; /* name of ellipse */
320 }
321 SPHEROID;
322 
323 /******************************************************************
324 * POINT2D, POINT3D, POINT3DM, POINT4D
325 */
326 typedef struct
327 {
328  double x, y;
329 }
330 POINT2D;
331 
332 typedef struct
333 {
334  double x, y, z;
335 }
336 POINT3DZ;
337 
338 typedef struct
339 {
340  double x, y, z;
341 }
342 POINT3D;
343 
344 typedef struct
345 {
346  double x, y, m;
347 }
348 POINT3DM;
349 
350 typedef struct
351 {
352  double x, y, z, m;
353 }
354 POINT4D;
355 
356 /******************************************************************
357 * POINTARRAY
358 * Point array abstracts a lot of the complexity of points and point lists.
359 * It handles 2d/3d translation
360 * (2d points converted to 3d will have z=0 or NaN)
361 * DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
362 */
363 typedef struct
364 {
365  /* Array of POINT 2D, 3D or 4D, possibly missaligned. */
367 
368  /* Use FLAGS_* macros to handle */
370 
371  int npoints; /* how many points we are currently storing */
372  int maxpoints; /* how many points we have space for in serialized_pointlist */
373 }
374 POINTARRAY;
375 
376 /******************************************************************
377 * GSERIALIZED
378 */
379 typedef struct
380 {
381  uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
382  uint8_t srid[3]; /* 24 bits of SRID */
383  uint8_t flags; /* HasZ, HasM, HasBBox, IsGeodetic, IsReadOnly */
384  uint8_t data[1]; /* See gserialized.txt */
385 } GSERIALIZED;
386 
387 
388 /******************************************************************
389 * LWGEOM (any geometry type)
390 *
391 * Abstract type, note that 'type', 'bbox' and 'srid' are available in
392 * all geometry variants.
393 */
394 typedef struct
395 {
399  int32_t srid;
400  void *data;
401 }
402 LWGEOM;
403 
404 /* POINTYPE */
405 typedef struct
406 {
407  uint8_t type; /* POINTTYPE */
410  int32_t srid;
411  POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
412 }
413 LWPOINT; /* "light-weight point" */
414 
415 /* LINETYPE */
416 typedef struct
417 {
418  uint8_t type; /* LINETYPE */
421  int32_t srid;
422  POINTARRAY *points; /* array of POINT3D */
423 }
424 LWLINE; /* "light-weight line" */
425 
426 /* TRIANGLE */
427 typedef struct
428 {
432  int32_t srid;
434 }
435 LWTRIANGLE;
436 
437 /* CIRCSTRINGTYPE */
438 typedef struct
439 {
440  uint8_t type; /* CIRCSTRINGTYPE */
443  int32_t srid;
444  POINTARRAY *points; /* array of POINT(3D/3DM) */
445 }
446 LWCIRCSTRING; /* "light-weight circularstring" */
447 
448 /* POLYGONTYPE */
449 typedef struct
450 {
451  uint8_t type; /* POLYGONTYPE */
454  int32_t srid;
455  int nrings; /* how many rings we are currently storing */
456  int maxrings; /* how many rings we have space for in **rings */
457  POINTARRAY **rings; /* list of rings (list of points) */
458 }
459 LWPOLY; /* "light-weight polygon" */
460 
461 /* MULTIPOINTTYPE */
462 typedef struct
463 {
467  int32_t srid;
468  int ngeoms; /* how many geometries we are currently storing */
469  int maxgeoms; /* how many geometries we have space for in **geoms */
471 }
472 LWMPOINT;
473 
474 /* MULTILINETYPE */
475 typedef struct
476 {
480  int32_t srid;
481  int ngeoms; /* how many geometries we are currently storing */
482  int maxgeoms; /* how many geometries we have space for in **geoms */
484 }
485 LWMLINE;
486 
487 /* MULTIPOLYGONTYPE */
488 typedef struct
489 {
493  int32_t srid;
494  int ngeoms; /* how many geometries we are currently storing */
495  int maxgeoms; /* how many geometries we have space for in **geoms */
497 }
498 LWMPOLY;
499 
500 /* COLLECTIONTYPE */
501 typedef struct
502 {
506  int32_t srid;
507  int ngeoms; /* how many geometries we are currently storing */
508  int maxgeoms; /* how many geometries we have space for in **geoms */
510 }
512 
513 /* COMPOUNDTYPE */
514 typedef struct
515 {
516  uint8_t type; /* COMPOUNDTYPE */
519  int32_t srid;
520  int ngeoms; /* how many geometries we are currently storing */
521  int maxgeoms; /* how many geometries we have space for in **geoms */
523 }
524 LWCOMPOUND; /* "light-weight compound line" */
525 
526 /* CURVEPOLYTYPE */
527 typedef struct
528 {
529  uint8_t type; /* CURVEPOLYTYPE */
532  int32_t srid;
533  int nrings; /* how many rings we are currently storing */
534  int maxrings; /* how many rings we have space for in **rings */
535  LWGEOM **rings; /* list of rings (list of points) */
536 }
537 LWCURVEPOLY; /* "light-weight polygon" */
538 
539 /* MULTICURVE */
540 typedef struct
541 {
545  int32_t srid;
546  int ngeoms; /* how many geometries we are currently storing */
547  int maxgeoms; /* how many geometries we have space for in **geoms */
549 }
550 LWMCURVE;
551 
552 /* MULTISURFACETYPE */
553 typedef struct
554 {
558  int32_t srid;
559  int ngeoms; /* how many geometries we are currently storing */
560  int maxgeoms; /* how many geometries we have space for in **geoms */
562 }
563 LWMSURFACE;
564 
565 /* POLYHEDRALSURFACETYPE */
566 typedef struct
567 {
571  int32_t srid;
572  int ngeoms; /* how many geometries we are currently storing */
573  int maxgeoms; /* how many geometries we have space for in **geoms */
575 }
576 LWPSURFACE;
577 
578 /* TINTYPE */
579 typedef struct
580 {
584  int32_t srid;
585  int ngeoms; /* how many geometries we are currently storing */
586  int maxgeoms; /* how many geometries we have space for in **geoms */
588 }
589 LWTIN;
590 
591 /* Casts LWGEOM->LW* (return NULL if cast is illegal) */
592 extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
593 extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
594 extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
595 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
596 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
597 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
598 extern LWPOINT *lwgeom_as_lwpoint(const LWGEOM *lwgeom);
599 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
600 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
601 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
602 extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
603 extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
604 extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
605 extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
606 extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
607 
608 /* Casts LW*->LWGEOM (always cast) */
609 extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
610 extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
611 extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
612 extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
613 extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
614 extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
615 extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
616 extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
617 extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
618 extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
619 extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
620 extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
621 extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
622 
623 
624 extern LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom);
625 extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
626 extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
627 extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
628 extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
629 extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
630 
631 
632 
633 /***********************************************************************
634 ** Utility functions for flag byte and srid_flag integer.
635 */
636 
640 extern uint8_t gflags(int hasz, int hasm, int geodetic);
641 
646 extern uint32_t gserialized_get_type(const GSERIALIZED *g);
647 
653 
658 extern uint32_t gserialized_header_size(const GSERIALIZED *gser);
659 
664 extern int32_t gserialized_get_srid(const GSERIALIZED *g);
665 
670 extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
671 
678 extern int gserialized_is_empty(const GSERIALIZED *g);
679 
683 extern int gserialized_has_bbox(const GSERIALIZED *gser);
684 
688 extern int gserialized_has_z(const GSERIALIZED *gser);
689 
693 extern int gserialized_has_m(const GSERIALIZED *gser);
694 
698 extern int gserialized_is_geodetic(const GSERIALIZED *gser);
699 
704 extern int gserialized_get_zm(const GSERIALIZED *gser);
705 
709 extern int gserialized_ndims(const GSERIALIZED *gser);
710 
720 extern int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2);
721 
728 extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
729 extern void lwgeom_drop_srid(LWGEOM *lwgeom);
730 
737 extern void lwgeom_add_bbox(LWGEOM *lwgeom);
741 extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
742 
750 extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
751 
755 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
756 
757 /******************************************************************/
758 /* Functions that work on type numbers */
759 
763 extern int lwtype_is_collection(uint8_t type);
764 
769 
774 extern const char *lwtype_name(uint8_t type);
775 
776 
777 /******************************************************************/
778 
779 /*
780  * copies a point from the point array into the parameter point
781  * will set point's z=0 (or NaN) if pa is 2d
782  * will set point's m=0 (or NaN) if pa is 3d or 2d
783  * NOTE: point is a real POINT3D *not* a pointer
784  */
785 extern POINT4D getPoint4d(const POINTARRAY *pa, int n);
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: this will modify the point4d pointed to by 'point'.
792  */
793 extern int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point);
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  * NOTE: point is a real POINT3D *not* a pointer
799  */
800 extern POINT3DZ getPoint3dz(const POINTARRAY *pa, int n);
801 extern POINT3DM getPoint3dm(const POINTARRAY *pa, int n);
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: this will modify the point3d pointed to by 'point'.
807  */
808 extern int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point);
809 extern int getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *point);
810 
811 
812 /*
813  * copies a point from the point array into the parameter point
814  * z value (if present is not returned)
815  * NOTE: point is a real POINT3D *not* a pointer
816  */
817 extern POINT2D getPoint2d(const POINTARRAY *pa, int n);
818 
819 /*
820  * copies a point from the point array into the parameter point
821  * z value (if present is not returned)
822  * NOTE: this will modify the point2d pointed to by 'point'.
823  */
824 extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point);
825 
832 extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, int n);
833 
840 extern const POINT3DZ* getPoint3dz_cp(const POINTARRAY *pa, int n);
841 
848 extern const POINT4D* getPoint4d_cp(const POINTARRAY *pa, int n);
849 
850 /*
851  * set point N to the given value
852  * NOTE that the pointarray can be of any
853  * dimension, the appropriate ordinate values
854  * will be extracted from it
855  *
856  * N must be a valid point index
857  */
858 extern void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d);
859 
860 /*
861  * get a pointer to nth point of a POINTARRAY
862  * You'll need to cast it to appropriate dimensioned point.
863  * Note that if you cast to a higher dimensional point you'll
864  * possibly corrupt the POINTARRAY.
865  *
866  * WARNING: Don't cast this to a POINT !
867  * it would not be reliable due to memory alignment constraints
868  */
869 extern uint8_t *getPoint_internal(const POINTARRAY *pa, int n);
870 
871 /*
872  * size of point represeneted in the POINTARRAY
873  * 16 for 2d, 24 for 3d, 32 for 4d
874  */
875 extern int ptarray_point_size(const POINTARRAY *pa);
876 
877 
883 extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
884 
888 extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
889 
893 extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
894 
900 extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
901 
907 extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
908 
920 extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
921 
926 extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where);
927 
932 extern int ptarray_remove_point(POINTARRAY *pa, int where);
933 
945 extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
946 
953 
960 extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
961 
962 extern int ptarray_is_closed(const POINTARRAY *pa);
963 extern int ptarray_is_closed_2d(const POINTARRAY *pa);
964 extern int ptarray_is_closed_3d(const POINTARRAY *pa);
965 extern int ptarray_is_closed_z(const POINTARRAY *pa);
966 extern void ptarray_longitude_shift(POINTARRAY *pa);
967 extern int ptarray_isccw(const POINTARRAY *pa);
968 extern void ptarray_reverse(POINTARRAY *pa);
970 
976 extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
977  double tolerance);
978 
979 
983 extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
984 extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
985 extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
986 extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
987 
988 extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
989 extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
990 
991 /*
992  * Force to use SFS 1.1 geometry type
993  * (rather than SFS 1.2 and/or SQL/MM)
994  */
995 extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
996 
997 
998 /*--------------------------------------------------------
999  * all the base types (point/line/polygon) will have a
1000  * basic constructor, basic de-serializer, basic serializer,
1001  * bounding box finder and (TODO) serialized form size finder.
1002  *--------------------------------------------------------*/
1003 
1004 /*
1005  * convenience functions to hide the POINTARRAY
1006  */
1007 extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
1008 extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
1009 extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
1010 extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
1011 
1012 /******************************************************************
1013  * LWLINE functions
1014  ******************************************************************/
1015 
1019 extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where);
1020 
1021 /******************************************************************
1022  * LWPOLY functions
1023  ******************************************************************/
1024 
1029 extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1030 
1035 extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1036 
1041 extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1042 
1047 extern LWCOMPOUND* lwcompound_construct_from_lwline(const LWLINE *lwpoly);
1048 
1054 
1055 
1056 /******************************************************************
1057  * LWGEOM functions
1058  ******************************************************************/
1059 
1060 extern int lwcollection_ngeoms(const LWCOLLECTION *col);
1061 
1062 /* Given a generic geometry/collection, return the "simplest" form.
1063  * The elements of the homogenized collection are references to the
1064  * input geometry; a deep clone is not performed.
1065  * TODO: consider returning a geometry that does not reference the
1066  * input
1067  * */
1068 extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
1069 
1070 
1071 /******************************************************************
1072  * LWMULTIx and LWCOLLECTION functions
1073  ******************************************************************/
1074 
1076 
1077 /* WARNING: the output will contain references to geometries in the input, */
1078 /* so the result must be carefully released, not freed. */
1080 
1081 
1082 /******************************************************************
1083  * SERIALIZED FORM functions
1084  ******************************************************************/
1085 
1091 extern void lwgeom_set_srid(LWGEOM *geom, int srid);
1092 
1093 /*------------------------------------------------------
1094  * other stuff
1095  *
1096  * handle the double-to-float conversion. The results of this
1097  * will usually be a slightly bigger box because of the difference
1098  * between float8 and float4 representations.
1099  */
1100 
1101 extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1102 extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1103 
1104 void expand_box3d(BOX3D *box, double d);
1105 
1106 
1107 /****************************************************************
1108  * MEMORY MANAGEMENT
1109  ****************************************************************/
1110 
1111 /*
1112 * The *_free family of functions frees *all* memory associated
1113 * with the pointer. When the recursion gets to the level of the
1114 * POINTARRAY, the POINTARRAY is only freed if it is not flagged
1115 * as "read only". LWGEOMs constructed on top of GSERIALIZED
1116 * from PgSQL use read only point arrays.
1117 */
1118 
1119 extern void ptarray_free(POINTARRAY *pa);
1120 extern void lwpoint_free(LWPOINT *pt);
1121 extern void lwline_free(LWLINE *line);
1122 extern void lwpoly_free(LWPOLY *poly);
1123 extern void lwtriangle_free(LWTRIANGLE *triangle);
1124 extern void lwmpoint_free(LWMPOINT *mpt);
1125 extern void lwmline_free(LWMLINE *mline);
1126 extern void lwmpoly_free(LWMPOLY *mpoly);
1127 extern void lwpsurface_free(LWPSURFACE *psurf);
1128 extern void lwtin_free(LWTIN *tin);
1129 extern void lwcollection_free(LWCOLLECTION *col);
1130 extern void lwcircstring_free(LWCIRCSTRING *curve);
1131 extern void lwgeom_free(LWGEOM *geom);
1132 
1133 /*
1134 * The *_release family of functions frees the LWGEOM structures
1135 * surrounding the POINTARRAYs but leaves the POINTARRAYs
1136 * intact. Useful when re-shaping geometries between types,
1137 * or splicing geometries together.
1138 */
1139 
1140 extern void lwpoint_release(LWPOINT *lwpoint);
1141 extern void lwline_release(LWLINE *lwline);
1142 extern void lwpoly_release(LWPOLY *lwpoly);
1143 extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1144 extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1145 extern void lwmpoint_release(LWMPOINT *lwpoint);
1146 extern void lwmline_release(LWMLINE *lwline);
1147 extern void lwmpoly_release(LWMPOLY *lwpoly);
1148 extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1149 extern void lwtin_release(LWTIN *lwtin);
1150 extern void lwcollection_release(LWCOLLECTION *lwcollection);
1151 extern void lwgeom_release(LWGEOM *lwgeom);
1152 
1153 
1154 /****************************************************************
1155 * Utility
1156 ****************************************************************/
1157 
1158 extern void printBOX3D(BOX3D *b);
1159 extern void printPA(POINTARRAY *pa);
1160 extern void printLWPOINT(LWPOINT *point);
1161 extern void printLWLINE(LWLINE *line);
1162 extern void printLWPOLY(LWPOLY *poly);
1163 extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1164 extern void printLWPSURFACE(LWPSURFACE *psurf);
1165 extern void printLWTIN(LWTIN *tin);
1166 
1167 extern float next_float_down(double d);
1168 extern float next_float_up(double d);
1169 
1170 /* general utilities 2D */
1171 extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1172 extern double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2);
1173 extern double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1174 extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1175 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1176 extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1177 extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1178 extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1179 extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1180 extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1181 extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1182 extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1183 
1184 /* 3D */
1185 extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1186 extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1187 
1188 extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1189 extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1190 extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1191 
1192 
1193 extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1194 extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1195 extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1196 extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1197 
1198 extern double lwgeom_area(const LWGEOM *geom);
1199 extern double lwgeom_length(const LWGEOM *geom);
1200 extern double lwgeom_length_2d(const LWGEOM *geom);
1201 extern double lwgeom_perimeter(const LWGEOM *geom);
1202 extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1203 extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1204 extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1205 extern int lwgeom_dimension(const LWGEOM *geom);
1206 
1207 extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, int where);
1208 extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, int where);
1209 
1210 extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1211 extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1212 extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where);
1213 
1214 
1215 extern double ptarray_length_2d(const POINTARRAY *pts);
1216 extern double ptarray_length(const POINTARRAY *pts);
1217 extern double ptarray_arc_length_2d(const POINTARRAY *pts);
1218 
1219 
1220 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1221 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1222 extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1223 extern void lwgeom_reverse(LWGEOM *lwgeom);
1224 extern void lwline_reverse(LWLINE *line);
1225 extern void lwpoly_reverse(LWPOLY *poly);
1226 extern void lwtriangle_reverse(LWTRIANGLE *triangle);
1227 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1228 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1229 extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1230 
1235 extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1236 extern void lwpoly_force_clockwise(LWPOLY *poly);
1237 extern void lwtriangle_force_clockwise(LWTRIANGLE *triangle);
1238 
1239 extern int lwgeom_is_clockwise(LWGEOM *lwgeom);
1240 extern int lwpoly_is_clockwise(LWPOLY *poly);
1241 extern int lwtriangle_is_clockwise(LWTRIANGLE *triangle);
1242 
1243 extern void interpolate_point4d(POINT4D *A, POINT4D *B, POINT4D *I, double F);
1244 
1245 void lwgeom_longitude_shift(LWGEOM *lwgeom);
1246 
1259 LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1260 
1261 
1271 extern int lwgeom_needs_bbox(const LWGEOM *geom);
1272 
1276 extern int lwgeom_count_vertices(const LWGEOM *geom);
1277 
1282 extern int lwgeom_count_rings(const LWGEOM *geom);
1283 
1288 extern int lwgeom_has_srid(const LWGEOM *geom);
1289 
1294 extern int lwgeom_is_empty(const LWGEOM *geom);
1295 
1300 extern int lwgeom_is_closed(const LWGEOM *geom);
1301 
1305 extern int lwgeom_dimensionality(LWGEOM *geom);
1306 
1307 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
1308 char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1309 char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2);
1310 char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2);
1311 char lwline_same(const LWLINE *p1, const LWLINE *p2);
1312 char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2);
1313 char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2);
1314 char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2);
1315 char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2);
1316 
1317 
1325 extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1326 
1330 extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1331 
1332 /* TODO Move to Internal */
1333 LWPOINT *lwpoint_clone(const LWPOINT *lwgeom);
1334 POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1335 
1336 
1337 /*
1338 * Geometry constructors. These constructors to not copy the point arrays
1339 * passed to them, they just take references, so do not free them out
1340 * from underneath the geometries.
1341 */
1342 extern LWPOINT* lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point);
1343 extern LWMPOINT *lwmpoint_construct(int srid, const POINTARRAY *pa);
1344 extern LWLINE* lwline_construct(int srid, GBOX *bbox, POINTARRAY *points);
1345 extern LWCIRCSTRING* lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points);
1346 extern LWPOLY* lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1347 extern LWCURVEPOLY* lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1348 extern LWTRIANGLE* lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points);
1349 extern LWCOLLECTION* lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1350 /*
1351 * Empty geometry constructors.
1352 */
1353 extern LWGEOM* lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1354 extern LWPOINT* lwpoint_construct_empty(int srid, char hasz, char hasm);
1355 extern LWLINE* lwline_construct_empty(int srid, char hasz, char hasm);
1356 extern LWPOLY* lwpoly_construct_empty(int srid, char hasz, char hasm);
1357 extern LWCURVEPOLY* lwcurvepoly_construct_empty(int srid, char hasz, char hasm);
1358 extern LWCIRCSTRING* lwcircstring_construct_empty(int srid, char hasz, char hasm);
1359 extern LWCOMPOUND* lwcompound_construct_empty(int srid, char hasz, char hasm);
1360 extern LWTRIANGLE* lwtriangle_construct_empty(int srid, char hasz, char hasm);
1361 extern LWMPOINT* lwmpoint_construct_empty(int srid, char hasz, char hasm);
1362 extern LWMLINE* lwmline_construct_empty(int srid, char hasz, char hasm);
1363 extern LWMPOLY* lwmpoly_construct_empty(int srid, char hasz, char hasm);
1364 extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1365 
1366 
1367 /* Other constructors */
1368 extern LWPOINT *lwpoint_make2d(int srid, double x, double y);
1369 extern LWPOINT *lwpoint_make3dz(int srid, double x, double y, double z);
1370 extern LWPOINT *lwpoint_make3dm(int srid, double x, double y, double m);
1371 extern LWPOINT *lwpoint_make4d(int srid, double x, double y, double z, double m);
1372 extern LWPOINT *lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p);
1373 extern LWLINE *lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms);
1374 extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1375 extern LWLINE *lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint);
1376 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1377 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1378 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1379 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1380 extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1381 extern LWPOLY *lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2);
1382 extern LWPOLY *lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1383 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1384 extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1385 
1386 /* Some point accessors */
1387 extern double lwpoint_get_x(const LWPOINT *point);
1388 extern double lwpoint_get_y(const LWPOINT *point);
1389 extern double lwpoint_get_z(const LWPOINT *point);
1390 extern double lwpoint_get_m(const LWPOINT *point);
1391 
1395 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1396 
1400 extern uint32_t lwgeom_get_type(const LWGEOM *geom);
1401 
1405 extern int lwgeom_has_z(const LWGEOM *geom);
1406 
1410 extern int lwgeom_has_m(const LWGEOM *geom);
1411 
1415 extern int lwgeom_ndims(const LWGEOM *geom);
1416 
1417 /*
1418  * Given a point, returns the location of closest point on pointarray
1419  * as a fraction of total length (0: first point -- 1: last point).
1420  *
1421  * If not-null, the third argument will be set to the actual distance
1422  * of the point from the pointarray.
1423  */
1424 extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1425 
1430 extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1431 extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1432 
1437 extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1438 
1444 extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1445 
1449 extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1450 
1461 extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1462 
1468 extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1469 
1474 extern int lwgeom_is_trajectory(const LWGEOM *geom);
1475 extern int lwline_is_trajectory(const LWLINE *geom);
1476 
1477 /*
1478  * Ensure every segment is at most 'dist' long.
1479  * Returned LWGEOM might is unchanged if a POINT.
1480  */
1481 extern LWGEOM *lwgeom_segmentize2d(LWGEOM *line, double dist);
1482 extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1483 extern LWLINE *lwline_segmentize2d(LWLINE *line, double dist);
1484 extern LWPOLY *lwpoly_segmentize2d(LWPOLY *line, double dist);
1485 extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist);
1486 
1487 /*
1488  * Point density functions
1489  */
1490 extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, int npoints);
1491 extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, int npoints);
1492 extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, int npoints);
1493 
1494 /*
1495  * Geometric median
1496  */
1497 extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1498 extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1499 
1503 char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1504 unsigned int geohash_point_as_int(POINT2D *pt);
1505 
1506 
1518 };
1519 
1523 int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1524 
1528 LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1529 
1535 #define LW_GML_IS_DIMS (1<<0)
1536 
1537 #define LW_GML_IS_DEGREE (1<<1)
1538 
1539 #define LW_GML_SHORTLINE (1<<2)
1540 
1541 #define LW_GML_EXTENT (1<<4)
1542 
1543 
1544 #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1545 #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1546 
1553 #define LW_X3D_FLIP_XY (1<<0)
1554 #define LW_X3D_USE_GEOCOORDS (1<<1)
1555 #define X3D_USE_GEOCOORDS(x) ((x) & LW_X3D_USE_GEOCOORDS)
1556 
1557 
1558 
1559 extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1560 extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1564 extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1565 extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1566 extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1567 extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1568 extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1569 extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1570 extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1571 
1581 extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1582 
1588 extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1589 
1593 extern void spheroid_init(SPHEROID *s, double a, double b);
1594 
1600 extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1601 
1605 extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1606 
1611 extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1612 
1616 extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1617 
1622 extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1623 
1628 extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1629 
1634 extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1635 
1640 extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1641 
1642 typedef struct {
1644  double radius;
1646 
1648 
1649 /* Calculates the minimum circle that encloses all of the points in g, using a
1650  * two-dimensional implementation of the algorithm proposed in:
1651  *
1652  * Welzl, Emo (1991), "Smallest enclosing disks (balls and elipsoids)."
1653  * New Results and Trends in Computer Science (H. Maurer, Ed.), Lecture Notes
1654  * in Computer Science, 555 (1991) 359-370.
1655  *
1656  * Available online at the time of this writing at
1657  * https://www.inf.ethz.ch/personal/emo/PublFiles/SmallEnclDisk_LNCS555_91.pdf
1658  *
1659  * Returns NULL if the circle could not be calculated.
1660  */
1661 extern LWBOUNDINGCIRCLE* lwgeom_calculate_mbc(const LWGEOM* g);
1662 
1666 extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1667 
1668 extern char lwtriangle_is_repeated_points(LWTRIANGLE *triangle);
1669 
1682 extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1683 
1692 
1693 struct LWPOINTITERATOR;
1695 
1700 
1706 
1711 
1716 
1722 extern int lwpointiterator_modify_next(LWPOINTITERATOR* s, const POINT4D* p);
1723 
1731 
1737 
1738 
1742 extern uint8_t parse_hex(char *str);
1743 
1747 extern void deparse_hex(uint8_t str, char *result);
1748 
1749 
1750 
1751 /***********************************************************************
1752 ** Functions for managing serialized forms and bounding boxes.
1753 */
1754 
1761 
1768 
1773 extern char* gserialized_to_string(const GSERIALIZED *g);
1774 
1778 extern GSERIALIZED* gserialized_copy(const GSERIALIZED *g);
1779 
1783 extern int lwgeom_check_geodetic(const LWGEOM *geom);
1784 
1788 extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1789 
1793 extern int lwgeom_force_geodetic(LWGEOM *geom);
1794 
1798 extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1799 
1806 extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1807 
1813 extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1814 
1819 extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1820 
1825 extern int getPoint2d_p_ro(const POINTARRAY *pa, int n, POINT2D **point);
1826 
1830 extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1831 
1835 extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1836 
1840 int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1841 
1846 extern GBOX* gbox_new(uint8_t flags);
1847 
1852 extern void gbox_init(GBOX *gbox);
1853 
1857 extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1858 
1862 extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1863 
1867 extern void gbox_expand(GBOX *g, double d);
1868 
1872 extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
1873 
1877 extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1878 
1882 extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1883 
1887 extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1888 
1892 extern char* gbox_to_string(const GBOX *gbox);
1893 
1897 extern GBOX* gbox_copy(const GBOX *gbox);
1898 
1902 extern GBOX* gbox_from_string(const char *str);
1903 
1907 extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1908 
1912 extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1913 
1917 extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
1918 
1922 extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1923 
1928 extern size_t gbox_serialized_size(uint8_t flags);
1929 
1933 extern int gbox_same(const GBOX *g1, const GBOX *g2);
1934 
1938 extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
1939 
1944 extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
1945 
1952 extern void gbox_float_round(GBOX *gbox);
1953 
1957 extern int gbox_is_valid(const GBOX *gbox);
1958 
1963 extern uint64_t gbox_get_sortable_hash(const GBOX *g);
1964 
1969 extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
1970 
1976 extern size_t gserialized_from_lwgeom_size(const LWGEOM *geom);
1977 
1985 extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
1986 
1991 extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g);
1992 
1998 extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox);
1999 
2000 
2008 #define LW_PARSER_CHECK_MINPOINTS 1
2009 #define LW_PARSER_CHECK_ODD 2
2010 #define LW_PARSER_CHECK_CLOSURE 4
2011 #define LW_PARSER_CHECK_ZCLOSURE 8
2012 
2013 #define LW_PARSER_CHECK_NONE 0
2014 #define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
2015 
2021 {
2022  const char *wkinput; /* Copy of pointer to input WKT/WKB */
2023  uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
2024  int size; /* Size of serialized LWGEOM in bytes */
2025  LWGEOM *geom; /* Pointer to LWGEOM struct */
2026  const char *message; /* Error/warning message */
2027  int errcode; /* Error/warning number */
2028  int errlocation; /* Location of error */
2029  int parser_check_flags; /* Bitmask of validity checks run during this parse */
2030 }
2032 
2033 /*
2034  * Parser error messages (these must match the message array in lwgparse.c)
2035  */
2036 #define PARSER_ERROR_MOREPOINTS 1
2037 #define PARSER_ERROR_ODDPOINTS 2
2038 #define PARSER_ERROR_UNCLOSED 3
2039 #define PARSER_ERROR_MIXDIMS 4
2040 #define PARSER_ERROR_INVALIDGEOM 5
2041 #define PARSER_ERROR_INVALIDWKBTYPE 6
2042 #define PARSER_ERROR_INCONTINUOUS 7
2043 #define PARSER_ERROR_TRIANGLEPOINTS 8
2044 #define PARSER_ERROR_LESSPOINTS 9
2045 #define PARSER_ERROR_OTHER 10
2046 
2047 
2048 
2049 /*
2050  * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
2051  */
2053 {
2054  uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
2055  char *wkoutput; /* Pointer to WKT or WKB output */
2056  int size; /* Size of serialized LWGEOM in bytes */
2057  const char *message; /* Error/warning message */
2058  int errlocation; /* Location of error */
2059 }
2061 
2062 /*
2063  * Unparser error messages (these must match the message array in lwgunparse.c)
2064  */
2065 #define UNPARSER_ERROR_MOREPOINTS 1
2066 #define UNPARSER_ERROR_ODDPOINTS 2
2067 #define UNPARSER_ERROR_UNCLOSED 3
2068 
2069 
2070 /*
2071 ** Variants available for WKB and WKT output types
2072 */
2073 
2074 #define WKB_ISO 0x01
2075 #define WKB_SFSQL 0x02
2076 #define WKB_EXTENDED 0x04
2077 #define WKB_NDR 0x08
2078 #define WKB_XDR 0x10
2079 #define WKB_HEX 0x20
2080 #define WKB_NO_NPOINTS 0x40 /* Internal use only */
2081 #define WKB_NO_SRID 0x80 /* Internal use only */
2082 
2083 #define WKT_ISO 0x01
2084 #define WKT_SFSQL 0x02
2085 #define WKT_EXTENDED 0x04
2086 
2087 
2088 /*
2089 ** Variants available for TWKB
2090 */
2091 #define TWKB_BBOX 0x01 /* User wants bboxes */
2092 #define TWKB_SIZE 0x02 /* User wants sizes */
2093 #define TWKB_ID 0x04 /* User wants id */
2094 #define TWKB_NO_TYPE 0x10 /* No type because it is a sub geoemtry */
2095 #define TWKB_NO_ID 0x20 /* No ID because it is a subgeoemtry */
2096 #define TWKB_DEFAULT_PRECISION 0 /* Aim for 1m (or ft) rounding by default */
2097 
2098 /*
2099 ** New parsing and unparsing functions.
2100 */
2101 
2106 extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2107 
2113 extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2114 
2120 extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2121 
2125 extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2126 
2132 extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2133 
2138 extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2139 
2143 extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2144 
2145 extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2146 
2147 extern char* hexbytes_from_bytes(uint8_t *bytes, size_t size);
2148 
2149 /*
2150 * WKT detailed parsing support
2151 */
2152 extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2153 void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
2154 void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
2155 
2156 
2157 /* Memory management */
2158 extern void *lwalloc(size_t size);
2159 extern void *lwrealloc(void *mem, size_t size);
2160 extern void lwfree(void *mem);
2161 
2162 /* Utilities */
2163 extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2164 
2165 /*
2166 * TWKB functions
2167 */
2168 
2173 extern LWGEOM* lwgeom_from_twkb(uint8_t *twkb, size_t twkb_size, char check);
2174 
2180 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);
2181 
2182 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);
2183 
2184 /*******************************************************************************
2185  * SQLMM internal functions
2186  ******************************************************************************/
2187 
2188 int lwgeom_has_arc(const LWGEOM *geom);
2189 LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2191 
2196 typedef enum {
2219 
2220 typedef enum {
2227 
2248 
2257 extern LWGEOM* lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags);
2258 
2259 /*******************************************************************************
2260  * GEOS proxy functions on LWGEOM
2261  ******************************************************************************/
2262 
2264 const char* lwgeom_geos_version(void);
2265 
2268 
2270 LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2271 LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2272 LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2274 LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2275 LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2276 LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2277 LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2278 LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, int maxvertices);
2279 
2289 LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
2290 
2291 /*
2292  * Return the set of paths shared between two linear geometries,
2293  * and their direction (same or opposite).
2294  *
2295  * @param geom1 a lineal geometry
2296  * @param geom2 another lineal geometry
2297  *
2298  * Requires GEOS-3.3.0+
2299  */
2300 LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
2301 
2302 /*
2303  * An offset curve against the input line.
2304  *
2305  * @param lwline a lineal geometry
2306  * @param size offset distance. Offset left if negative and right if positive
2307  * @param quadsegs number of quadrature segments in curves (try 8)
2308  * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
2309  * @param mitreLimit (try 5.0)
2310  * @return derived geometry (linestring or multilinestring)
2311  *
2312  * Requires GEOS-3.2.0+
2313  */
2314 LWGEOM* lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit);
2315 
2316 /*
2317  * Return true if the input geometry is "simple" as per OGC defn.
2318  *
2319  * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called
2320  * in that case)
2321  */
2322 int lwgeom_is_simple(const LWGEOM *lwgeom);
2323 
2324 
2325 /*******************************************************************************
2326  * PROJ4-dependent extra functions on LWGEOM
2327  ******************************************************************************/
2328 
2334 projPJ lwproj_from_string(const char* txt);
2335 
2342 int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj) ;
2343 int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj) ;
2344 int point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj) ;
2345 
2346 
2347 /*******************************************************************************
2348  * GEOS-dependent extra functions on LWGEOM
2349  ******************************************************************************/
2350 
2359 
2360 
2368 
2369 /*
2370  * Split (multi)polygon by line; (multi)line by (multi)line,
2371  * (multi)point or (multi)polygon boundary.
2372  *
2373  * Collections are accepted as first argument.
2374  * Returns all obtained pieces as a collection.
2375  */
2376 LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
2377 
2378 /*
2379  * Fully node a set of linestrings, using the least nodes preserving
2380  * all the input ones.
2381  *
2382  * Requires GEOS-3.3.0 or higher
2383  */
2384 LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2385 
2395 LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly);
2396 
2408 LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2409 
2418 int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k);
2419 
2420 
2421 #endif /* !defined _LIBLWGEOM_H */
2422 
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:437
int ngeoms
Definition: liblwgeom.h:546
int32_t srid
Definition: liblwgeom.h:519
LWCOMPOUND * lwcompound_construct_empty(int srid, char hasz, char hasm)
Definition: lwcompound.c:123
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:3012
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
Definition: measures3d.c:363
int32_t srid
Definition: liblwgeom.h:279
int lwtriangle_is_clockwise(LWTRIANGLE *triangle)
Definition: lwtriangle.c:113
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:396
uint8_t type
Definition: liblwgeom.h:418
uint8_t flags
Definition: liblwgeom.h:569
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:380
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition: lwstroke.c:767
uint8_t flags
Definition: liblwgeom.h:543
LWGEOM * lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area)
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
Definition: lwout_gml.c:231
uint8_t type
Definition: liblwgeom.h:477
double z
Definition: liblwgeom.h:334
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
Definition: g_box.c:295
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:810
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition: g_box.c:376
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:996
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox)
Compute a box for geom and all sub-geometries, if not already computed.
Definition: lwgeom.c:660
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition: lwtin.c:34
GBOX * bbox
Definition: liblwgeom.h:398
POINT2D getPoint2d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:333
uint8_t flags
Definition: liblwgeom.h:441
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
POINTARRAY * points
Definition: liblwgeom.h:433
char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
Definition: lwpoint.c:264
GBOX * bbox
Definition: liblwgeom.h:466
void printLWPSURFACE(LWPSURFACE *psurf)
Definition: lwpsurface.c:57
int lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition: lwgeom.c:1075
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:2080
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
uint8_t * serialized_pointlist
Definition: liblwgeom.h:366
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1389
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:568
GBOX * bbox
Definition: liblwgeom.h:420
uint8_t variant
Definition: cu_in_twkb.c:26
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:54
void lwmpoly_release(LWMPOLY *lwpoly)
Definition: lwmpoly.c:34
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition: lwin_wkb.c:86
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1040
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point...
Definition: lwiterator.c:212
void lwtin_release(LWTIN *lwtin)
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:369
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid)
Calculate the bearing between two points on a spheroid.
Definition: lwgeodetic.c:2152
uint8_t type
Definition: liblwgeom.h:407
Tolerance expresses the maximum angle between the radii generating approximation line vertices...
Definition: liblwgeom.h:2217
int lwpointiterator_modify_next(LWPOINTITERATOR *s, const POINT4D *p)
Attempts to replace the next point int the iterator with p, and advances the iterator to the next poi...
Definition: lwiterator.c:226
char * r
Definition: cu_in_wkt.c:24
int gserialized_get_zm(const GSERIALIZED *gser)
Return a number indicating presence of Z and M coordinates.
Definition: g_serialized.c:55
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:669
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:60
int maxgeoms
Definition: liblwgeom.h:495
int lwcollection_ngeoms(const LWCOLLECTION *col)
Definition: lwcollection.c:302
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
LWLINE * lwline_segmentize2d(LWLINE *line, double dist)
Definition: lwline.c:147
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:40
void lwfree(void *mem)
Definition: lwutil.c:244
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:58
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
uint8_t flags
Definition: liblwgeom.h:556
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfyllywithin calculations.
Definition: measures.c:181
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:50
LWGEOM ** rings
Definition: liblwgeom.h:535
int npoints
Definition: liblwgeom.h:371
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:213
LWGEOM * lwgeom_force_4d(const LWGEOM *geom)
Definition: lwgeom.c:757
struct struct_lwgeom_unparser_result LWGEOM_UNPARSER_RESULT
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: g_box.c:191
uint8_t type
Definition: liblwgeom.h:503
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition: lwgeom_api.c:702
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition: lwgeom_api.c:648
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition: measures3d.c:352
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:113
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
Definition: lwalgorithm.c:460
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:878
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:710
GBOX * bbox
Definition: liblwgeom.h:544
GBOX * bbox
Definition: liblwgeom.h:583
void lwcircstring_free(LWCIRCSTRING *curve)
Definition: lwcircstring.c:98
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition: lwpsurface.c:33
int maxrings
Definition: liblwgeom.h:534
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:56
int32_t srid
Definition: liblwgeom.h:443
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2405
GSERIALIZED * gserialized_copy(const GSERIALIZED *g)
Return a copy of the input serialized geometry.
Definition: g_serialized.c:142
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:1881
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
Datum area(PG_FUNCTION_ARGS)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:518
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition: lwgeom.c:745
double b
Definition: liblwgeom.h:314
void lwtin_free(LWTIN *tin)
Definition: lwtin.c:39
uint8_t flags
Definition: liblwgeom.h:397
#define __attribute__(x)
Definition: liblwgeom.h:198
double xmax
Definition: liblwgeom.h:293
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition: lwpoint.c:40
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:243
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition: lwprint.c:424
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition: lwgeom.c:273
int lwgeom_check_geodetic(const LWGEOM *geom)
Check that coordinates of LWGEOM are all within the geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3115
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
void printLWTIN(LWTIN *tin)
Definition: lwtin.c:57
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
start location (distance from start / total distance) end location (distance from start / total dist...
Definition: ptarray.c:1061
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
def fmt
Definition: pixval.py:92
void lwpoint_release(LWPOINT *lwpoint)
Definition: lwpoint.c:256
LWGEOM * lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it&#39;s 3d)
Definition: ptarray.c:1692
int lwgeom_dimensionality(LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1411
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:167
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:264
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:351
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:415
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:280
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
int32_t srid
Definition: liblwgeom.h:545
GBOX * bbox
Definition: liblwgeom.h:505
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1786
LWMPOLY * lwmpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoly.c:40
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:248
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:723
double radius
Definition: liblwgeom.h:318
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1513
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:165
LWGEOM * lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision)
Create an LWGEOM object from an Encoded Polyline representation.
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:871
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:258
void lwtriangle_reverse(LWTRIANGLE *triangle)
Definition: lwtriangle.c:119
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
int lwline_is_trajectory(const LWLINE *geom)
Definition: lwline.c:477
data
Definition: ovdump.py:103
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:88
LWPOINT * lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth)
Calculate the location of a point on a spheroid, give a start point, bearing and distance.
Definition: lwgeodetic.c:2095
GBOX * bbox
Definition: liblwgeom.h:431
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition: lwmpoint.c:127
void printBOX3D(BOX3D *b)
Definition: lwgeom_api.c:466
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition: lwgeom.c:615
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:885
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:3388
uint8_t type
Definition: liblwgeom.h:529
LWPOINTITERATOR * lwpointiterator_create_rw(LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM* Supports modification of coordinates during iterat...
Definition: lwiterator.c:253
void lwtriangle_force_clockwise(LWTRIANGLE *triangle)
Definition: lwtriangle.c:106
LWGEOM * lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:60
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:259
LWPOLY ** geoms
Definition: liblwgeom.h:574
char * hexbytes_from_bytes(uint8_t *bytes, size_t size)
Definition: lwout_wkb.c:39
int getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *point)
Definition: lwgeom_api.c:266
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:251
LW_LINEARIZE_TOLERANCE_TYPE
Semantic of the tolerance argument passed to lwcurve_linearize.
Definition: liblwgeom.h:2196
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:240
uint8_t flags
Definition: liblwgeom.h:465
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:482
float next_float_down(double d)
Definition: lwgeom_api.c:51
GBOX * bbox
Definition: liblwgeom.h:453
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:174
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2317
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition: lwgeom.c:333
Tolerance expresses the maximum distance between an arbitrary point on the curve and the closest poin...
Definition: liblwgeom.h:2209
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:46
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
double zoff
Definition: liblwgeom.h:270
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
int32_t srid
Definition: liblwgeom.h:421
void lwpoly_force_clockwise(LWPOLY *poly)
Definition: lwpoly.c:270
LWGEOM ** geoms
Definition: liblwgeom.h:522
uint8_t flags
Definition: liblwgeom.h:517
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3281
GBOX * bbox
Definition: liblwgeom.h:518
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
Definition: measures3d.c:94
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:698
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:793
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2342
POINTARRAY * point
Definition: liblwgeom.h:411
double lwgeom_length_2d(const LWGEOM *geom)
Definition: lwgeom.c:1712
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
Definition: lwmline.c:38
int lwpoly_is_clockwise(LWPOLY *poly)
Definition: lwpoly.c:290
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:642
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:697
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:885
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:244
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:635
int32_t srid
Definition: liblwgeom.h:399
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:288
void interpolate_point4d(POINT4D *A, 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:680
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:380
int ngeoms
Definition: liblwgeom.h:481
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
GBOX * bbox
Definition: liblwgeom.h:557
POINT3DZ getPoint3dz(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:186
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: lwgeom.c:899
double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt)
Find the measure value at the location on the line closest to the point.
void lwgeom_longitude_shift(LWGEOM *lwgeom)
Definition: lwgeom.c:951
LWGEOM * lwgeom_flip_coordinates(LWGEOM *in)
Reverse the X and Y coordinate order.
Definition: lwgeom.c:1507
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition: g_box.c:91
uint8_t type
Definition: liblwgeom.h:429
double lwgeom_perimeter(const LWGEOM *geom)
Definition: lwgeom.c:1646
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition: lwtriangle.c:126
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:219
void * data
Definition: liblwgeom.h:400
int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
Is the closest point of approach within a distance ?
double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfullywithin calculations.
Definition: measures3d.c:326
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:369
char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2)
check for same geometry composition
Definition: lwcollection.c:262
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:100
int maxgeoms
Definition: liblwgeom.h:547
float next_float_up(double d)
Definition: lwgeom_api.c:72
uint8_t type
Definition: liblwgeom.h:555
LWPOINT * lwpoint_make3dm(int srid, double x, double y, double m)
Definition: lwpoint.c:184
double z
Definition: liblwgeom.h:340
void lwmpoint_release(LWMPOINT *lwpoint)
Definition: lwmpoint.c:33
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
unsigned int uint32_t
Definition: uthash.h:78
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:701
void(* lwfreeor)(void *mem)
Definition: liblwgeom.h:217
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:195
uint8_t flags
Definition: liblwgeom.h:504
int lwpointiterator_has_next(LWPOINTITERATOR *s)
Returns LW_TRUE if there is another point available in the iterator.
Definition: lwiterator.c:204
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1306
LWCURVEPOLY * lwcurvepoly_construct_from_lwpoly(LWPOLY *lwpoly)
Construct an equivalent curve polygon from a polygon.
Definition: lwcurvepoly.c:53
LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell)
Definition: lwtriangle.c:147
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:146
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
Definition: lwpoly.c:98
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:36
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Utility function to get type number from string.
Definition: g_util.c:163
int ngeoms
Definition: liblwgeom.h:585
LWCOLLECTION * lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset)
Determine the segments along a measured line that fall within the m-range given.
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
uint8_t flags
Definition: liblwgeom.h:478
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
Definition: ptarray.c:504
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
void expand_box3d(BOX3D *box, double d)
Expand given box of &#39;d&#39; units in all directions.
Definition: lwgeom_box3d.c:359
double zmax
Definition: liblwgeom.h:297
double ymin
Definition: liblwgeom.h:294
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:269
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
Definition: lwhomogenize.c:209
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition: liblwgeom.h:215
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:308
POINT4D getPoint4d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:105
char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2)
Definition: lwcircstring.c:138
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:335
int ptarray_isccw(const POINTARRAY *pa)
Definition: ptarray.c:1029
double f
Definition: liblwgeom.h:315
uint8_t type
Definition: liblwgeom.h:464
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
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:214
uint8_t type
Definition: liblwgeom.h:542
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:298
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:176
double xmin
Definition: liblwgeom.h:292
LWCIRCSTRING * lwcircstring_construct_empty(int srid, char hasz, char hasm)
Definition: lwcircstring.c:80
LWCURVEPOLY * lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
int32_t srid
Definition: liblwgeom.h:532
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2)
Definition: lwtriangle.c:133
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition: lwgeom.c:236
uint8_t type
Definition: liblwgeom.h:451
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:373
void lwcircstring_release(LWCIRCSTRING *lwcirc)
Definition: lwcircstring.c:92
POINT3DM getPoint3dm(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:200
LW_LINEARIZE_FLAGS
Definition: liblwgeom.h:2220
uint8_t flags
Definition: liblwgeom.h:369
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
GBOX * bbox
Definition: liblwgeom.h:531
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:174
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
Definition: lwgeom_api.c:36
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
Definition: g_serialized.c:65
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:239
LWPOLY ** geoms
Definition: liblwgeom.h:496
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
Definition: liblwgeom.h:2020
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:290
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
Definition: lwpoint.c:47
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition: lwutil.c:294
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3206
LWGEOM ** geoms
Definition: liblwgeom.h:509
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1602
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:254
LWTRIANGLE ** geoms
Definition: liblwgeom.h:587
void lwpsurface_release(LWPSURFACE *lwpsurface)
GBOX * gserialized_calculate_gbox_geocentric(const GSERIALIZED *g)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates...
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
uint8_t flags
Definition: liblwgeom.h:491
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:739
uint8_t type
Definition: liblwgeom.h:440
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1753
GBOX * bbox
Definition: liblwgeom.h:570
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
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:295
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
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:717
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition: lwgeom.c:210
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:689
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition: ptarray.c:187
LWPOINT * lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
POINTARRAY ** rings
Definition: liblwgeom.h:457
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1048
double e
Definition: liblwgeom.h:316
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition: lwgeom.c:283
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:309
uint8_t precision
Definition: cu_in_twkb.c:25
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition: lwkmeans.c:77
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:173
LWPOINT ** geoms
Definition: liblwgeom.h:470
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:630
double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing max distance calculation.
Definition: measures.c:169
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
LWCURVEPOLY * lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwcurvepoly.c:36
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form...
Definition: g_box.c:451
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:156
int maxgeoms
Definition: liblwgeom.h:573
int nrings
Definition: liblwgeom.h:455
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:39
int32_t srid
Definition: liblwgeom.h:506
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:108
double ymax
Definition: liblwgeom.h:295
int lwgeom_has_arc(const LWGEOM *geom)
Definition: lwstroke.c:54
LWGEOM * lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:48
void printLWLINE(LWLINE *line)
Definition: lwline.c:88
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:293
enum LWORD_T LWORD
Ordinate names.
char * s
Definition: cu_in_wkt.c:23
double y
Definition: liblwgeom.h:328
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where)
Insert a point into an existing POINTARRAY.
Definition: ptarray.c:96
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:347
uint8_t flags
Definition: liblwgeom.h:530
void(* lwreporter)(const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:218
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:1851
LWCOLLECTION * lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset)
Given a geometry clip based on the from/to range of one of its ordinates (x, y, z, m).
double e_sq
Definition: liblwgeom.h:317
double z
Definition: liblwgeom.h:352
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:198
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
LWCOMPOUND * lwcompound_construct_from_lwline(const LWLINE *lwpoly)
Construct an equivalent compound curve from a linestring.
Definition: lwcompound.c:204
int point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj)
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&#39;t already there) interpolating the measure betwe...
Definition: lwmline.c:56
uint8_t type
Definition: liblwgeom.h:581
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:444
Datum distance(PG_FUNCTION_ARGS)
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:64
double y
Definition: liblwgeom.h:346
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:2027
int ngeoms
Definition: liblwgeom.h:494
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:907
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
int32_t srid
Definition: liblwgeom.h:410
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:51
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, int maxvertices)
Definition: lwgeom.c:2054
uint8_t flags
Definition: liblwgeom.h:291
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:544
char * gserialized_to_string(const GSERIALIZED *g)
Return a WKT representation of the gserialized geometry.
Definition: g_serialized.c:193
void lwtriangle_free(LWTRIANGLE *triangle)
Definition: lwtriangle.c:69
LWCOLLECTION * lwcollection_segmentize2d(LWCOLLECTION *coll, double dist)
Definition: lwcollection.c:237
void *(* lwreallocator)(void *mem, size_t size)
Definition: liblwgeom.h:216
void lwpsurface_free(LWPSURFACE *psurf)
Definition: lwpsurface.c:39
int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2)
Return -1 if g1 is "less than" g2, 1 if g1 is "greater than" g2 and 0 if g1 and g2 are the "same"...
Definition: g_serialized.c:294
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:797
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
unsigned int geohash_point_as_int(POINT2D *pt)
Definition: lwalgorithm.c:647
int lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition: lwgeom.c:1298
double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist)
Find the time of closest point of approach.
LWPOINT * lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged)
int maxgeoms
Definition: liblwgeom.h:586
LWGEOM * lwgeom_locate_along(const LWGEOM *lwin, double m, double offset)
Determine the location(s) along a measured line where m occurs and return as a multipoint.
int gbox_merge(const GBOX *new_box, GBOX *merged_box)
Update the merged GBOX to be large enough to include itself and the new box.
Definition: g_box.c:269
uint8_t type
Definition: liblwgeom.h:568
GBOX * bbox
Definition: liblwgeom.h:442
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
Symmetric linearization means that the output vertices would be the same no matter the order of the p...
Definition: liblwgeom.h:2226
POINT2D * center
Definition: liblwgeom.h:1643
void lwcollection_release(LWCOLLECTION *lwcollection)
Definition: lwcollection.c:36
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:513
uint8_t flags
Definition: liblwgeom.h:408
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:213
void lwpoly_reverse(LWPOLY *poly)
Definition: lwpoly.c:314
LWLINE ** geoms
Definition: liblwgeom.h:483
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
Definition: ptarray.c:1720
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
Definition: lwgeodetic.c:2873
char lwtriangle_is_repeated_points(LWTRIANGLE *triangle)
Definition: lwtriangle.c:169
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition: lwgeom.c:1668
void lwgeom_reverse(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition: lwgeom.c:93
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:183
int ngeoms
Definition: liblwgeom.h:559
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:368
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:166
int maxrings
Definition: liblwgeom.h:456
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:107
int maxgeoms
Definition: liblwgeom.h:482
Tolerance expresses the number of segments to use for each quarter of circle (quadrant).
Definition: liblwgeom.h:2202
void lwline_reverse(LWLINE *line)
Definition: lwline.c:140
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
Definition: g_box.c:209
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
Definition: lwalgorithm.c:846
GBOX * bbox
Definition: liblwgeom.h:409
int getPoint2d_p_ro(const POINTARRAY *pa, int n, POINT2D **point)
New function to read doubles directly from the double* coordinate array of an aligned lwgeom POINTARR...
Definition: lwgeodetic.c:2858
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:708
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, int n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:387
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:472
void ptarray_longitude_shift(POINTARRAY *pa)
Longitude shift for a pointarray.
Definition: ptarray.c:1417
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
double a
Definition: liblwgeom.h:313
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition: lwgeom.c:711
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:1739
LWPOINT * lwpoint_make4d(int srid, double x, double y, double z, double m)
Definition: lwpoint.c:195
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition: lwpoint.c:52
int32_t srid
Definition: liblwgeom.h:454
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:479
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition: lwgeom.c:248
LWMPOINT * lwmpoly_to_points(const LWMPOLY *mpoly, int npoints)
uint32_t size
Definition: liblwgeom.h:381
int maxgeoms
Definition: liblwgeom.h:521
LWGEOM ** geoms
Definition: liblwgeom.h:561
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
LWMPOINT * lwpoly_to_points(const LWPOLY *poly, int npoints)
int ptarray_remove_point(POINTARRAY *pa, int where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:261
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:220
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:192
LWGEOM * lwgeom_from_twkb(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
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1623
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:199
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:1241
double mmin
Definition: liblwgeom.h:298
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
Definition: measures3d.c:818
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:683
int ngeoms
Definition: liblwgeom.h:520
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:445
double zmin
Definition: liblwgeom.h:296
int lwgeom_is_simple(const LWGEOM *lwgeom)
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:117
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:879
void(*) typedef void(*) voi lwgeom_set_handlers)(lwallocator allocator, lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, lwreporter noticereporter)
Install custom memory management and error handling functions you want your application to use...
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
double ptarray_arc_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY, using circular arc interpolation between each coordinate ...
Definition: ptarray.c:1665
LWGEOM ** geoms
Definition: liblwgeom.h:548
double lwgeom_length(const LWGEOM *geom)
Definition: lwgeom.c:1690
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
LWGEOM * lwgeom_segmentize2d(LWGEOM *line, double dist)
Definition: lwgeom.c:717
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:201
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
void printLWPOINT(LWPOINT *point)
Definition: lwpoint.c:224
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing min distance calculation.
Definition: measures.c:202
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, int npoints)
const POINT4D * getPoint4d_cp(const POINTARRAY *pa, int n)
Returns a POINT4D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:408
void ptarray_reverse(POINTARRAY *pa)
Definition: ptarray.c:343
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition: lwgeom.c:228
Retain angle instructs the engine to try its best to retain the requested angle between generating ra...
Definition: liblwgeom.h:2246
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:547
int32_t srid
Definition: liblwgeom.h:558
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:421
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
LWPOINT * lwline_get_lwpoint(const LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:324
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:51
uint8_t type
Definition: liblwgeom.h:396
int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1548
type
Definition: ovdump.py:41
uint8_t type
Definition: liblwgeom.h:516
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: g_serialized.c:60
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:72
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
double mmax
Definition: liblwgeom.h:299
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:340
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:303
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition: lwutil.c:171
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition: lwgeom.c:243
POINTARRAY * points
Definition: liblwgeom.h:444
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom)
Definition: lwgeom.c:751
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:642
CG_LINE_CROSS_TYPE
The return values of lwline_crossing_direction()
Definition: liblwgeom.h:1510
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Remove repeated points!
Definition: lwgeom.c:1456
double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d max distance calculation.
Definition: measures3d.c:314
LWGEOM * lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj)
Definition: lwgeom.c:278
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:42
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:249
int maxgeoms
Definition: liblwgeom.h:469
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:2183
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2327
LWORD_T
Ordinate names.
Definition: liblwgeom.h:113
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 maxpoints
Definition: liblwgeom.h:372
int value
Definition: genraster.py:61
uint8_t flags
Definition: liblwgeom.h:452
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:373
LWPOLY * lwpoly_segmentize2d(LWPOLY *line, double dist)
Definition: lwpoly.c:323
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Check clockwise orientation on LWGEOM polygons.
Definition: lwgeom.c:64
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition: ptarray.c:557
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:736
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void * lwalloc(size_t size)
Definition: lwutil.c:229
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1346
uint8_t flags
Definition: liblwgeom.h:582
void lwmline_release(LWMLINE *lwline)
Definition: lwmline.c:32
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:342
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1189
LWGEOM * lwgeom_unstroke(const LWGEOM *geom)
Definition: lwstroke.c:1139
GBOX * bbox
Definition: liblwgeom.h:492
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:772
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where)
Definition: lwcompound.c:213
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
Definition: g_box.c:126
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2391
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
int ngeoms
Definition: liblwgeom.h:468
opts
Definition: ovdump.py:44
uint32_t gserialized_max_header_size(void)
Returns the size in bytes to read from toast to get the basic information from a geometry: GSERIALIZE...
Definition: g_serialized.c:70
uint8_t flags
Definition: liblwgeom.h:419
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2427
LWGEOM * lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags)
Definition: lwstroke.c:734
int32_t srid
Definition: liblwgeom.h:571
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:615
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:363
void lwline_release(LWLINE *lwline)
Definition: lwline.c:134
unsigned char uint8_t
Definition: uthash.h:79
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:43
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:158
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
Definition: lwpoly.c:347
int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
int ngeoms
Definition: liblwgeom.h:572
int32_t srid
Definition: liblwgeom.h:467
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:892
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1152
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:253
char lwline_same(const LWLINE *p1, const LWLINE *p2)
Definition: lwline.c:156
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:47
int lwpointiterator_peek(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assigns the next point in the iterator to p.
Definition: lwiterator.c:195
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:89
int32_t srid
Definition: liblwgeom.h:584
int gserialized_calculate_gbox_geocentric_p(const GSERIALIZED *g, GBOX *g_box)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates...
int32_t srid
Definition: liblwgeom.h:493
int maxgeoms
Definition: liblwgeom.h:560
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, int where)
Definition: lwcircstring.c:300
int32_t srid
Definition: liblwgeom.h:432
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:404
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
GBOX * bbox
Definition: liblwgeom.h:479
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition: lwcompound.c:88
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:683
uint8_t type
Definition: liblwgeom.h:490
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1735
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:43
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
uint8_t flags
Definition: liblwgeom.h:383
double zmax
Definition: liblwgeom.h:278
int32_t srid
Definition: liblwgeom.h:480
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition: lwtriangle.c:82
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
uint8_t flags
Definition: liblwgeom.h:430
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
POINTARRAY * points
Definition: liblwgeom.h:422
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:539
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:268
double zmin
Definition: liblwgeom.h:277
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:263
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition: ptarray.c:599