PostGIS  2.3.8dev-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.3.8dev"
65 #define LIBLWGEOM_VERSION_MAJOR "2"
66 #define LIBLWGEOM_VERSION_MINOR "3"
67 #define LIBLWGEOM_GEOS_VERSION "37"
68 
70 const char* lwgeom_version(void);
71 
75 #define LW_TRUE 1
76 #define LW_FALSE 0
77 #define LW_UNKNOWN 2
78 #define LW_FAILURE 0
79 #define LW_SUCCESS 1
80 
84 #define POINTTYPE 1
85 #define LINETYPE 2
86 #define POLYGONTYPE 3
87 #define MULTIPOINTTYPE 4
88 #define MULTILINETYPE 5
89 #define MULTIPOLYGONTYPE 6
90 #define COLLECTIONTYPE 7
91 #define CIRCSTRINGTYPE 8
92 #define COMPOUNDTYPE 9
93 #define CURVEPOLYTYPE 10
94 #define MULTICURVETYPE 11
95 #define MULTISURFACETYPE 12
96 #define POLYHEDRALSURFACETYPE 13
97 #define TRIANGLETYPE 14
98 #define TINTYPE 15
99 
100 #define NUMTYPES 16
101 
106 #define WKBZOFFSET 0x80000000
107 #define WKBMOFFSET 0x40000000
108 #define WKBSRIDFLAG 0x20000000
109 #define WKBBBOXFLAG 0x10000000
110 
112 typedef enum LWORD_T {
113  LWORD_X = 0,
114  LWORD_Y = 1,
115  LWORD_Z = 2,
117 } LWORD;
118 
119 /**********************************************************************
120 ** Spherical radius.
121 ** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
122 ** the XVII General Assembly of the IUGG in Canberra.
123 ** http://en.wikipedia.org/wiki/Earth_radius
124 ** http://en.wikipedia.org/wiki/World_Geodetic_System
125 */
126 
127 #define WGS84_MAJOR_AXIS 6378137.0
128 #define WGS84_INVERSE_FLATTENING 298.257223563
129 #define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
130 #define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
131 
132 
139 #define FLAGS_GET_Z(flags) ((flags) & 0x01)
140 #define FLAGS_GET_M(flags) (((flags) & 0x02)>>1)
141 #define FLAGS_GET_BBOX(flags) (((flags) & 0x04)>>2)
142 #define FLAGS_GET_GEODETIC(flags) (((flags) & 0x08)>>3)
143 #define FLAGS_GET_READONLY(flags) (((flags) & 0x10)>>4)
144 #define FLAGS_GET_SOLID(flags) (((flags) & 0x20)>>5)
145 #define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | 0x01) : ((flags) & 0xFE))
146 #define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | 0x02) : ((flags) & 0xFD))
147 #define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | 0x04) : ((flags) & 0xFB))
148 #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | 0x08) : ((flags) & 0xF7))
149 #define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | 0x10) : ((flags) & 0xEF))
150 #define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | 0x20) : ((flags) & 0xDF))
151 #define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
152 #define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
153 #define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
154 
164 #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
165 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
166 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
167 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
168 #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
169 #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
170 #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
171 #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
172 #define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
173 
178 #define SRID_MAXIMUM 999999
179 
184 #define SRID_USER_MAXIMUM 998999
185 
187 #define SRID_UNKNOWN 0
188 #define SRID_IS_UNKNOWN(x) ((int)x<=0)
189 
190 /*
191 ** EPSG WGS84 geographics, OGC standard default SRS, better be in
192 ** the SPATIAL_REF_SYS table!
193 */
194 #define SRID_DEFAULT 4326
195 
196 #ifndef __GNUC__
197 # define __attribute__(x)
198 #endif
199 
206 extern int clamp_srid(int srid);
207 
208 /* Raise an lwerror if srids do not match */
209 void error_if_srid_mismatch(int srid1, int srid2);
210 
214 typedef void* (*lwallocator)(size_t size);
215 typedef void* (*lwreallocator)(void *mem, size_t size);
216 typedef void (*lwfreeor)(void* mem);
217 typedef void (*lwreporter)(const char* fmt, va_list ap)
218  __attribute__ (( format(printf, 1, 0) ));
219 typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
220  __attribute__ (( format(printf, 2,0) ));
221 
228 extern void lwgeom_set_handlers(lwallocator allocator,
229  lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
230  lwreporter noticereporter);
231 
232 extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
233 
246 extern void lwgeom_request_interrupt(void);
247 
251 extern void lwgeom_cancel_interrupt(void);
252 
263 typedef void (lwinterrupt_callback)();
265 
266 /******************************************************************/
267 
268 typedef struct {
269  double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
270 } AFFINE;
271 
272 /******************************************************************/
273 
274 typedef struct
275 {
276  double xmin, ymin, zmin;
277  double xmax, ymax, zmax;
278  int32_t srid;
279 }
280 BOX3D;
281 
282 /******************************************************************
283 * GBOX structure.
284 * We include the flags (information about dimensinality),
285 * so we don't have to constantly pass them
286 * into functions that use the GBOX.
287 */
288 typedef struct
289 {
290  uint8_t flags;
291  double xmin;
292  double xmax;
293  double ymin;
294  double ymax;
295  double zmin;
296  double zmax;
297  double mmin;
298  double mmax;
299 } GBOX;
300 
301 
302 /******************************************************************
303 * SPHEROID
304 *
305 * Standard definition of an ellipsoid (what wkt calls a spheroid)
306 * f = (a-b)/a
307 * e_sq = (a*a - b*b)/(a*a)
308 * b = a - fa
309 */
310 typedef struct
311 {
312  double a; /* semimajor axis */
313  double b; /* semiminor axis b = (a - fa) */
314  double f; /* flattening f = (a-b)/a */
315  double e; /* eccentricity (first) */
316  double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
317  double radius; /* spherical average radius = (2*a+b)/3 */
318  char name[20]; /* name of ellipse */
319 }
320 SPHEROID;
321 
322 /******************************************************************
323 * POINT2D, POINT3D, POINT3DM, POINT4D
324 */
325 typedef struct
326 {
327  double x, y;
328 }
329 POINT2D;
330 
331 typedef struct
332 {
333  double x, y, z;
334 }
335 POINT3DZ;
336 
337 typedef struct
338 {
339  double x, y, z;
340 }
341 POINT3D;
342 
343 typedef struct
344 {
345  double x, y, m;
346 }
347 POINT3DM;
348 
349 typedef struct
350 {
351  double x, y, z, m;
352 }
353 POINT4D;
354 
355 /******************************************************************
356 * POINTARRAY
357 * Point array abstracts a lot of the complexity of points and point lists.
358 * It handles 2d/3d translation
359 * (2d points converted to 3d will have z=0 or NaN)
360 * DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
361 */
362 typedef struct
363 {
364  /* Array of POINT 2D, 3D or 4D, possibly missaligned. */
366 
367  /* Use FLAGS_* macros to handle */
368  uint8_t flags;
369 
370  int npoints; /* how many points we are currently storing */
371  int maxpoints; /* how many points we have space for in serialized_pointlist */
372 }
373 POINTARRAY;
374 
375 /******************************************************************
376 * GSERIALIZED
377 */
378 typedef struct
379 {
380  uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
381  uint8_t srid[3]; /* 24 bits of SRID */
382  uint8_t flags; /* HasZ, HasM, HasBBox, IsGeodetic, IsReadOnly */
383  uint8_t data[1]; /* See gserialized.txt */
384 } GSERIALIZED;
385 
386 
387 /******************************************************************
388 * LWGEOM (any geometry type)
389 *
390 * Abstract type, note that 'type', 'bbox' and 'srid' are available in
391 * all geometry variants.
392 */
393 typedef struct
394 {
395  uint8_t type;
396  uint8_t flags;
398  int32_t srid;
399  void *data;
400 }
401 LWGEOM;
402 
403 /* POINTYPE */
404 typedef struct
405 {
406  uint8_t type; /* POINTTYPE */
407  uint8_t flags;
409  int32_t srid;
410  POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
411 }
412 LWPOINT; /* "light-weight point" */
413 
414 /* LINETYPE */
415 typedef struct
416 {
417  uint8_t type; /* LINETYPE */
418  uint8_t flags;
420  int32_t srid;
421  POINTARRAY *points; /* array of POINT3D */
422 }
423 LWLINE; /* "light-weight line" */
424 
425 /* TRIANGLE */
426 typedef struct
427 {
428  uint8_t type;
429  uint8_t flags;
431  int32_t srid;
433 }
434 LWTRIANGLE;
435 
436 /* CIRCSTRINGTYPE */
437 typedef struct
438 {
439  uint8_t type; /* CIRCSTRINGTYPE */
440  uint8_t flags;
442  int32_t srid;
443  POINTARRAY *points; /* array of POINT(3D/3DM) */
444 }
445 LWCIRCSTRING; /* "light-weight circularstring" */
446 
447 /* POLYGONTYPE */
448 typedef struct
449 {
450  uint8_t type; /* POLYGONTYPE */
451  uint8_t flags;
453  int32_t srid;
454  int nrings; /* how many rings we are currently storing */
455  int maxrings; /* how many rings we have space for in **rings */
456  POINTARRAY **rings; /* list of rings (list of points) */
457 }
458 LWPOLY; /* "light-weight polygon" */
459 
460 /* MULTIPOINTTYPE */
461 typedef struct
462 {
463  uint8_t type;
464  uint8_t flags;
466  int32_t srid;
467  int ngeoms; /* how many geometries we are currently storing */
468  int maxgeoms; /* how many geometries we have space for in **geoms */
470 }
471 LWMPOINT;
472 
473 /* MULTILINETYPE */
474 typedef struct
475 {
476  uint8_t type;
477  uint8_t flags;
479  int32_t srid;
480  int ngeoms; /* how many geometries we are currently storing */
481  int maxgeoms; /* how many geometries we have space for in **geoms */
483 }
484 LWMLINE;
485 
486 /* MULTIPOLYGONTYPE */
487 typedef struct
488 {
489  uint8_t type;
490  uint8_t flags;
492  int32_t srid;
493  int ngeoms; /* how many geometries we are currently storing */
494  int maxgeoms; /* how many geometries we have space for in **geoms */
496 }
497 LWMPOLY;
498 
499 /* COLLECTIONTYPE */
500 typedef struct
501 {
502  uint8_t type;
503  uint8_t flags;
505  int32_t srid;
506  int ngeoms; /* how many geometries we are currently storing */
507  int maxgeoms; /* how many geometries we have space for in **geoms */
509 }
511 
512 /* COMPOUNDTYPE */
513 typedef struct
514 {
515  uint8_t type; /* COMPOUNDTYPE */
516  uint8_t flags;
518  int32_t srid;
519  int ngeoms; /* how many geometries we are currently storing */
520  int maxgeoms; /* how many geometries we have space for in **geoms */
522 }
523 LWCOMPOUND; /* "light-weight compound line" */
524 
525 /* CURVEPOLYTYPE */
526 typedef struct
527 {
528  uint8_t type; /* CURVEPOLYTYPE */
529  uint8_t flags;
531  int32_t srid;
532  int nrings; /* how many rings we are currently storing */
533  int maxrings; /* how many rings we have space for in **rings */
534  LWGEOM **rings; /* list of rings (list of points) */
535 }
536 LWCURVEPOLY; /* "light-weight polygon" */
537 
538 /* MULTICURVE */
539 typedef struct
540 {
541  uint8_t type;
542  uint8_t flags;
544  int32_t srid;
545  int ngeoms; /* how many geometries we are currently storing */
546  int maxgeoms; /* how many geometries we have space for in **geoms */
548 }
549 LWMCURVE;
550 
551 /* MULTISURFACETYPE */
552 typedef struct
553 {
554  uint8_t type;
555  uint8_t flags;
557  int32_t srid;
558  int ngeoms; /* how many geometries we are currently storing */
559  int maxgeoms; /* how many geometries we have space for in **geoms */
561 }
562 LWMSURFACE;
563 
564 /* POLYHEDRALSURFACETYPE */
565 typedef struct
566 {
567  uint8_t type;
568  uint8_t flags;
570  int32_t srid;
571  int ngeoms; /* how many geometries we are currently storing */
572  int maxgeoms; /* how many geometries we have space for in **geoms */
574 }
575 LWPSURFACE;
576 
577 /* TINTYPE */
578 typedef struct
579 {
580  uint8_t type;
581  uint8_t flags;
583  int32_t srid;
584  int ngeoms; /* how many geometries we are currently storing */
585  int maxgeoms; /* how many geometries we have space for in **geoms */
587 }
588 LWTIN;
589 
590 /* Casts LWGEOM->LW* (return NULL if cast is illegal) */
591 extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
592 extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
593 extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
594 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
595 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
596 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
597 extern LWPOINT *lwgeom_as_lwpoint(const LWGEOM *lwgeom);
598 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
599 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
600 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
601 extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
602 extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
603 extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
604 extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
605 extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
606 
607 /* Casts LW*->LWGEOM (always cast) */
608 extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
609 extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
610 extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
611 extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
612 extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
613 extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
614 extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
615 extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
616 extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
617 extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
618 extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
619 extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
620 extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
621 
622 
623 extern LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom);
624 extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
625 extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
626 extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
627 extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
628 extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
629 
630 
631 
632 /***********************************************************************
633 ** Utility functions for flag byte and srid_flag integer.
634 */
635 
639 extern uint8_t gflags(int hasz, int hasm, int geodetic);
640 
645 extern uint32_t gserialized_get_type(const GSERIALIZED *g);
646 
651 extern uint32_t gserialized_max_header_size(void);
652 
657 extern int32_t gserialized_get_srid(const GSERIALIZED *g);
658 
663 extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
664 
671 extern int gserialized_is_empty(const GSERIALIZED *g);
672 
676 extern int gserialized_has_bbox(const GSERIALIZED *gser);
677 
681 extern int gserialized_has_z(const GSERIALIZED *gser);
682 
686 extern int gserialized_has_m(const GSERIALIZED *gser);
687 
691 extern int gserialized_is_geodetic(const GSERIALIZED *gser);
692 
697 extern int gserialized_get_zm(const GSERIALIZED *gser);
698 
702 extern int gserialized_ndims(const GSERIALIZED *gser);
703 
704 
711 extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
712 extern void lwgeom_drop_srid(LWGEOM *lwgeom);
713 
720 extern void lwgeom_add_bbox(LWGEOM *lwgeom);
724 extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
725 
733 extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
734 
738 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
739 
740 /******************************************************************/
741 /* Functions that work on type numbers */
742 
746 extern int lwtype_is_collection(uint8_t type);
747 
751 extern int lwtype_get_collectiontype(uint8_t type);
752 
757 extern const char *lwtype_name(uint8_t type);
758 
759 
760 /******************************************************************/
761 
762 /*
763  * copies a point from the point array into the parameter point
764  * will set point's z=0 (or NaN) if pa is 2d
765  * will set point's m=0 (or NaN) if pa is 3d or 2d
766  * NOTE: point is a real POINT3D *not* a pointer
767  */
768 extern POINT4D getPoint4d(const POINTARRAY *pa, int n);
769 
770 /*
771  * copies a point from the point array into the parameter point
772  * will set point's z=0 (or NaN) if pa is 2d
773  * will set point's m=0 (or NaN) if pa is 3d or 2d
774  * NOTE: this will modify the point4d pointed to by 'point'.
775  */
776 extern int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point);
777 
778 /*
779  * copies a point from the point array into the parameter point
780  * will set point's z=0 (or NaN) if pa is 2d
781  * NOTE: point is a real POINT3D *not* a pointer
782  */
783 extern POINT3DZ getPoint3dz(const POINTARRAY *pa, int n);
784 extern POINT3DM getPoint3dm(const POINTARRAY *pa, int n);
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  * NOTE: this will modify the point3d pointed to by 'point'.
790  */
791 extern int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point);
792 extern int getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *point);
793 
794 
795 /*
796  * copies a point from the point array into the parameter point
797  * z value (if present is not returned)
798  * NOTE: point is a real POINT3D *not* a pointer
799  */
800 extern POINT2D getPoint2d(const POINTARRAY *pa, int n);
801 
802 /*
803  * copies a point from the point array into the parameter point
804  * z value (if present is not returned)
805  * NOTE: this will modify the point2d pointed to by 'point'.
806  */
807 extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point);
808 
815 extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, int n);
816 
823 extern const POINT3DZ* getPoint3dz_cp(const POINTARRAY *pa, int n);
824 
831 extern const POINT4D* getPoint4d_cp(const POINTARRAY *pa, int n);
832 
833 /*
834  * set point N to the given value
835  * NOTE that the pointarray can be of any
836  * dimension, the appropriate ordinate values
837  * will be extracted from it
838  *
839  * N must be a valid point index
840  */
841 extern void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d);
842 
843 /*
844  * get a pointer to nth point of a POINTARRAY
845  * You'll need to cast it to appropriate dimensioned point.
846  * Note that if you cast to a higher dimensional point you'll
847  * possibly corrupt the POINTARRAY.
848  *
849  * WARNING: Don't cast this to a POINT !
850  * it would not be reliable due to memory alignment constraints
851  */
852 extern uint8_t *getPoint_internal(const POINTARRAY *pa, int n);
853 
854 /*
855  * size of point represeneted in the POINTARRAY
856  * 16 for 2d, 24 for 3d, 32 for 4d
857  */
858 extern int ptarray_point_size(const POINTARRAY *pa);
859 
860 
866 extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
867 
871 extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
872 
876 extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
877 
883 extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
884 
890 extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
891 
903 extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
904 
909 extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where);
910 
915 extern int ptarray_remove_point(POINTARRAY *pa, int where);
916 
928 extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
929 
935 extern POINTARRAY *ptarray_removePoint(POINTARRAY *pa, uint32_t where);
936 
943 extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
944 
945 extern int ptarray_is_closed(const POINTARRAY *pa);
946 extern int ptarray_is_closed_2d(const POINTARRAY *pa);
947 extern int ptarray_is_closed_3d(const POINTARRAY *pa);
948 extern int ptarray_is_closed_z(const POINTARRAY *pa);
949 extern void ptarray_longitude_shift(POINTARRAY *pa);
950 extern int ptarray_isccw(const POINTARRAY *pa);
951 extern void ptarray_reverse(POINTARRAY *pa);
953 
959 extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
960  double tolerance);
961 
962 
966 extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
967 extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
968 extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
969 extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
970 
971 extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
972 extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
973 
974 /*
975  * Force to use SFS 1.1 geometry type
976  * (rather than SFS 1.2 and/or SQL/MM)
977  */
978 extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
979 
980 
981 /*--------------------------------------------------------
982  * all the base types (point/line/polygon) will have a
983  * basic constructor, basic de-serializer, basic serializer,
984  * bounding box finder and (TODO) serialized form size finder.
985  *--------------------------------------------------------*/
986 
987 /*
988  * convenience functions to hide the POINTARRAY
989  */
990 extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
991 extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
992 extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
993 extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
994 
995 /******************************************************************
996  * LWLINE functions
997  ******************************************************************/
998 
1002 extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where);
1003 
1004 /******************************************************************
1005  * LWPOLY functions
1006  ******************************************************************/
1007 
1012 extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1013 
1018 extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1019 
1024 extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1025 
1030 extern LWCOMPOUND* lwcompound_construct_from_lwline(const LWLINE *lwpoly);
1031 
1037 
1038 
1039 /******************************************************************
1040  * LWGEOM functions
1041  ******************************************************************/
1042 
1043 extern int lwcollection_ngeoms(const LWCOLLECTION *col);
1044 
1045 /* Given a generic geometry/collection, return the "simplest" form.
1046  * The elements of the homogenized collection are references to the
1047  * input geometry; a deep clone is not performed.
1048  * TODO: consider returning a geometry that does not reference the
1049  * input
1050  * */
1051 extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
1052 
1053 
1054 /******************************************************************
1055  * LWMULTIx and LWCOLLECTION functions
1056  ******************************************************************/
1057 
1060 
1061 
1062 /******************************************************************
1063  * SERIALIZED FORM functions
1064  ******************************************************************/
1065 
1071 extern void lwgeom_set_srid(LWGEOM *geom, int srid);
1072 
1073 /*------------------------------------------------------
1074  * other stuff
1075  *
1076  * handle the double-to-float conversion. The results of this
1077  * will usually be a slightly bigger box because of the difference
1078  * between float8 and float4 representations.
1079  */
1080 
1081 extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1082 extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1083 
1084 void expand_box3d(BOX3D *box, double d);
1085 
1086 
1087 /****************************************************************
1088  * MEMORY MANAGEMENT
1089  ****************************************************************/
1090 
1091 /*
1092 * The *_free family of functions frees *all* memory associated
1093 * with the pointer. When the recursion gets to the level of the
1094 * POINTARRAY, the POINTARRAY is only freed if it is not flagged
1095 * as "read only". LWGEOMs constructed on top of GSERIALIZED
1096 * from PgSQL use read only point arrays.
1097 */
1098 
1099 extern void ptarray_free(POINTARRAY *pa);
1100 extern void lwpoint_free(LWPOINT *pt);
1101 extern void lwline_free(LWLINE *line);
1102 extern void lwpoly_free(LWPOLY *poly);
1103 extern void lwtriangle_free(LWTRIANGLE *triangle);
1104 extern void lwmpoint_free(LWMPOINT *mpt);
1105 extern void lwmline_free(LWMLINE *mline);
1106 extern void lwmpoly_free(LWMPOLY *mpoly);
1107 extern void lwpsurface_free(LWPSURFACE *psurf);
1108 extern void lwtin_free(LWTIN *tin);
1109 extern void lwcollection_free(LWCOLLECTION *col);
1110 extern void lwcircstring_free(LWCIRCSTRING *curve);
1111 extern void lwgeom_free(LWGEOM *geom);
1112 
1113 /*
1114 * The *_release family of functions frees the LWGEOM structures
1115 * surrounding the POINTARRAYs but leaves the POINTARRAYs
1116 * intact. Useful when re-shaping geometries between types,
1117 * or splicing geometries together.
1118 */
1119 
1120 extern void lwpoint_release(LWPOINT *lwpoint);
1121 extern void lwline_release(LWLINE *lwline);
1122 extern void lwpoly_release(LWPOLY *lwpoly);
1123 extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1124 extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1125 extern void lwmpoint_release(LWMPOINT *lwpoint);
1126 extern void lwmline_release(LWMLINE *lwline);
1127 extern void lwmpoly_release(LWMPOLY *lwpoly);
1128 extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1129 extern void lwtin_release(LWTIN *lwtin);
1130 extern void lwcollection_release(LWCOLLECTION *lwcollection);
1131 extern void lwgeom_release(LWGEOM *lwgeom);
1132 
1133 
1134 /****************************************************************
1135 * Utility
1136 ****************************************************************/
1137 
1138 extern void printBOX3D(BOX3D *b);
1139 extern void printPA(POINTARRAY *pa);
1140 extern void printLWPOINT(LWPOINT *point);
1141 extern void printLWLINE(LWLINE *line);
1142 extern void printLWPOLY(LWPOLY *poly);
1143 extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1144 extern void printLWPSURFACE(LWPSURFACE *psurf);
1145 extern void printLWTIN(LWTIN *tin);
1146 
1147 extern float next_float_down(double d);
1148 extern float next_float_up(double d);
1149 extern double next_double_down(float d);
1150 extern double next_double_up(float d);
1151 
1152 /* general utilities 2D */
1153 extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1154 extern double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2);
1155 extern double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1156 extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1157 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1158 extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1159 extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1160 extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1161 extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1162 extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1163 extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1164 extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1165 
1166 /* 3D */
1167 extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1168 extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1169 
1170 extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1171 extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1172 extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1173 
1174 
1175 extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1176 extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1177 extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1178 extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1179 
1180 extern double lwgeom_area(const LWGEOM *geom);
1181 extern double lwgeom_length(const LWGEOM *geom);
1182 extern double lwgeom_length_2d(const LWGEOM *geom);
1183 extern double lwgeom_perimeter(const LWGEOM *geom);
1184 extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1185 extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1186 extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1187 extern int lwgeom_dimension(const LWGEOM *geom);
1188 
1189 extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, int where);
1190 extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, int where);
1191 
1192 extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1193 extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1194 extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where);
1195 
1196 
1197 extern double ptarray_length_2d(const POINTARRAY *pts);
1198 extern double ptarray_length(const POINTARRAY *pts);
1199 extern double ptarray_arc_length_2d(const POINTARRAY *pts);
1200 
1201 
1202 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1203 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1204 extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1205 extern void lwgeom_reverse(LWGEOM *lwgeom);
1206 extern void lwline_reverse(LWLINE *line);
1207 extern void lwpoly_reverse(LWPOLY *poly);
1208 extern void lwtriangle_reverse(LWTRIANGLE *triangle);
1209 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1210 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1211 extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1212 
1217 extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1218 extern void lwpoly_force_clockwise(LWPOLY *poly);
1219 extern void lwtriangle_force_clockwise(LWTRIANGLE *triangle);
1220 
1221 
1222 extern void interpolate_point4d(POINT4D *A, POINT4D *B, POINT4D *I, double F);
1223 
1224 void lwgeom_longitude_shift(LWGEOM *lwgeom);
1225 
1238 LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1239 
1240 
1250 extern int lwgeom_needs_bbox(const LWGEOM *geom);
1251 
1255 extern int lwgeom_count_vertices(const LWGEOM *geom);
1256 
1261 extern int lwgeom_count_rings(const LWGEOM *geom);
1262 
1267 extern int lwgeom_has_srid(const LWGEOM *geom);
1268 
1273 extern int lwgeom_is_empty(const LWGEOM *geom);
1274 
1279 extern int lwgeom_is_closed(const LWGEOM *geom);
1280 
1284 extern int lwgeom_dimensionality(LWGEOM *geom);
1285 
1286 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
1287 char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1288 char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2);
1289 char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2);
1290 char lwline_same(const LWLINE *p1, const LWLINE *p2);
1291 char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2);
1292 char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2);
1293 char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2);
1294 char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2);
1295 
1296 
1304 extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1305 
1309 extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1310 
1311 /* TODO Move to Internal */
1312 LWPOINT *lwpoint_clone(const LWPOINT *lwgeom);
1313 POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1314 
1315 
1316 /*
1317 * Geometry constructors. These constructors to not copy the point arrays
1318 * passed to them, they just take references, so do not free them out
1319 * from underneath the geometries.
1320 */
1321 extern LWPOINT* lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point);
1322 extern LWMPOINT *lwmpoint_construct(int srid, const POINTARRAY *pa);
1323 extern LWLINE* lwline_construct(int srid, GBOX *bbox, POINTARRAY *points);
1324 extern LWCIRCSTRING* lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points);
1325 extern LWPOLY* lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1326 extern LWCURVEPOLY* lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1327 extern LWTRIANGLE* lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points);
1328 extern LWCOLLECTION* lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1329 /*
1330 * Empty geometry constructors.
1331 */
1332 extern LWGEOM* lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1333 extern LWPOINT* lwpoint_construct_empty(int srid, char hasz, char hasm);
1334 extern LWLINE* lwline_construct_empty(int srid, char hasz, char hasm);
1335 extern LWPOLY* lwpoly_construct_empty(int srid, char hasz, char hasm);
1336 extern LWCURVEPOLY* lwcurvepoly_construct_empty(int srid, char hasz, char hasm);
1337 extern LWCIRCSTRING* lwcircstring_construct_empty(int srid, char hasz, char hasm);
1338 extern LWCOMPOUND* lwcompound_construct_empty(int srid, char hasz, char hasm);
1339 extern LWTRIANGLE* lwtriangle_construct_empty(int srid, char hasz, char hasm);
1340 extern LWMPOINT* lwmpoint_construct_empty(int srid, char hasz, char hasm);
1341 extern LWMLINE* lwmline_construct_empty(int srid, char hasz, char hasm);
1342 extern LWMPOLY* lwmpoly_construct_empty(int srid, char hasz, char hasm);
1343 extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1344 
1345 
1346 /* Other constructors */
1347 extern LWPOINT *lwpoint_make2d(int srid, double x, double y);
1348 extern LWPOINT *lwpoint_make3dz(int srid, double x, double y, double z);
1349 extern LWPOINT *lwpoint_make3dm(int srid, double x, double y, double m);
1350 extern LWPOINT *lwpoint_make4d(int srid, double x, double y, double z, double m);
1351 extern LWPOINT *lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p);
1352 extern LWLINE *lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms);
1353 extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1354 extern LWLINE *lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint);
1355 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1356 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1357 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1358 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1359 extern LWPOLY* lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1360 extern LWPOLY* lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1361 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1362 extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1363 
1364 /* Some point accessors */
1365 extern double lwpoint_get_x(const LWPOINT *point);
1366 extern double lwpoint_get_y(const LWPOINT *point);
1367 extern double lwpoint_get_z(const LWPOINT *point);
1368 extern double lwpoint_get_m(const LWPOINT *point);
1369 
1373 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1374 
1378 extern uint32_t lwgeom_get_type(const LWGEOM *geom);
1379 
1383 extern int lwgeom_has_z(const LWGEOM *geom);
1384 
1388 extern int lwgeom_has_m(const LWGEOM *geom);
1389 
1393 extern int lwgeom_ndims(const LWGEOM *geom);
1394 
1395 /*
1396  * Given a point, returns the location of closest point on pointarray
1397  * as a fraction of total length (0: first point -- 1: last point).
1398  *
1399  * If not-null, the third argument will be set to the actual distance
1400  * of the point from the pointarray.
1401  */
1402 extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1403 
1408 extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1409 extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1410 
1415 extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1416 
1422 extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1423 
1427 extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1428 
1439 extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1440 
1446 extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1447 
1452 extern int lwgeom_is_trajectory(const LWGEOM *geom);
1453 extern int lwline_is_trajectory(const LWLINE *geom);
1454 
1455 /*
1456  * Ensure every segment is at most 'dist' long.
1457  * Returned LWGEOM might is unchanged if a POINT.
1458  */
1459 extern LWGEOM *lwgeom_segmentize2d(LWGEOM *line, double dist);
1460 extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1461 extern LWLINE *lwline_segmentize2d(LWLINE *line, double dist);
1462 extern LWPOLY *lwpoly_segmentize2d(LWPOLY *line, double dist);
1463 extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist);
1464 
1465 /*
1466  * Point density functions
1467  */
1468 extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, int npoints);
1469 extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, int npoints);
1470 extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, int npoints);
1471 
1472 /*
1473  * Geometric median
1474  */
1475 extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1476 extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1477 
1481 char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1482 unsigned int geohash_point_as_int(POINT2D *pt);
1483 
1484 
1496 };
1497 
1501 int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1502 
1506 LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1507 
1513 #define LW_GML_IS_DIMS (1<<0)
1514 
1515 #define LW_GML_IS_DEGREE (1<<1)
1516 
1517 #define LW_GML_SHORTLINE (1<<2)
1518 
1519 #define LW_GML_EXTENT (1<<4)
1520 
1521 
1522 #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1523 #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1524 
1531 #define LW_X3D_FLIP_XY (1<<0)
1532 #define LW_X3D_USE_GEOCOORDS (1<<1)
1533 #define X3D_USE_GEOCOORDS(x) ((x) & LW_X3D_USE_GEOCOORDS)
1534 
1535 
1536 
1537 extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1538 extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1542 extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1543 extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1544 extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1545 extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1546 extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1547 extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1548 extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1549 
1559 extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1560 
1566 extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1567 
1571 extern void spheroid_init(SPHEROID *s, double a, double b);
1572 
1578 extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1579 
1583 extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1584 
1589 extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1590 
1594 extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1595 
1600 extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1601 
1606 extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1607 
1612 extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1613 
1618 extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1619 
1620 typedef struct {
1622  double radius;
1624 
1626 
1627 /* Calculates the minimum circle that encloses all of the points in g, using a
1628  * two-dimensional implementation of the algorithm proposed in:
1629  *
1630  * Welzl, Emo (1991), "Smallest enclosing disks (balls and elipsoids)."
1631  * New Results and Trends in Computer Science (H. Maurer, Ed.), Lecture Notes
1632  * in Computer Science, 555 (1991) 359-370.
1633  *
1634  * Available online at the time of this writing at
1635  * https://www.inf.ethz.ch/personal/emo/PublFiles/SmallEnclDisk_LNCS555_91.pdf
1636  *
1637  * Returns NULL if the circle could not be calculated.
1638  */
1639 extern LWBOUNDINGCIRCLE* lwgeom_calculate_mbc(const LWGEOM* g);
1640 
1644 extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1645 
1646 extern char lwtriangle_is_repeated_points(LWTRIANGLE *triangle);
1647 
1660 extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1661 
1670 
1671 struct LWPOINTITERATOR;
1673 
1678 
1684 
1689 
1694 
1700 extern int lwpointiterator_modify_next(LWPOINTITERATOR* s, const POINT4D* p);
1701 
1709 
1715 
1716 
1720 extern uint8_t parse_hex(char *str);
1721 
1725 extern void deparse_hex(uint8_t str, char *result);
1726 
1727 
1728 
1729 /***********************************************************************
1730 ** Functions for managing serialized forms and bounding boxes.
1731 */
1732 
1739 
1746 
1751 extern char* gserialized_to_string(const GSERIALIZED *g);
1752 
1756 extern GSERIALIZED* gserialized_copy(const GSERIALIZED *g);
1757 
1761 extern int lwgeom_check_geodetic(const LWGEOM *geom);
1762 
1766 extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1767 
1771 extern int lwgeom_force_geodetic(LWGEOM *geom);
1772 
1776 extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1777 
1784 extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1785 
1791 extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1792 
1797 extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1798 
1803 extern int getPoint2d_p_ro(const POINTARRAY *pa, int n, POINT2D **point);
1804 
1808 extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1809 
1813 extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1814 
1818 void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1819 
1824 extern GBOX* gbox_new(uint8_t flags);
1825 
1830 extern void gbox_init(GBOX *gbox);
1831 
1835 extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1836 
1840 extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1841 
1845 extern void gbox_expand(GBOX *g, double d);
1846 
1850 extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
1851 
1855 extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1856 
1860 extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1861 
1865 extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1866 
1870 extern char* gbox_to_string(const GBOX *gbox);
1871 
1875 extern GBOX* gbox_copy(const GBOX *gbox);
1876 
1880 extern GBOX* gbox_from_string(const char *str);
1881 
1885 extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1886 
1890 extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1891 
1895 extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
1896 
1900 extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1901 
1906 extern size_t gbox_serialized_size(uint8_t flags);
1907 
1911 extern int gbox_same(const GBOX *g1, const GBOX *g2);
1912 
1916 extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
1917 
1922 extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
1923 
1930 extern void gbox_float_round(GBOX *gbox);
1931 
1935 extern int gbox_is_valid(const GBOX *gbox);
1936 
1941 extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
1942 
1948 extern size_t gserialized_from_lwgeom_size(const LWGEOM *geom);
1949 
1957 extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
1958 
1963 extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g);
1964 
1970 extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox);
1971 
1972 
1980 #define LW_PARSER_CHECK_MINPOINTS 1
1981 #define LW_PARSER_CHECK_ODD 2
1982 #define LW_PARSER_CHECK_CLOSURE 4
1983 #define LW_PARSER_CHECK_ZCLOSURE 8
1984 
1985 #define LW_PARSER_CHECK_NONE 0
1986 #define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
1987 
1993 {
1994  const char *wkinput; /* Copy of pointer to input WKT/WKB */
1995  uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
1996  int size; /* Size of serialized LWGEOM in bytes */
1997  LWGEOM *geom; /* Pointer to LWGEOM struct */
1998  const char *message; /* Error/warning message */
1999  int errcode; /* Error/warning number */
2000  int errlocation; /* Location of error */
2001  int parser_check_flags; /* Bitmask of validity checks run during this parse */
2002 }
2004 
2005 /*
2006  * Parser error messages (these must match the message array in lwgparse.c)
2007  */
2008 #define PARSER_ERROR_MOREPOINTS 1
2009 #define PARSER_ERROR_ODDPOINTS 2
2010 #define PARSER_ERROR_UNCLOSED 3
2011 #define PARSER_ERROR_MIXDIMS 4
2012 #define PARSER_ERROR_INVALIDGEOM 5
2013 #define PARSER_ERROR_INVALIDWKBTYPE 6
2014 #define PARSER_ERROR_INCONTINUOUS 7
2015 #define PARSER_ERROR_TRIANGLEPOINTS 8
2016 #define PARSER_ERROR_LESSPOINTS 9
2017 #define PARSER_ERROR_OTHER 10
2018 
2019 
2020 
2021 /*
2022  * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
2023  */
2025 {
2026  uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
2027  char *wkoutput; /* Pointer to WKT or WKB output */
2028  int size; /* Size of serialized LWGEOM in bytes */
2029  const char *message; /* Error/warning message */
2030  int errlocation; /* Location of error */
2031 }
2033 
2034 /*
2035  * Unparser error messages (these must match the message array in lwgunparse.c)
2036  */
2037 #define UNPARSER_ERROR_MOREPOINTS 1
2038 #define UNPARSER_ERROR_ODDPOINTS 2
2039 #define UNPARSER_ERROR_UNCLOSED 3
2040 
2041 
2042 /*
2043 ** Variants available for WKB and WKT output types
2044 */
2045 
2046 #define WKB_ISO 0x01
2047 #define WKB_SFSQL 0x02
2048 #define WKB_EXTENDED 0x04
2049 #define WKB_NDR 0x08
2050 #define WKB_XDR 0x10
2051 #define WKB_HEX 0x20
2052 #define WKB_NO_NPOINTS 0x40 /* Internal use only */
2053 #define WKB_NO_SRID 0x80 /* Internal use only */
2054 
2055 #define WKT_ISO 0x01
2056 #define WKT_SFSQL 0x02
2057 #define WKT_EXTENDED 0x04
2058 
2059 
2060 /*
2061 ** Variants available for TWKB
2062 */
2063 #define TWKB_BBOX 0x01 /* User wants bboxes */
2064 #define TWKB_SIZE 0x02 /* User wants sizes */
2065 #define TWKB_ID 0x04 /* User wants id */
2066 #define TWKB_NO_TYPE 0x10 /* No type because it is a sub geoemtry */
2067 #define TWKB_NO_ID 0x20 /* No ID because it is a subgeoemtry */
2068 #define TWKB_DEFAULT_PRECISION 0 /* Aim for 1m (or ft) rounding by default */
2069 
2070 /*
2071 ** New parsing and unparsing functions.
2072 */
2073 
2078 extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2079 
2085 extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2086 
2092 extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2093 
2097 extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2098 
2104 extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2105 
2110 extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2111 
2115 extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2116 
2117 extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2118 
2119 extern char* hexbytes_from_bytes(uint8_t *bytes, size_t size);
2120 
2121 /*
2122 * WKT detailed parsing support
2123 */
2124 extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2125 void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
2126 void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
2127 
2128 
2129 /* Memory management */
2130 extern void *lwalloc(size_t size);
2131 extern void *lwrealloc(void *mem, size_t size);
2132 extern void lwfree(void *mem);
2133 
2134 /* Utilities */
2135 extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2136 
2137 /*
2138 * TWKB functions
2139 */
2140 
2145 extern LWGEOM* lwgeom_from_twkb(uint8_t *twkb, size_t twkb_size, char check);
2146 
2152 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);
2153 
2154 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);
2155 
2156 /*******************************************************************************
2157  * SQLMM internal functions - TODO: Move into separate header files
2158  ******************************************************************************/
2159 
2160 int lwgeom_has_arc(const LWGEOM *geom);
2161 LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2163 
2164 /*******************************************************************************
2165  * GEOS proxy functions on LWGEOM
2166  ******************************************************************************/
2167 
2169 const char* lwgeom_geos_version(void);
2170 
2173 
2175 LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2176 LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2177 LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2179 LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2180 LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2181 LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2182 LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2183 LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, int maxvertices);
2184 
2194 LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
2195 
2196 /*
2197  * Return the set of paths shared between two linear geometries,
2198  * and their direction (same or opposite).
2199  *
2200  * @param geom1 a lineal geometry
2201  * @param geom2 another lineal geometry
2202  *
2203  * Requires GEOS-3.3.0+
2204  */
2205 LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
2206 
2207 /*
2208  * An offset curve against the input line.
2209  *
2210  * @param lwline a lineal geometry
2211  * @param size offset distance. Offset left if negative and right if positive
2212  * @param quadsegs number of quadrature segments in curves (try 8)
2213  * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
2214  * @param mitreLimit (try 5.0)
2215  * @return derived geometry (linestring or multilinestring)
2216  *
2217  * Requires GEOS-3.2.0+
2218  */
2219 LWGEOM* lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit);
2220 
2221 /*
2222  * Return true if the input geometry is "simple" as per OGC defn.
2223  *
2224  * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called
2225  * in that case)
2226  */
2227 int lwgeom_is_simple(const LWGEOM *lwgeom);
2228 
2229 
2230 /*******************************************************************************
2231  * PROJ4-dependent extra functions on LWGEOM
2232  ******************************************************************************/
2233 
2239 projPJ lwproj_from_string(const char* txt);
2240 
2247 int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj) ;
2248 int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj) ;
2249 int point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj) ;
2250 
2251 
2252 /*******************************************************************************
2253  * GEOS-dependent extra functions on LWGEOM
2254  ******************************************************************************/
2255 
2264 
2265 
2273 
2274 /*
2275  * Split (multi)polygon by line; (multi)line by (multi)line,
2276  * (multi)point or (multi)polygon boundary.
2277  *
2278  * Collections are accepted as first argument.
2279  * Returns all obtained pieces as a collection.
2280  */
2281 LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
2282 
2283 /*
2284  * Fully node a set of linestrings, using the least nodes preserving
2285  * all the input ones.
2286  *
2287  * Requires GEOS-3.3.0 or higher
2288  */
2289 LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2290 
2300 LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly);
2301 
2313 LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2314 
2323 int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k);
2324 
2325 
2326 #endif /* !defined _LIBLWGEOM_H */
2327 
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:549
int ngeoms
Definition: liblwgeom.h:545
int32_t srid
Definition: liblwgeom.h:518
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:2626
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
Definition: measures3d.c:363
int32_t srid
Definition: liblwgeom.h:278
LWLINE * lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end)
Add a measure dimension to a line, interpolating linearly from the start to the end value...
Definition: lwline.c:396
uint8_t type
Definition: liblwgeom.h:417
uint8_t flags
Definition: liblwgeom.h:568
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition: lwutil.c:378
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition: lwstroke.c:462
uint8_t flags
Definition: liblwgeom.h:542
LWGEOM * lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area)
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
Definition: lwout_gml.c:231
uint8_t type
Definition: liblwgeom.h:476
double z
Definition: liblwgeom.h:333
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
Definition: g_box.c:295
size_t gserialized_from_lwgeom_size(const LWGEOM *geom)
Calculate required memory segment to contain a serialized form of the LWGEOM.
Definition: g_serialized.c:566
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition: g_box.c:376
int lwgeom_is_closed(const LWGEOM *geom)
Return true or false depending on whether a geometry is a linear feature that closes on itself...
Definition: lwgeom.c:960
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:624
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition: lwtin.c:34
GBOX * bbox
Definition: liblwgeom.h:397
POINT2D getPoint2d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:447
uint8_t flags
Definition: liblwgeom.h:440
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
POINTARRAY * points
Definition: liblwgeom.h:432
char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
Definition: lwpoint.c:246
GBOX * bbox
Definition: liblwgeom.h:465
void printLWPSURFACE(LWPSURFACE *psurf)
Definition: lwpsurface.c:57
int lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition: lwgeom.c:1039
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:2049
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
uint8_t * serialized_pointlist
Definition: liblwgeom.h:365
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1353
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:560
GBOX * bbox
Definition: liblwgeom.h:419
uint8_t variant
Definition: cu_in_twkb.c:26
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:54
void lwmpoly_release(LWMPOLY *lwpoly)
Definition: lwmpoly.c:34
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition: lwin_wkb.c:86
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1004
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:366
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:2061
uint8_t type
Definition: liblwgeom.h:406
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:48
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:669
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:60
int maxgeoms
Definition: liblwgeom.h:494
int lwcollection_ngeoms(const LWCOLLECTION *col)
Definition: lwcollection.c:301
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
LWLINE * lwline_segmentize2d(LWLINE *line, double dist)
Definition: lwline.c:147
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:33
void lwfree(void *mem)
Definition: lwutil.c:242
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:58
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
uint8_t flags
Definition: liblwgeom.h:555
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfyllywithin calculations.
Definition: measures.c:181
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:43
LWGEOM ** rings
Definition: liblwgeom.h:534
int npoints
Definition: liblwgeom.h:370
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:721
struct struct_lwgeom_unparser_result LWGEOM_UNPARSER_RESULT
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: g_box.c:191
uint8_t type
Definition: liblwgeom.h:502
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition: lwgeom_api.c:841
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition: lwgeom_api.c:787
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition: measures3d.c:352
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:113
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
Definition: lwalgorithm.c:460
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:842
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:707
GBOX * bbox
Definition: liblwgeom.h:543
GBOX * bbox
Definition: liblwgeom.h:582
void lwcircstring_free(LWCIRCSTRING *curve)
Definition: lwcircstring.c:98
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition: lwpsurface.c:33
int maxrings
Definition: liblwgeom.h:533
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:56
double next_double_down(float d)
Definition: lwgeom_api.c:188
int32_t srid
Definition: liblwgeom.h:442
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2314
GSERIALIZED * gserialized_copy(const GSERIALIZED *g)
Return a copy of the input serialized geometry.
Definition: g_serialized.c:116
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:1850
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:145
Datum area(PG_FUNCTION_ARGS)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:482
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition: lwgeom.c:709
double b
Definition: liblwgeom.h:313
void lwtin_free(LWTIN *tin)
Definition: lwtin.c:39
uint8_t flags
Definition: liblwgeom.h:396
#define __attribute__(x)
Definition: liblwgeom.h:197
double xmax
Definition: liblwgeom.h:292
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition: lwpoint.c:40
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:243
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition: lwprint.c:424
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition: lwgeom.c:237
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:2729
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:195
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
void printLWTIN(LWTIN *tin)
Definition: lwtin.c:57
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
start location (distance from start / total distance) end location (distance from start / total dist...
Definition: ptarray.c:1058
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:238
LWGEOM * lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it&#39;s 3d)
Definition: ptarray.c:1645
int lwgeom_dimensionality(LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1375
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:167
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:263
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:351
POINTARRAY * ptarray_segmentize2d(const POINTARRAY *ipa, double dist)
Returns a modified POINTARRAY so that no segment is longer than the given distance (computed using 2d...
Definition: ptarray.c:420
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:280
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
int32_t srid
Definition: liblwgeom.h:544
GBOX * bbox
Definition: liblwgeom.h:504
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1755
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:720
double radius
Definition: liblwgeom.h:317
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1477
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
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:835
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:222
void lwtriangle_reverse(LWTRIANGLE *triangle)
Definition: lwtriangle.c:113
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
int lwline_is_trajectory(const LWLINE *geom)
Definition: lwline.c:477
data
Definition: ovdump.py:103
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:88
LWPOINT * lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth)
Calculate the location of a point on a spheroid, give a start point, bearing and distance.
Definition: lwgeodetic.c:2006
GBOX * bbox
Definition: liblwgeom.h:430
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition: lwmpoint.c:124
void printBOX3D(BOX3D *b)
Definition: lwgeom_api.c:605
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition: lwgeom.c:579
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:3002
uint8_t type
Definition: liblwgeom.h:528
LWPOINTITERATOR * lwpointiterator_create_rw(LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM* Supports modification of coordinates during iterat...
Definition: lwiterator.c:253
void lwtriangle_force_clockwise(LWTRIANGLE *triangle)
Definition: lwtriangle.c:106
LWGEOM * lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:60
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:69
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:259
LWPOLY ** geoms
Definition: liblwgeom.h:573
char * hexbytes_from_bytes(uint8_t *bytes, size_t size)
Definition: lwout_wkb.c:39
int getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *point)
Definition: lwgeom_api.c:382
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:251
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
Definition: g_box.c:240
uint8_t flags
Definition: liblwgeom.h:464
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:446
float next_float_down(double d)
Definition: lwgeom_api.c:156
GBOX * bbox
Definition: liblwgeom.h:452
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2315
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:369
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition: lwgeom.c:297
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:133
double zoff
Definition: liblwgeom.h:269
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
int32_t srid
Definition: liblwgeom.h:420
void lwpoly_force_clockwise(LWPOLY *poly)
Definition: lwpoly.c:248
LWGEOM ** geoms
Definition: liblwgeom.h:521
uint8_t flags
Definition: liblwgeom.h:516
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:2895
GBOX * bbox
Definition: liblwgeom.h:517
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
Definition: measures3d.c:94
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:837
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:757
double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2340
POINTARRAY * point
Definition: liblwgeom.h:410
double lwgeom_length_2d(const LWGEOM *geom)
Definition: lwgeom.c:1681
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:398
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:849
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:599
int32_t srid
Definition: liblwgeom.h:398
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:252
void interpolate_point4d(POINT4D *A, POINT4D *B, POINT4D *I, double F)
Find interpolation point I between point A and point B so that the len(AI) == len(AB)*F and I falls o...
Definition: lwgeom_api.c:819
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:380
int ngeoms
Definition: liblwgeom.h:480
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
GBOX * bbox
Definition: liblwgeom.h:556
POINT3DZ getPoint3dz(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:304
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: lwgeom.c:863
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:915
LWGEOM * lwgeom_flip_coordinates(LWGEOM *in)
Reverse the X and Y coordinate order.
Definition: lwgeom.c:1471
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition: g_box.c:91
uint8_t type
Definition: liblwgeom.h:428
double lwgeom_perimeter(const LWGEOM *geom)
Definition: lwgeom.c:1615
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition: lwtriangle.c:120
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:183
void * data
Definition: liblwgeom.h:399
int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
Is the closest point of approach within a distance ?
double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfullywithin calculations.
Definition: measures3d.c:326
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:369
char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2)
check for same geometry composition
Definition: lwcollection.c:261
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:100
int maxgeoms
Definition: liblwgeom.h:546
float next_float_up(double d)
Definition: lwgeom_api.c:172
uint8_t type
Definition: liblwgeom.h:554
LWPOINT * lwpoint_make3dm(int srid, double x, double y, double m)
Definition: lwpoint.c:166
double z
Definition: liblwgeom.h:339
void lwmpoint_release(LWMPOINT *lwpoint)
Definition: lwmpoint.c:33
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
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:665
void(* lwfreeor)(void *mem)
Definition: liblwgeom.h:216
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:173
uint8_t flags
Definition: liblwgeom.h:503
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:1303
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:141
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
Definition: g_box.c:146
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:36
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Utility function to get type number from string.
Definition: g_util.c:163
int ngeoms
Definition: liblwgeom.h:584
LWCOLLECTION * lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset)
Determine the segments along a measured line that fall within the m-range given.
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
uint8_t flags
Definition: liblwgeom.h:477
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
Definition: ptarray.c:509
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
void expand_box3d(BOX3D *box, double d)
Expand given box of &#39;d&#39; units in all directions.
Definition: lwgeom_box3d.c:361
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
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:216
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
Definition: lwhomogenize.c:209
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition: liblwgeom.h:214
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:268
POINT4D getPoint4d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:229
char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2)
Definition: lwcircstring.c:138
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:335
int ptarray_isccw(const POINTARRAY *pa)
Definition: ptarray.c:1026
double f
Definition: liblwgeom.h:314
uint8_t type
Definition: liblwgeom.h:463
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
Definition: lwout_wkb.c:764
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:332
uint8_t type
Definition: liblwgeom.h:541
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:262
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:176
double xmin
Definition: liblwgeom.h:291
LWCIRCSTRING * lwcircstring_construct_empty(int srid, char hasz, char hasm)
Definition: lwcircstring.c:80
LWCURVEPOLY * lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
int32_t srid
Definition: liblwgeom.h:531
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2)
Definition: lwtriangle.c:127
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition: lwgeom.c:200
uint8_t type
Definition: liblwgeom.h:450
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:485
void lwcircstring_release(LWCIRCSTRING *lwcirc)
Definition: lwcircstring.c:92
POINT3DM getPoint3dm(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:318
uint8_t flags
Definition: liblwgeom.h:368
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
GBOX * bbox
Definition: liblwgeom.h:530
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:152
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
Definition: lwgeom_api.c:41
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
Definition: g_serialized.c:58
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:221
LWPOLY ** geoms
Definition: liblwgeom.h:495
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
Definition: liblwgeom.h:1992
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:290
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
Definition: lwpoint.c:47
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:38
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition: lwutil.c:292
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:2820
LWGEOM ** geoms
Definition: liblwgeom.h:508
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1571
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:254
LWTRIANGLE ** geoms
Definition: liblwgeom.h:586
void lwpsurface_release(LWPSURFACE *lwpsurface)
GBOX * gserialized_calculate_gbox_geocentric(const GSERIALIZED *g)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates...
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
uint8_t flags
Definition: liblwgeom.h:490
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:703
uint8_t type
Definition: liblwgeom.h:439
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
GBOX * bbox
Definition: liblwgeom.h:569
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Construct a new POINTARRAY, referencing to the data from ptlist.
Definition: ptarray.c:295
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
Definition: lwout_geojson.c:48
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:717
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition: lwgeom.c:174
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:653
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:188
POINTARRAY ** rings
Definition: liblwgeom.h:456
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1012
double e
Definition: liblwgeom.h:315
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition: lwgeom.c:247
POINTARRAY * ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist)
Construct a new POINTARRAY, copying in the data from ptlist.
Definition: ptarray.c:309
uint8_t precision
Definition: cu_in_twkb.c:25
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition: lwkmeans.c:77
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:155
LWPOINT ** geoms
Definition: liblwgeom.h:469
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:634
double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing max distance calculation.
Definition: measures.c:169
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
LWCURVEPOLY * lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwcurvepoly.c:36
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form...
Definition: g_box.c:451
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:120
int maxgeoms
Definition: liblwgeom.h:572
int nrings
Definition: liblwgeom.h:454
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:39
int32_t srid
Definition: liblwgeom.h:505
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:108
double ymax
Definition: liblwgeom.h:294
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:257
enum LWORD_T LWORD
Ordinate names.
char * s
Definition: cu_in_wkt.c:23
double y
Definition: liblwgeom.h:327
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where)
Insert a point into an existing POINTARRAY.
Definition: ptarray.c:96
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:461
uint8_t flags
Definition: liblwgeom.h:529
void(* lwreporter)(const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:217
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:1820
LWCOLLECTION * lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset)
Given a geometry clip based on the from/to range of one of its ordinates (x, y, z, m).
double e_sq
Definition: liblwgeom.h:316
double z
Definition: liblwgeom.h:351
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:198
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
LWCOMPOUND * lwcompound_construct_from_lwline(const LWLINE *lwpoly)
Construct an equivalent compound curve from a linestring.
Definition: lwcompound.c:204
int point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj)
LWMLINE * lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end)
Re-write the measure ordinate (or add one, if it isn&#39;t already there) interpolating the measure betwe...
Definition: lwmline.c:56
uint8_t type
Definition: liblwgeom.h:580
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:408
Datum distance(PG_FUNCTION_ARGS)
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:64
double y
Definition: liblwgeom.h:345
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:1938
int ngeoms
Definition: liblwgeom.h:493
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:871
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:102
int32_t srid
Definition: liblwgeom.h:409
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:51
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, int maxvertices)
Definition: lwgeom.c:2023
uint8_t flags
Definition: liblwgeom.h:290
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:508
char * gserialized_to_string(const GSERIALIZED *g)
Return a WKT representation of the gserialized geometry.
Definition: g_serialized.c:167
void lwtriangle_free(LWTRIANGLE *triangle)
Definition: lwtriangle.c:69
LWCOLLECTION * lwcollection_segmentize2d(LWCOLLECTION *coll, double dist)
Definition: lwcollection.c:236
void *(* lwreallocator)(void *mem, size_t size)
Definition: liblwgeom.h:215
void lwpsurface_free(LWPSURFACE *psurf)
Definition: lwpsurface.c:39
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:790
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:111
unsigned int geohash_point_as_int(POINT2D *pt)
Definition: lwalgorithm.c:647
int lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition: lwgeom.c:1262
double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist)
Find the time of closest point of approach.
LWPOINT * lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged)
int maxgeoms
Definition: liblwgeom.h:585
LWGEOM * lwgeom_locate_along(const LWGEOM *lwin, double m, double offset)
Determine the location(s) along a measured line where m occurs and return as a multipoint.
int gbox_merge(const GBOX *new_box, GBOX *merged_box)
Update the merged GBOX to be large enough to include itself and the new box.
Definition: g_box.c:269
uint8_t type
Definition: liblwgeom.h:567
GBOX * bbox
Definition: liblwgeom.h:441
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
POINT2D * center
Definition: liblwgeom.h:1621
void lwcollection_release(LWCOLLECTION *lwcollection)
Definition: lwcollection.c:36
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:652
uint8_t flags
Definition: liblwgeom.h:407
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:213
void lwpoly_reverse(LWPOLY *poly)
Definition: lwpoly.c:274
LWLINE ** geoms
Definition: liblwgeom.h:482
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
Definition: ptarray.c:1673
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
Definition: lwgeodetic.c:2487
char lwtriangle_is_repeated_points(LWTRIANGLE *triangle)
Definition: lwtriangle.c:163
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition: lwgeom.c:1637
void lwgeom_reverse(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition: lwgeom.c:64
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
int ngeoms
Definition: liblwgeom.h:558
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:328
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:166
int maxrings
Definition: liblwgeom.h:455
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:95
int maxgeoms
Definition: liblwgeom.h:481
void lwline_reverse(LWLINE *line)
Definition: lwline.c:140
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
Definition: g_box.c:209
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
Definition: lwalgorithm.c:827
GBOX * bbox
Definition: liblwgeom.h:408
int getPoint2d_p_ro(const POINTARRAY *pa, int n, POINT2D **point)
New function to read doubles directly from the double* coordinate array of an aligned lwgeom POINTARR...
Definition: lwgeodetic.c:2473
void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1461
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:847
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, int n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:499
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:611
void ptarray_longitude_shift(POINTARRAY *pa)
Longitude shift for a pointarray.
Definition: ptarray.c:1414
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
double a
Definition: liblwgeom.h:312
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition: lwgeom.c:675
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:1650
LWPOINT * lwpoint_make4d(int srid, double x, double y, double z, double m)
Definition: lwpoint.c:177
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition: lwpoint.c:52
int32_t srid
Definition: liblwgeom.h:453
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:484
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition: lwgeom.c:212
LWMPOINT * lwmpoly_to_points(const LWMPOLY *mpoly, int npoints)
uint32_t size
Definition: liblwgeom.h:380
int maxgeoms
Definition: liblwgeom.h:520
LWGEOM ** geoms
Definition: liblwgeom.h:560
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
LWMPOINT * lwpoly_to_points(const LWPOLY *poly, int npoints)
int ptarray_remove_point(POINTARRAY *pa, int where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:261
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:219
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:156
LWGEOM * lwgeom_from_twkb(uint8_t *twkb, size_t twkb_size, char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_twkb.c:656
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1592
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: g_box.c:199
int lwgeom_dimension(const LWGEOM *geom)
For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension...
Definition: lwgeom.c:1205
double mmin
Definition: liblwgeom.h:297
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
Definition: measures3d.c:795
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:683
int ngeoms
Definition: liblwgeom.h:519
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:445
double zmin
Definition: liblwgeom.h:295
int lwgeom_is_simple(const LWGEOM *lwgeom)
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:879
void(*) typedef void(*) voi lwgeom_set_handlers)(lwallocator allocator, lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, lwreporter noticereporter)
Install custom memory management and error handling functions you want your application to use...
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
double ptarray_arc_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY, using circular arc interpolation between each coordinate ...
Definition: ptarray.c:1618
LWGEOM ** geoms
Definition: liblwgeom.h:547
double lwgeom_length(const LWGEOM *geom)
Definition: lwgeom.c:1659
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
LWGEOM * lwgeom_segmentize2d(LWGEOM *line, double dist)
Definition: lwgeom.c:681
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:139
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:165
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:612
void printLWPOINT(LWPOINT *point)
Definition: lwpoint.c:206
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing min distance calculation.
Definition: measures.c:202
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, int npoints)
const POINT4D * getPoint4d_cp(const POINTARRAY *pa, int n)
Returns a POINT4D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:520
void ptarray_reverse(POINTARRAY *pa)
Definition: ptarray.c:343
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition: lwgeom.c:192
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:547
int32_t srid
Definition: liblwgeom.h:557
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:385
LWPOINT * lwline_get_lwpoint(const LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:324
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:51
uint8_t type
Definition: liblwgeom.h:395
type
Definition: ovdump.py:41
uint8_t type
Definition: liblwgeom.h:515
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: g_serialized.c:53
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:73
double mmax
Definition: liblwgeom.h:298
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:339
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition: lwutil.c:210
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition: lwgeom.c:207
POINTARRAY * points
Definition: liblwgeom.h:443
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:98
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:715
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:1488
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Remove repeated points!
Definition: lwgeom.c:1420
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:242
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:227
int maxgeoms
Definition: liblwgeom.h:468
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:2092
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2325
LWORD_T
Ordinate names.
Definition: liblwgeom.h:112
int maxpoints
Definition: liblwgeom.h:371
int value
Definition: genraster.py:61
uint8_t flags
Definition: liblwgeom.h:451
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:337
LWPOLY * lwpoly_segmentize2d(LWPOLY *line, double dist)
Definition: lwpoly.c:283
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:562
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:736
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:111
void * lwalloc(size_t size)
Definition: lwutil.c:227
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:1310
uint8_t flags
Definition: liblwgeom.h:581
void lwmline_release(LWMLINE *lwline)
Definition: lwmline.c:32
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:342
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1153
LWGEOM * lwgeom_unstroke(const LWGEOM *geom)
Definition: lwstroke.c:858
GBOX * bbox
Definition: liblwgeom.h:491
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_wkb.c:765
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where)
Definition: lwcompound.c:213
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
Definition: g_box.c:126
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2389
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:933
int ngeoms
Definition: liblwgeom.h:467
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:63
uint8_t flags
Definition: liblwgeom.h:418
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2425
int32_t srid
Definition: liblwgeom.h:570
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:608
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:363
void lwline_release(LWLINE *lwline)
Definition: lwline.c:134
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:43
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:158
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
Definition: lwpoly.c:307
int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
int ngeoms
Definition: liblwgeom.h:571
int32_t srid
Definition: liblwgeom.h:466
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:856
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1116
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:217
char lwline_same(const LWLINE *p1, const LWLINE *p2)
Definition: lwline.c:156
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:47
int lwpointiterator_peek(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assigns the next point in the iterator to p.
Definition: lwiterator.c:195
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:83
int32_t srid
Definition: liblwgeom.h:583
int gserialized_calculate_gbox_geocentric_p(const GSERIALIZED *g, GBOX *g_box)
Calculate the geocentric bounding box directly from the serialized form of the geodetic coordinates...
int32_t srid
Definition: liblwgeom.h:492
int maxgeoms
Definition: liblwgeom.h:559
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, int where)
Definition: lwcircstring.c:300
int32_t srid
Definition: liblwgeom.h:431
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:404
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
GBOX * bbox
Definition: liblwgeom.h:478
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition: lwcompound.c:88
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:680
uint8_t type
Definition: liblwgeom.h:489
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:244
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1704
double next_double_up(float d)
Definition: lwgeom_api.c:203
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:43
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
uint8_t flags
Definition: liblwgeom.h:382
double zmax
Definition: liblwgeom.h:277
int32_t srid
Definition: liblwgeom.h:479
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition: lwtriangle.c:82
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
uint8_t flags
Definition: liblwgeom.h:429
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:83
POINTARRAY * points
Definition: liblwgeom.h:421
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:526
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:232
double zmin
Definition: liblwgeom.h:276
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:227
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition: ptarray.c:603