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