PostGIS  2.1.10dev-r@@SVN_REVISION@@
liblwgeom.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: liblwgeom.h.in 13391 2015-03-23 16:34:30Z strk $
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  *
6  * Copyright 2011 Sandro Santilli <strk@keybit.net>
7  * Copyright 2011 Paul Ramsey <pramsey@cleverelephant.ca>
8  * Copyright 2007-2008 Mark Cave-Ayland
9  * Copyright 2001-2006 Refractions Research Inc.
10  *
11  * This is free software; you can redistribute and/or modify it under
12  * the terms of the GNU General Public Licence. See the COPYING file.
13  *
14  **********************************************************************/
15 
16 #ifndef _LIBLWGEOM_H
17 #define _LIBLWGEOM_H 1
18 
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include "proj_api.h"
23 
43 #define LIBLWGEOM_VERSION "2.1.10dev"
44 #define LIBLWGEOM_VERSION_MAJOR "2"
45 #define LIBLWGEOM_VERSION_MINOR "1"
46 #define LIBLWGEOM_GEOS_VERSION "34"
47 
51 #define LW_TRUE 1
52 #define LW_FALSE 0
53 #define LW_UNKNOWN 2
54 #define LW_FAILURE 0
55 #define LW_SUCCESS 1
56 
60 #define POINTTYPE 1
61 #define LINETYPE 2
62 #define POLYGONTYPE 3
63 #define MULTIPOINTTYPE 4
64 #define MULTILINETYPE 5
65 #define MULTIPOLYGONTYPE 6
66 #define COLLECTIONTYPE 7
67 #define CIRCSTRINGTYPE 8
68 #define COMPOUNDTYPE 9
69 #define CURVEPOLYTYPE 10
70 #define MULTICURVETYPE 11
71 #define MULTISURFACETYPE 12
72 #define POLYHEDRALSURFACETYPE 13
73 #define TRIANGLETYPE 14
74 #define TINTYPE 15
75 
76 #define NUMTYPES 16
77 
82 #define WKBZOFFSET 0x80000000
83 #define WKBMOFFSET 0x40000000
84 #define WKBSRIDFLAG 0x20000000
85 #define WKBBBOXFLAG 0x10000000
86 
87 /**********************************************************************
88 ** Spherical radius.
89 ** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
90 ** the XVII General Assembly of the IUGG in Canberra.
91 ** http://en.wikipedia.org/wiki/Earth_radius
92 ** http://en.wikipedia.org/wiki/World_Geodetic_System
93 */
94 
95 #define WGS84_MAJOR_AXIS 6378137.0
96 #define WGS84_INVERSE_FLATTENING 298.257223563
97 #define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
98 #define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
99 
100 
106 #define FLAGS_GET_Z(flags) ((flags) & 0x01)
107 #define FLAGS_GET_M(flags) (((flags) & 0x02)>>1)
108 #define FLAGS_GET_BBOX(flags) (((flags) & 0x04)>>2)
109 #define FLAGS_GET_GEODETIC(flags) (((flags) & 0x08)>>3)
110 #define FLAGS_GET_READONLY(flags) (((flags) & 0x10)>>4)
111 #define FLAGS_GET_SOLID(flags) (((flags) & 0x20)>>5)
112 #define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | 0x01) : ((flags) & 0xFE))
113 #define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | 0x02) : ((flags) & 0xFD))
114 #define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | 0x04) : ((flags) & 0xFB))
115 #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | 0x08) : ((flags) & 0xF7))
116 #define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | 0x10) : ((flags) & 0xEF))
117 #define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | 0x20) : ((flags) & 0xDF))
118 #define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
119 #define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
120 #define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
121 
131 #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x1FFFFF00)<<3)>>11)
132 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
133 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
134 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
135 #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
136 #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
137 #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
138 #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
139 #define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
140 
145 #define SRID_MAXIMUM 999999
146 
151 #define SRID_USER_MAXIMUM 998999
152 
154 #define SRID_UNKNOWN 0
155 #define SRID_IS_UNKNOWN(x) ((int)x<=0)
156 
157 /*
158 ** EPSG WGS84 geographics, OGC standard default SRS, better be in
159 ** the SPATIAL_REF_SYS table!
160 */
161 #define SRID_DEFAULT 4326
162 
169 extern int clamp_srid(int srid);
170 
171 
175 typedef void* (*lwallocator)(size_t size);
176 typedef void* (*lwreallocator)(void *mem, size_t size);
177 typedef void (*lwfreeor)(void* mem);
178 typedef void (*lwreporter)(const char* fmt, va_list ap);
179 
186 extern void lwgeom_set_handlers(lwallocator allocator,
187  lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
188  lwreporter noticereporter);
189 
198 void lwnotice(const char *fmt, ...);
199 
208 void lwerror(const char *fmt, ...);
209 
210 
211 /* TODO: move these elsewhere */
212 extern int lw_vasprintf (char **result, const char *format, va_list args);
213 extern int lw_asprintf
214 #if __STDC__
215 (char **result, const char *format, ...);
216 #else
217 (result, va_alist);
218 char **result;
219 va_dcl
220 #endif
221 
222 
223 /******************************************************************/
224 
225 typedef struct {
226  double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
227 } AFFINE;
228 
229 /******************************************************************/
230 
231 typedef struct
232 {
233  double xmin, ymin, zmin;
234  double xmax, ymax, zmax;
235  int32_t srid;
236 }
237 BOX3D;
238 
239 /******************************************************************
240 * GBOX structure.
241 * We include the flags (information about dimensinality),
242 * so we don't have to constantly pass them
243 * into functions that use the GBOX.
244 */
245 typedef struct
246 {
247  uint8_t flags;
248  double xmin;
249  double xmax;
250  double ymin;
251  double ymax;
252  double zmin;
253  double zmax;
254  double mmin;
255  double mmax;
256 } GBOX;
257 
258 
259 /******************************************************************
260 * SPHEROID
261 *
262 * Standard definition of an ellipsoid (what wkt calls a spheroid)
263 * f = (a-b)/a
264 * e_sq = (a*a - b*b)/(a*a)
265 * b = a - fa
266 */
267 typedef struct
268 {
269  double a; /* semimajor axis */
270  double b; /* semiminor axis b = (a - fa) */
271  double f; /* flattening f = (a-b)/a */
272  double e; /* eccentricity (first) */
273  double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
274  double radius; /* spherical average radius = (2*a+b)/3 */
275  char name[20]; /* name of ellipse */
276 }
277 SPHEROID;
278 
279 /******************************************************************
280 * POINT2D, POINT3D, POINT3DM, POINT4D
281 */
282 typedef struct
283 {
284  double x, y;
285 }
286 POINT2D;
287 
288 typedef struct
289 {
290  double x, y, z;
291 }
292 POINT3DZ;
293 
294 typedef struct
295 {
296  double x, y, z;
297 }
298 POINT3D;
299 
300 typedef struct
301 {
302  double x, y, m;
303 }
304 POINT3DM;
305 
306 typedef struct
307 {
308  double x, y, z, m;
309 }
310 POINT4D;
311 
312 /******************************************************************
313 * POINTARRAY
314 * Point array abstracts a lot of the complexity of points and point lists.
315 * It handles 2d/3d translation
316 * (2d points converted to 3d will have z=0 or NaN)
317 * DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
318 */
319 typedef struct
320 {
321  /* Array of POINT 2D, 3D or 4D, possibly missaligned. */
323 
324  /* Use FLAGS_* macros to handle */
325  uint8_t flags;
326 
327  int npoints; /* how many points we are currently storing */
328  int maxpoints; /* how many points we have space for in serialized_pointlist */
329 }
330 POINTARRAY;
331 
332 /******************************************************************
333 * GSERIALIZED
334 */
335 typedef struct
336 {
337  uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
338  uint8_t srid[3]; /* 24 bits of SRID */
339  uint8_t flags; /* HasZ, HasM, HasBBox, IsGeodetic, IsReadOnly */
340  uint8_t data[1]; /* See gserialized.txt */
341 } GSERIALIZED;
342 
343 
344 /******************************************************************
345 * LWGEOM (any geometry type)
346 *
347 * Abstract type, note that 'type', 'bbox' and 'srid' are available in
348 * all geometry variants.
349 */
350 typedef struct
351 {
352  uint8_t type;
353  uint8_t flags;
355  int32_t srid;
356  void *data;
357 }
358 LWGEOM;
359 
360 /* POINTYPE */
361 typedef struct
362 {
363  uint8_t type; /* POINTTYPE */
364  uint8_t flags;
366  int32_t srid;
367  POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
368 }
369 LWPOINT; /* "light-weight point" */
370 
371 /* LINETYPE */
372 typedef struct
373 {
374  uint8_t type; /* LINETYPE */
375  uint8_t flags;
377  int32_t srid;
378  POINTARRAY *points; /* array of POINT3D */
379 }
380 LWLINE; /* "light-weight line" */
381 
382 /* TRIANGLE */
383 typedef struct
384 {
385  uint8_t type;
386  uint8_t flags;
388  int32_t srid;
390 }
391 LWTRIANGLE;
392 
393 /* CIRCSTRINGTYPE */
394 typedef struct
395 {
396  uint8_t type; /* CIRCSTRINGTYPE */
397  uint8_t flags;
399  int32_t srid;
400  POINTARRAY *points; /* array of POINT(3D/3DM) */
401 }
402 LWCIRCSTRING; /* "light-weight circularstring" */
403 
404 /* POLYGONTYPE */
405 typedef struct
406 {
407  uint8_t type; /* POLYGONTYPE */
408  uint8_t flags;
410  int32_t srid;
411  int nrings; /* how many rings we are currently storing */
412  int maxrings; /* how many rings we have space for in **rings */
413  POINTARRAY **rings; /* list of rings (list of points) */
414 }
415 LWPOLY; /* "light-weight polygon" */
416 
417 /* MULTIPOINTTYPE */
418 typedef struct
419 {
420  uint8_t type;
421  uint8_t flags;
423  int32_t srid;
424  int ngeoms; /* how many geometries we are currently storing */
425  int maxgeoms; /* how many geometries we have space for in **geoms */
427 }
428 LWMPOINT;
429 
430 /* MULTILINETYPE */
431 typedef struct
432 {
433  uint8_t type;
434  uint8_t flags;
436  int32_t srid;
437  int ngeoms; /* how many geometries we are currently storing */
438  int maxgeoms; /* how many geometries we have space for in **geoms */
440 }
441 LWMLINE;
442 
443 /* MULTIPOLYGONTYPE */
444 typedef struct
445 {
446  uint8_t type;
447  uint8_t flags;
449  int32_t srid;
450  int ngeoms; /* how many geometries we are currently storing */
451  int maxgeoms; /* how many geometries we have space for in **geoms */
453 }
454 LWMPOLY;
455 
456 /* COLLECTIONTYPE */
457 typedef struct
458 {
459  uint8_t type;
460  uint8_t flags;
462  int32_t srid;
463  int ngeoms; /* how many geometries we are currently storing */
464  int maxgeoms; /* how many geometries we have space for in **geoms */
466 }
468 
469 /* COMPOUNDTYPE */
470 typedef struct
471 {
472  uint8_t type; /* COMPOUNDTYPE */
473  uint8_t flags;
475  int32_t srid;
476  int ngeoms; /* how many geometries we are currently storing */
477  int maxgeoms; /* how many geometries we have space for in **geoms */
479 }
480 LWCOMPOUND; /* "light-weight compound line" */
481 
482 /* CURVEPOLYTYPE */
483 typedef struct
484 {
485  uint8_t type; /* CURVEPOLYTYPE */
486  uint8_t flags;
488  int32_t srid;
489  int nrings; /* how many rings we are currently storing */
490  int maxrings; /* how many rings we have space for in **rings */
491  LWGEOM **rings; /* list of rings (list of points) */
492 }
493 LWCURVEPOLY; /* "light-weight polygon" */
494 
495 /* MULTICURVE */
496 typedef struct
497 {
498  uint8_t type;
499  uint8_t flags;
501  int32_t srid;
502  int ngeoms; /* how many geometries we are currently storing */
503  int maxgeoms; /* how many geometries we have space for in **geoms */
505 }
506 LWMCURVE;
507 
508 /* MULTISURFACETYPE */
509 typedef struct
510 {
511  uint8_t type;
512  uint8_t flags;
514  int32_t srid;
515  int ngeoms; /* how many geometries we are currently storing */
516  int maxgeoms; /* how many geometries we have space for in **geoms */
518 }
519 LWMSURFACE;
520 
521 /* POLYHEDRALSURFACETYPE */
522 typedef struct
523 {
524  uint8_t type;
525  uint8_t flags;
527  int32_t srid;
528  int ngeoms; /* how many geometries we are currently storing */
529  int maxgeoms; /* how many geometries we have space for in **geoms */
531 }
532 LWPSURFACE;
533 
534 /* TINTYPE */
535 typedef struct
536 {
537  uint8_t type;
538  uint8_t flags;
540  int32_t srid;
541  int ngeoms; /* how many geometries we are currently storing */
542  int maxgeoms; /* how many geometries we have space for in **geoms */
544 }
545 LWTIN;
546 
547 /* Casts LWGEOM->LW* (return NULL if cast is illegal) */
548 extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
549 extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
550 extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
551 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
552 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
553 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
554 extern LWPOINT *lwgeom_as_lwpoint(const LWGEOM *lwgeom);
555 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
556 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
557 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
558 extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
559 extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
560 extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
561 extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
562 
563 /* Casts LW*->LWGEOM (always cast) */
564 extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
565 extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
566 extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
567 extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
568 extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
569 extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
570 extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
571 extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
572 extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
573 extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
574 extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
575 extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
576 extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
577 
578 
579 extern LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom);
580 extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
581 extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
582 extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
583 extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
584 extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
585 
586 
587 
588 /***********************************************************************
589 ** Utility functions for flag byte and srid_flag integer.
590 */
591 
595 extern uint8_t gflags(int hasz, int hasm, int geodetic);
596 
601 extern uint32_t gserialized_get_type(const GSERIALIZED *g);
602 
607 extern uint32_t gserialized_max_header_size(void);
608 
613 extern int32_t gserialized_get_srid(const GSERIALIZED *g);
614 
619 extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
620 
627 extern int gserialized_is_empty(const GSERIALIZED *g);
628 
632 extern int gserialized_has_bbox(const GSERIALIZED *gser);
633 
637 extern int gserialized_has_z(const GSERIALIZED *gser);
638 
642 extern int gserialized_has_m(const GSERIALIZED *gser);
643 
647 extern int gserialized_is_geodetic(const GSERIALIZED *gser);
648 
653 extern int gserialized_get_zm(const GSERIALIZED *gser);
654 
658 extern int gserialized_ndims(const GSERIALIZED *gser);
659 
660 
667 extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
668 extern void lwgeom_drop_srid(LWGEOM *lwgeom);
669 
676 extern void lwgeom_add_bbox(LWGEOM *lwgeom);
680 extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
681 
689 extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
690 
694 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
695 
696 /******************************************************************/
697 /* Functions that work on type numbers */
698 
702 extern int lwtype_is_collection(uint8_t type);
703 
707 extern int lwtype_get_collectiontype(uint8_t type);
708 
713 extern const char *lwtype_name(uint8_t type);
714 
715 
716 /******************************************************************/
717 
718 /*
719  * copies a point from the point array into the parameter point
720  * will set point's z=0 (or NaN) if pa is 2d
721  * will set point's m=0 (or NaN) if pa is 3d or 2d
722  * NOTE: point is a real POINT3D *not* a pointer
723  */
724 extern POINT4D getPoint4d(const POINTARRAY *pa, int n);
725 
726 /*
727  * copies a point from the point array into the parameter point
728  * will set point's z=0 (or NaN) if pa is 2d
729  * will set point's m=0 (or NaN) if pa is 3d or 2d
730  * NOTE: this will modify the point4d pointed to by 'point'.
731  */
732 extern int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point);
733 
734 /*
735  * copies a point from the point array into the parameter point
736  * will set point's z=0 (or NaN) if pa is 2d
737  * NOTE: point is a real POINT3D *not* a pointer
738  */
739 extern POINT3DZ getPoint3dz(const POINTARRAY *pa, int n);
740 extern POINT3DM getPoint3dm(const POINTARRAY *pa, int n);
741 
742 /*
743  * copies a point from the point array into the parameter point
744  * will set point's z=0 (or NaN) if pa is 2d
745  * NOTE: this will modify the point3d pointed to by 'point'.
746  */
747 extern int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point);
748 extern int getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *point);
749 
750 
751 /*
752  * copies a point from the point array into the parameter point
753  * z value (if present is not returned)
754  * NOTE: point is a real POINT3D *not* a pointer
755  */
756 extern POINT2D getPoint2d(const POINTARRAY *pa, int n);
757 
758 /*
759  * copies a point from the point array into the parameter point
760  * z value (if present is not returned)
761  * NOTE: this will modify the point2d pointed to by 'point'.
762  */
763 extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point);
764 
771 extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, int n);
772 
779 extern const POINT3DZ* getPoint3dz_cp(const POINTARRAY *pa, int n);
780 
781 /*
782  * set point N to the given value
783  * NOTE that the pointarray can be of any
784  * dimension, the appropriate ordinate values
785  * will be extracted from it
786  *
787  * N must be a valid point index
788  */
789 extern void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d);
790 
791 /*
792  * get a pointer to nth point of a POINTARRAY
793  * You'll need to cast it to appropriate dimensioned point.
794  * Note that if you cast to a higher dimensional point you'll
795  * possibly corrupt the POINTARRAY.
796  *
797  * WARNING: Don't cast this to a POINT !
798  * it would not be reliable due to memory alignment constraints
799  */
800 extern uint8_t *getPoint_internal(const POINTARRAY *pa, int n);
801 
802 /*
803  * size of point represeneted in the POINTARRAY
804  * 16 for 2d, 24 for 3d, 32 for 4d
805  */
806 extern int ptarray_point_size(const POINTARRAY *pa);
807 
808 
814 extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
815 
819 extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
820 
824 extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
825 
831 extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
832 
838 extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
839 
851 extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
852 
857 extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where);
858 
863 extern int ptarray_remove_point(POINTARRAY *pa, int where);
864 
865 extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
866 extern POINTARRAY *ptarray_removePoint(POINTARRAY *pa, uint32_t where);
867 extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
868 extern int ptarray_is_closed(const POINTARRAY *pa);
869 extern int ptarray_is_closed_2d(const POINTARRAY *pa);
870 extern int ptarray_is_closed_3d(const POINTARRAY *pa);
871 extern int ptarray_is_closed_z(const POINTARRAY *pa);
872 extern void ptarray_longitude_shift(POINTARRAY *pa);
873 extern void ptarray_reverse(POINTARRAY *pa);
875 
881 extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
882  double tolerance);
883 
884 
888 extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
889 extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
890 extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
891 extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
892 
893 extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist);
894 
895 /*
896  * Force to use SFS 1.1 geometry type
897  * (rather than SFS 1.2 and/or SQL/MM)
898  */
899 extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
900 
901 
902 /*--------------------------------------------------------
903  * all the base types (point/line/polygon) will have a
904  * basic constructor, basic de-serializer, basic serializer,
905  * bounding box finder and (TODO) serialized form size finder.
906  *--------------------------------------------------------*/
907 
908 /*
909  * convenience functions to hide the POINTARRAY
910  */
911 extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
912 extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
913 extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
914 extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
915 
916 /******************************************************************
917  * LWLINE functions
918  ******************************************************************/
919 
923 extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where);
924 
925 /******************************************************************
926  * LWPOLY functions
927  ******************************************************************/
928 
933 extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
934 
939 extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
940 
945 extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
946 
952 
953 
954 /******************************************************************
955  * LWGEOM functions
956  ******************************************************************/
957 
958 extern int lwcollection_ngeoms(const LWCOLLECTION *col);
959 
960 /* Given a generic geometry/collection, return the "simplest" form. */
961 extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
962 
963 
964 /******************************************************************
965  * LWMULTIx and LWCOLLECTION functions
966  ******************************************************************/
967 
970 
971 
972 /******************************************************************
973  * SERIALIZED FORM functions
974  ******************************************************************/
975 
981 extern void lwgeom_set_srid(LWGEOM *geom, int srid);
982 
983 /*------------------------------------------------------
984  * other stuff
985  *
986  * handle the double-to-float conversion. The results of this
987  * will usually be a slightly bigger box because of the difference
988  * between float8 and float4 representations.
989  */
990 
991 extern BOX3D* box3d_from_gbox(const GBOX *gbox);
992 extern GBOX* box3d_to_gbox(const BOX3D *b3d);
993 
994 void expand_box3d(BOX3D *box, double d);
995 
996 
997 /****************************************************************
998  * MEMORY MANAGEMENT
999  ****************************************************************/
1000 
1001 /*
1002 * The *_free family of functions frees *all* memory associated
1003 * with the pointer. When the recursion gets to the level of the
1004 * POINTARRAY, the POINTARRAY is only freed if it is not flagged
1005 * as "read only". LWGEOMs constructed on top of GSERIALIZED
1006 * from PgSQL use read only point arrays.
1007 */
1008 
1009 extern void ptarray_free(POINTARRAY *pa);
1010 extern void lwpoint_free(LWPOINT *pt);
1011 extern void lwline_free(LWLINE *line);
1012 extern void lwpoly_free(LWPOLY *poly);
1013 extern void lwtriangle_free(LWTRIANGLE *triangle);
1014 extern void lwmpoint_free(LWMPOINT *mpt);
1015 extern void lwmline_free(LWMLINE *mline);
1016 extern void lwmpoly_free(LWMPOLY *mpoly);
1017 extern void lwpsurface_free(LWPSURFACE *psurf);
1018 extern void lwtin_free(LWTIN *tin);
1019 extern void lwcollection_free(LWCOLLECTION *col);
1020 extern void lwcircstring_free(LWCIRCSTRING *curve);
1021 extern void lwgeom_free(LWGEOM *geom);
1022 
1023 /*
1024 * The *_release family of functions frees the LWGEOM structures
1025 * surrounding the POINTARRAYs but leaves the POINTARRAYs
1026 * intact. Useful when re-shaping geometries between types,
1027 * or splicing geometries together.
1028 */
1029 
1030 extern void lwpoint_release(LWPOINT *lwpoint);
1031 extern void lwline_release(LWLINE *lwline);
1032 extern void lwpoly_release(LWPOLY *lwpoly);
1033 extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1034 extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1035 extern void lwmpoint_release(LWMPOINT *lwpoint);
1036 extern void lwmline_release(LWMLINE *lwline);
1037 extern void lwmpoly_release(LWMPOLY *lwpoly);
1038 extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1039 extern void lwtin_release(LWTIN *lwtin);
1040 extern void lwcollection_release(LWCOLLECTION *lwcollection);
1041 extern void lwgeom_release(LWGEOM *lwgeom);
1042 
1043 
1044 /****************************************************************
1045 * Utility
1046 ****************************************************************/
1047 
1048 extern void printBOX3D(BOX3D *b);
1049 extern void printPA(POINTARRAY *pa);
1050 extern void printLWPOINT(LWPOINT *point);
1051 extern void printLWLINE(LWLINE *line);
1052 extern void printLWPOLY(LWPOLY *poly);
1053 extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1054 extern void printLWPSURFACE(LWPSURFACE *psurf);
1055 extern void printLWTIN(LWTIN *tin);
1056 
1057 extern float next_float_down(double d);
1058 extern float next_float_up(double d);
1059 extern double next_double_down(float d);
1060 extern double next_double_up(float d);
1061 
1062 /* general utilities
1063  2D*/
1064 extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1065 extern double distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1066 extern double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2);
1067 extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1068 extern LWGEOM *lw_dist2d_distancepoint(LWGEOM *lw1, LWGEOM *lw2,int srid,int mode);
1069 extern LWGEOM *lw_dist2d_distanceline(LWGEOM *lw1, LWGEOM *lw2,int srid,int mode);
1070 extern double lwgeom_mindistance2d(LWGEOM *lw1, LWGEOM *lw2);
1071 extern double lwgeom_mindistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance);
1072 extern double lwgeom_maxdistance2d(LWGEOM *lw1, LWGEOM *lw2);
1073 extern double lwgeom_maxdistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance);
1074 /*
1075  3D*/
1076 extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1077 extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1078 extern LWGEOM *lw_dist3d_distancepoint(LWGEOM *lw1, LWGEOM *lw2,int srid,int mode);
1079 extern LWGEOM *lw_dist3d_distanceline(LWGEOM *lw1, LWGEOM *lw2,int srid,int mode);
1080 extern double lwgeom_mindistance3d(LWGEOM *lw1, LWGEOM *lw2);
1081 extern double lwgeom_mindistance3d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance);
1082 extern double lwgeom_maxdistance3d(LWGEOM *lw1, LWGEOM *lw2);
1083 extern double lwgeom_maxdistance3d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance);
1084 
1085 
1086 extern double lwgeom_area(const LWGEOM *geom);
1087 extern double lwgeom_length(const LWGEOM *geom);
1088 extern double lwgeom_length_2d(const LWGEOM *geom);
1089 extern double lwgeom_perimeter(const LWGEOM *geom);
1090 extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1091 extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1092 extern int lwgeom_dimension(const LWGEOM *geom);
1093 
1094 extern LWPOINT* lwline_get_lwpoint(LWLINE *line, int where);
1095 extern LWPOINT* lwcircstring_get_lwpoint(LWCIRCSTRING *circ, int where);
1096 
1097 extern double ptarray_length_2d(const POINTARRAY *pts);
1098 extern double ptarray_length(const POINTARRAY *pts);
1099 extern double ptarray_arc_length_2d(const POINTARRAY *pts);
1100 
1101 
1102 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1103 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1104 extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1105 extern void lwgeom_reverse(LWGEOM *lwgeom);
1106 extern void lwline_reverse(LWLINE *line);
1107 extern void lwpoly_reverse(LWPOLY *poly);
1108 extern void lwtriangle_reverse(LWTRIANGLE *triangle);
1109 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1110 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1111 extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1112 
1117 extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1118 extern void lwpoly_force_clockwise(LWPOLY *poly);
1119 extern void lwtriangle_force_clockwise(LWTRIANGLE *triangle);
1120 
1121 
1122 extern void interpolate_point4d(POINT4D *A, POINT4D *B, POINT4D *I, double F);
1123 
1124 void lwgeom_longitude_shift(LWGEOM *lwgeom);
1125 
1126 
1136 extern int lwgeom_needs_bbox(const LWGEOM *geom);
1137 
1141 extern int lwgeom_count_vertices(const LWGEOM *geom);
1142 
1147 extern int lwgeom_count_rings(const LWGEOM *geom);
1148 
1153 extern int lwgeom_has_srid(const LWGEOM *geom);
1154 
1159 extern int lwgeom_is_empty(const LWGEOM *geom);
1160 
1165 extern int lwgeom_is_closed(const LWGEOM *geom);
1166 
1170 extern int lwgeom_dimensionality(LWGEOM *geom);
1171 
1172 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
1173 char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1174 char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2);
1175 char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2);
1176 char lwline_same(const LWLINE *p1, const LWLINE *p2);
1177 char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2);
1178 char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2);
1179 char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2);
1180 char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2);
1181 
1182 
1190 extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1191 
1195 extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1196 
1197 /* TODO Move to Internal */
1198 LWPOINT *lwpoint_clone(const LWPOINT *lwgeom);
1199 POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1200 
1201 
1202 /*
1203 * Geometry constructors. These constructors to not copy the point arrays
1204 * passed to them, they just take references, so do not free them out
1205 * from underneath the geometries.
1206 */
1207 extern LWPOINT* lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point);
1208 extern LWMPOINT *lwmpoint_construct(int srid, const POINTARRAY *pa);
1209 extern LWLINE* lwline_construct(int srid, GBOX *bbox, POINTARRAY *points);
1210 extern LWCIRCSTRING* lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points);
1211 extern LWPOLY* lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1212 extern LWCURVEPOLY* lwcurvepoly_construct(int srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1213 extern LWTRIANGLE* lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points);
1214 extern LWCOLLECTION* lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1215 /*
1216 * Empty geometry constructors.
1217 */
1218 extern LWGEOM* lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1219 extern LWPOINT* lwpoint_construct_empty(int srid, char hasz, char hasm);
1220 extern LWLINE* lwline_construct_empty(int srid, char hasz, char hasm);
1221 extern LWPOLY* lwpoly_construct_empty(int srid, char hasz, char hasm);
1222 extern LWCURVEPOLY* lwcurvepoly_construct_empty(int srid, char hasz, char hasm);
1223 extern LWCIRCSTRING* lwcircstring_construct_empty(int srid, char hasz, char hasm);
1224 extern LWCOMPOUND* lwcompound_construct_empty(int srid, char hasz, char hasm);
1225 extern LWTRIANGLE* lwtriangle_construct_empty(int srid, char hasz, char hasm);
1226 extern LWMPOINT* lwmpoint_construct_empty(int srid, char hasz, char hasm);
1227 extern LWMLINE* lwmline_construct_empty(int srid, char hasz, char hasm);
1228 extern LWMPOLY* lwmpoly_construct_empty(int srid, char hasz, char hasm);
1229 extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm);
1230 
1231 
1232 /* Other constructors */
1233 extern LWPOINT *lwpoint_make2d(int srid, double x, double y);
1234 extern LWPOINT *lwpoint_make3dz(int srid, double x, double y, double z);
1235 extern LWPOINT *lwpoint_make3dm(int srid, double x, double y, double m);
1236 extern LWPOINT *lwpoint_make4d(int srid, double x, double y, double z, double m);
1237 extern LWPOINT *lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p);
1238 extern LWLINE *lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms);
1239 extern LWLINE *lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1240 extern LWLINE *lwline_from_lwmpoint(int srid, LWMPOINT *mpoint);
1241 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1242 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1243 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1244 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1245 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1246 
1247 
1248 /* Some point accessors */
1249 extern double lwpoint_get_x(const LWPOINT *point);
1250 extern double lwpoint_get_y(const LWPOINT *point);
1251 extern double lwpoint_get_z(const LWPOINT *point);
1252 extern double lwpoint_get_m(const LWPOINT *point);
1253 
1257 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1258 
1262 extern uint32_t lwgeom_get_type(const LWGEOM *geom);
1263 
1267 extern int lwgeom_has_z(const LWGEOM *geom);
1268 
1272 extern int lwgeom_has_m(const LWGEOM *geom);
1273 
1277 extern int lwgeom_ndims(const LWGEOM *geom);
1278 
1279 /*
1280  * Given a point, returns the location of closest point on pointarray
1281  * as a fraction of total length (0: first point -- 1: last point).
1282  *
1283  * If not-null, the third argument will be set to the actual distance
1284  * of the point from the pointarray.
1285  */
1286 extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1287 
1292 extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1293 extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1294 
1299 extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1300 
1306 extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1307 
1311 extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1312 
1313 /*
1314  * Ensure every segment is at most 'dist' long.
1315  * Returned LWGEOM might is unchanged if a POINT.
1316  */
1317 extern LWGEOM *lwgeom_segmentize2d(LWGEOM *line, double dist);
1318 extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1319 extern LWLINE *lwline_segmentize2d(LWLINE *line, double dist);
1320 extern LWPOLY *lwpoly_segmentize2d(LWPOLY *line, double dist);
1321 extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist);
1322 
1326 char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1327 unsigned int geohash_point_as_int(POINT2D *pt);
1328 
1329 
1341 };
1342 
1346 int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1347 
1351 LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1352 
1358 #define LW_GML_IS_DIMS (1<<0)
1359 
1360 #define LW_GML_IS_DEGREE (1<<1)
1361 
1362 #define LW_GML_SHORTLINE (1<<2)
1363 
1364 #define LW_GML_EXTENT (1<<4)
1365 
1366 
1367 #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1368 #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1369 
1371 extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1372 extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1376 extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1377 extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1378 extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1379 extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1380 extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1381 extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1382 
1392 extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1393 
1397 extern void spheroid_init(SPHEROID *s, double a, double b);
1398 
1404 extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1405 
1409 extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1410 
1415 extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1416 
1420 extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1421 
1426 extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1427 
1432 extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1433 
1438 extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1439 
1444 extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1445 
1450 
1451 extern char lwtriangle_is_repeated_points(LWTRIANGLE *triangle);
1452 
1458 
1462 extern uint8_t parse_hex(char *str);
1463 
1467 extern void deparse_hex(uint8_t str, char *result);
1468 
1469 
1470 
1471 /***********************************************************************
1472 ** Functions for managing serialized forms and bounding boxes.
1473 */
1474 
1481 
1488 
1493 extern char* gserialized_to_string(const GSERIALIZED *g);
1494 
1498 extern GSERIALIZED* gserialized_copy(const GSERIALIZED *g);
1499 
1503 extern int lwgeom_check_geodetic(const LWGEOM *geom);
1504 
1508 extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1509 
1513 extern int lwgeom_force_geodetic(LWGEOM *geom);
1514 
1518 extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1519 
1526 extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1527 
1533 extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1534 
1539 extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1540 
1545 extern int getPoint2d_p_ro(const POINTARRAY *pa, int n, POINT2D **point);
1546 
1550 extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1551 
1555 extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1556 
1560 void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1561 
1566 extern GBOX* gbox_new(uint8_t flags);
1567 
1572 extern void gbox_init(GBOX *gbox);
1573 
1577 extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1578 
1582 extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1583 
1587 extern void gbox_expand(GBOX *g, double d);
1588 
1592 extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1593 
1597 extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1598 
1602 extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1603 
1607 extern char* gbox_to_string(const GBOX *gbox);
1608 
1612 extern GBOX* gbox_copy(const GBOX *gbox);
1613 
1617 extern GBOX* gbox_from_string(const char *str);
1618 
1622 extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1623 
1627 extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1628 
1632 extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1633 
1638 extern size_t gbox_serialized_size(uint8_t flags);
1639 
1643 extern int gbox_same(const GBOX *g1, const GBOX *g2);
1644 
1651 extern void gbox_float_round(GBOX *gbox);
1652 
1656 extern int gbox_is_valid(const GBOX *gbox);
1657 
1662 extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
1663 
1669 extern size_t gserialized_from_lwgeom_size(const LWGEOM *geom);
1670 
1678 extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size);
1679 
1684 extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g);
1685 
1691 extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox);
1692 
1693 
1701 #define LW_PARSER_CHECK_MINPOINTS 1
1702 #define LW_PARSER_CHECK_ODD 2
1703 #define LW_PARSER_CHECK_CLOSURE 4
1704 #define LW_PARSER_CHECK_ZCLOSURE 8
1705 
1706 #define LW_PARSER_CHECK_NONE 0
1707 #define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
1708 
1714 {
1715  const char *wkinput; /* Copy of pointer to input WKT/WKB */
1716  uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
1717  int size; /* Size of serialized LWGEOM in bytes */
1718  LWGEOM *geom; /* Pointer to LWGEOM struct */
1719  const char *message; /* Error/warning message */
1720  int errcode; /* Error/warning number */
1721  int errlocation; /* Location of error */
1722  int parser_check_flags; /* Bitmask of validity checks run during this parse */
1723 }
1725 
1726 /*
1727  * Parser error messages (these must match the message array in lwgparse.c)
1728  */
1729 #define PARSER_ERROR_MOREPOINTS 1
1730 #define PARSER_ERROR_ODDPOINTS 2
1731 #define PARSER_ERROR_UNCLOSED 3
1732 #define PARSER_ERROR_MIXDIMS 4
1733 #define PARSER_ERROR_INVALIDGEOM 5
1734 #define PARSER_ERROR_INVALIDWKBTYPE 6
1735 #define PARSER_ERROR_INCONTINUOUS 7
1736 #define PARSER_ERROR_TRIANGLEPOINTS 8
1737 #define PARSER_ERROR_LESSPOINTS 9
1738 #define PARSER_ERROR_OTHER 10
1739 
1740 
1741 
1742 /*
1743  * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
1744  */
1746 {
1747  uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
1748  char *wkoutput; /* Pointer to WKT or WKB output */
1749  int size; /* Size of serialized LWGEOM in bytes */
1750  const char *message; /* Error/warning message */
1751  int errlocation; /* Location of error */
1752 }
1754 
1755 /*
1756  * Unparser error messages (these must match the message array in lwgunparse.c)
1757  */
1758 #define UNPARSER_ERROR_MOREPOINTS 1
1759 #define UNPARSER_ERROR_ODDPOINTS 2
1760 #define UNPARSER_ERROR_UNCLOSED 3
1761 
1762 
1763 /*
1764 ** Variants available for WKB and WKT output types
1765 */
1766 
1767 #define WKB_ISO 0x01
1768 #define WKB_SFSQL 0x02
1769 #define WKB_EXTENDED 0x04
1770 #define WKB_NDR 0x08
1771 #define WKB_XDR 0x10
1772 #define WKB_HEX 0x20
1773 #define WKB_NO_NPOINTS 0x40 /* Internal use only */
1774 #define WKB_NO_SRID 0x80 /* Internal use only */
1775 
1776 #define WKT_ISO 0x01
1777 #define WKT_SFSQL 0x02
1778 #define WKT_EXTENDED 0x04
1779 
1780 /*
1781 ** New parsing and unparsing functions.
1782 */
1783 
1788 extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
1789 
1795 extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
1796 
1802 extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
1803 
1804 
1808 extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
1809 
1813 extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
1814 
1818 extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
1819 
1823 extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
1824 
1825 extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
1826 
1827 extern char* hexbytes_from_bytes(uint8_t *bytes, size_t size);
1828 
1829 /*
1830 * WKT detailed parsing support
1831 */
1832 extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
1833 void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
1834 void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
1835 
1836 
1837 /* Memory management */
1838 extern void *lwalloc(size_t size);
1839 extern void *lwrealloc(void *mem, size_t size);
1840 extern void lwfree(void *mem);
1841 
1842 /* Utilities */
1843 extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
1844 
1845 /*******************************************************************************
1846  * SQLMM internal functions - TODO: Move into separate header files
1847  ******************************************************************************/
1848 
1849 int lwgeom_has_arc(const LWGEOM *geom);
1850 LWGEOM *lwgeom_segmentize(LWGEOM *geom, uint32_t perQuad);
1852 
1853 /*******************************************************************************
1854  * GEOS proxy functions on LWGEOM
1855  ******************************************************************************/
1856 
1858 const char* lwgeom_geos_version(void);
1859 
1861 LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ;
1862 
1863 LWGEOM *lwgeom_normalize(const LWGEOM *geom);
1864 LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
1865 LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
1866 LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
1867 LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
1868 
1878 LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
1879 
1880 /*
1881  * Return the set of paths shared between two linear geometries,
1882  * and their direction (same or opposite).
1883  *
1884  * @param geom1 a lineal geometry
1885  * @param geom2 another lineal geometry
1886  *
1887  * Requires GEOS-3.3.0+
1888  */
1889 LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
1890 
1891 /*
1892  * An offset curve against the input line.
1893  *
1894  * @param lwline a lineal geometry
1895  * @param size offset distance. Offset left if negative and right if positive
1896  * @param quadsegs number of quadrature segments in curves (try 8)
1897  * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
1898  * @param mitreLimit (try 5.0)
1899  * @return derived geometry (linestring or multilinestring)
1900  *
1901  * Requires GEOS-3.2.0+
1902  */
1903 LWGEOM* lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit);
1904 
1905 
1906 /*******************************************************************************
1907  * PROJ4-dependent extra functions on LWGEOM
1908  ******************************************************************************/
1909 
1915 projPJ lwproj_from_string(const char* txt);
1916 
1923 int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj) ;
1924 int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj) ;
1925 int point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj) ;
1926 
1927 
1928 /*******************************************************************************
1929  * GEOS-dependent extra functions on LWGEOM
1930  ******************************************************************************/
1931 
1939 LWGEOM* lwgeom_buildarea(const LWGEOM *geom) ;
1940 
1941 
1949 
1950 /*
1951  * Split polygon by line, line by line, line by point.
1952  *
1953  * Returns all components as a collection.
1954  * First element of the collection is always the part which
1955  * remains after the cut, while the second element is the
1956  * part which has been cut out. We arbitrarely take the part
1957  * on the *right* of cut lines as the part which has been cut out.
1958  * For a line cut by a point the part which remains is the one
1959  * from start of the line to the cut point.
1960  */
1961 LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
1962 
1963 /*
1964  * Fully node a set of linestrings, using the least nodes preserving
1965  * all the input ones.
1966  *
1967  * Requires GEOS-3.3.0 or higher
1968  */
1969 LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
1970 
1980 LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly);
1981 
1982 #endif /* !defined _LIBLWGEOM_H */
1983 
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:501
int ngeoms
Definition: liblwgeom.h:502
int32_t srid
Definition: liblwgeom.h:475
LWCOMPOUND * lwcompound_construct_empty(int srid, char hasz, char hasm)
Definition: lwcompound.c:110
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2612
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:776
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:908
int32_t srid
Definition: liblwgeom.h:235
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:366
uint8_t type
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:525
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:326
double lwgeom_maxdistance3d(LWGEOM *lw1, LWGEOM *lw2)
Function initialazing 3d max distance calculation.
Definition: measures3d.c:120
uint8_t flags
Definition: liblwgeom.h:499
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:211
uint8_t type
Definition: liblwgeom.h:433
double z
Definition: liblwgeom.h:290
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
Definition: g_box.c:241
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:541
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition: g_box.c:300
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:903
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:49
LWPOINT * lwline_get_lwpoint(LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:294
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:567
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition: lwtin.c:21
GBOX * bbox
Definition: liblwgeom.h:354
POINT2D getPoint2d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:420
uint8_t flags
Definition: liblwgeom.h:397
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:51
POINTARRAY * points
Definition: liblwgeom.h:389
char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
Definition: lwpoint.c:231
GBOX * bbox
Definition: liblwgeom.h:422
void printLWPSURFACE(LWPSURFACE *psurf)
Definition: lwpsurface.c:44
int lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition: lwgeom.c:982
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:20
uint8_t * serialized_pointlist
Definition: liblwgeom.h:322
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1272
GBOX * bbox
Definition: liblwgeom.h:376
void lwmpoly_release(LWMPOLY *lwpoly)
Definition: lwmpoly.c:21
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition: lwin_wkb.c:69
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:947
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:343
double lwgeom_mindistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:173
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
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:2047
uint8_t type
Definition: liblwgeom.h:363
char * r
Definition: cu_in_wkt.c:25
tuple data
Definition: ovdump.py:103
int gserialized_get_zm(const GSERIALIZED *gser)
Return a number indicating presence of Z and M coordinates.
Definition: g_serialized.c:35
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:655
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:49
int maxgeoms
Definition: liblwgeom.h:451
LWGEOM * lwgeom_desegmentize(LWGEOM *geom)
Definition: lwsegmentize.c:841
int lwcollection_ngeoms(const LWCOLLECTION *col)
Definition: lwcollection.c:278
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:99
LWLINE * lwline_segmentize2d(LWLINE *line, double dist)
Definition: lwline.c:134
LWLINE * lwline_from_lwmpoint(int srid, LWMPOINT *mpoint)
Definition: lwline.c:260
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:20
void lwfree(void *mem)
Definition: lwutil.c:190
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:45
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:131
uint8_t flags
Definition: liblwgeom.h:512
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:30
LWGEOM ** rings
Definition: liblwgeom.h:491
int npoints
Definition: liblwgeom.h:327
LWGEOM * lwgeom_force_4d(const LWGEOM *geom)
Definition: lwgeom.c:664
struct struct_lwgeom_unparser_result LWGEOM_UNPARSER_RESULT
uint8_t type
Definition: liblwgeom.h:459
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition: lwgeom_api.c:739
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:100
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
Definition: lwalgorithm.c:461
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:785
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:678
GBOX * bbox
Definition: liblwgeom.h:500
GBOX * bbox
Definition: liblwgeom.h:539
void lwcircstring_free(LWCIRCSTRING *curve)
Definition: lwcircstring.c:85
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition: lwpsurface.c:20
int maxrings
Definition: liblwgeom.h:490
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:43
double next_double_down(float d)
Definition: lwgeom_api.c:161
int32_t srid
Definition: liblwgeom.h:399
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2300
GSERIALIZED * gserialized_copy(const GSERIALIZED *g)
Return a copy of the input serialized geometry.
Definition: g_serialized.c:103
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:1692
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:130
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition: lwgeom.c:652
double b
Definition: liblwgeom.h:270
void lwtin_free(LWTIN *tin)
Definition: lwtin.c:26
uint8_t flags
Definition: liblwgeom.h:353
double xmax
Definition: liblwgeom.h:249
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition: lwpoint.c:25
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:213
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition: lwprint.c:391
double lwgeom_maxdistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfyllywithin calculations.
Definition: measures.c:141
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition: lwgeom.c:224
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:2715
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:180
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:315
void printLWTIN(LWTIN *tin)
Definition: lwtin.c:44
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:1022
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:39
void lwpoint_release(LWPOINT *lwpoint)
Definition: lwpoint.c:223
LWGEOM * lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1586
tuple fmt
Definition: pixval.py:92
int lwgeom_dimensionality(LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1294
void lwline_free(LWLINE *line)
Definition: lwline.c:63
int lw_vasprintf(char **result, const char *format, va_list args)
Definition: vsprintf.c:148
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:381
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:281
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
int32_t srid
Definition: liblwgeom.h:501
GBOX * bbox
Definition: liblwgeom.h:461
LWMPOLY * lwmpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoly.c:27
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:684
double radius
Definition: liblwgeom.h:274
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:116
double lwgeom_mindistance3d(LWGEOM *lw1, LWGEOM *lw2)
Function initialazing 3d min distance calculation.
Definition: measures3d.c:153
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:778
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:209
void lwtriangle_reverse(LWTRIANGLE *triangle)
Definition: lwtriangle.c:100
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
LWGEOM * lw_dist2d_distanceline(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode)
Function initializing shortestline and longestline calculations.
Definition: measures.c:44
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:1992
GBOX * bbox
Definition: liblwgeom.h:387
void printBOX3D(BOX3D *b)
Definition: lwgeom_api.c:557
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition: lwgeom.c:522
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:825
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:2988
uint8_t type
Definition: liblwgeom.h:485
void lwtriangle_force_clockwise(LWTRIANGLE *triangle)
Definition: lwtriangle.c:93
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:56
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:205
LWPOLY ** geoms
Definition: liblwgeom.h:530
char * hexbytes_from_bytes(uint8_t *bytes, size_t size)
Definition: lwout_wkb.c:23
int getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *point)
Definition: lwgeom_api.c:355
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: g_box.c:197
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:186
uint8_t flags
Definition: liblwgeom.h:421
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:389
float next_float_down(double d)
Definition: lwgeom_api.c:129
GBOX * bbox
Definition: liblwgeom.h:409
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:125
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2123
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition: lwgeom.c:284
LWGEOM * lw_dist3d_distancepoint(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode)
Function initializing 3dclosestpoint calculations.
Definition: measures3d.c:79
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:33
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:118
double zoff
Definition: liblwgeom.h:226
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
int32_t srid
Definition: liblwgeom.h:377
void lwpoly_force_clockwise(LWPOLY *poly)
Definition: lwpoly.c:175
LWGEOM ** geoms
Definition: liblwgeom.h:478
uint8_t flags
Definition: liblwgeom.h:473
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:2881
GBOX * bbox
Definition: liblwgeom.h:474
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:700
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:2148
POINTARRAY * point
Definition: liblwgeom.h:367
double lwgeom_length_2d(const LWGEOM *geom)
Definition: lwgeom.c:1588
LWMLINE * lwmline_construct_empty(int srid, char hasz, char hasm)
Definition: lwmline.c:25
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:373
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:672
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:792
char ** result
Definition: liblwgeom.h:218
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:542
int32_t srid
Definition: liblwgeom.h:355
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
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:771
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:350
int ngeoms
Definition: liblwgeom.h:437
GBOX * bbox
Definition: liblwgeom.h:513
POINT3DZ getPoint3dz(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:277
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: lwgeom.c:806
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:858
LWGEOM * lwgeom_flip_coordinates(LWGEOM *in)
Reverse the X and Y coordinate order.
Definition: lwgeom.c:1390
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition: g_box.c:74
uint8_t type
Definition: liblwgeom.h:385
double lwgeom_perimeter(const LWGEOM *geom)
Definition: lwgeom.c:1522
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition: lwtriangle.c:107
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
LWGEOM * lwgeom_segmentize(LWGEOM *geom, uint32_t perQuad)
Definition: lwsegmentize.c:446
void * data
Definition: liblwgeom.h:356
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:354
char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2)
check for same geometry composition
Definition: lwcollection.c:238
int maxgeoms
Definition: liblwgeom.h:503
float next_float_up(double d)
Definition: lwgeom_api.c:145
uint8_t type
Definition: liblwgeom.h:511
LWPOINT * lwpoint_make3dm(int srid, double x, double y, double m)
Definition: lwpoint.c:151
double z
Definition: liblwgeom.h:296
void lwmpoint_release(LWMPOINT *lwpoint)
Definition: lwmpoint.c:20
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
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:608
void(* lwfreeor)(void *mem)
Definition: liblwgeom.h:177
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:100
uint8_t flags
Definition: liblwgeom.h:460
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1267
LWCURVEPOLY * lwcurvepoly_construct_from_lwpoly(LWPOLY *lwpoly)
Construct an equivalent curve polygon from a polygon.
Definition: lwcurvepoly.c:40
LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell)
Definition: lwtriangle.c:128
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:109
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:48
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:23
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:149
int ngeoms
Definition: liblwgeom.h:541
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.
uint8_t flags
Definition: liblwgeom.h:434
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
Definition: ptarray.c:481
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:40
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:59
void(* lwreporter)(const char *fmt, va_list ap)
Definition: liblwgeom.h:178
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
Definition: lwgeom_box3d.c:252
double zmax
Definition: liblwgeom.h:253
double ymin
Definition: liblwgeom.h:250
double lwgeom_mindistance2d(LWGEOM *lw1, LWGEOM *lw2)
Function initialazing min distance calculation.
Definition: measures.c:162
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
Definition: lwhomogenize.c:196
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition: liblwgeom.h:175
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:195
POINT4D getPoint4d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:202
char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2)
Definition: lwcircstring.c:125
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:281
double f
Definition: liblwgeom.h:271
uint8_t type
Definition: liblwgeom.h:420
LWGEOM * lw_dist2d_distancepoint(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode)
Function initializing closestpoint calculations.
Definition: measures.c:91
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:692
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:305
uint8_t type
Definition: liblwgeom.h:498
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:249
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:139
double xmin
Definition: liblwgeom.h:248
LWCIRCSTRING * lwcircstring_construct_empty(int srid, char hasz, char hasm)
Definition: lwcircstring.c:67
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
int32_t srid
Definition: liblwgeom.h:488
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:114
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition: lwgeom.c:187
uint8_t type
Definition: liblwgeom.h:407
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:458
void lwcircstring_release(LWCIRCSTRING *lwcirc)
Definition: lwcircstring.c:79
POINT3DM getPoint3dm(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:291
uint8_t flags
Definition: liblwgeom.h:325
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:29
GBOX * bbox
Definition: liblwgeom.h:487
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:79
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
Definition: g_serialized.c:45
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:206
LWPOLY ** geoms
Definition: liblwgeom.h:452
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
Definition: liblwgeom.h:1713
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
Definition: lwpoint.c:32
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition: lwutil.c:240
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:2806
LWGEOM ** geoms
Definition: liblwgeom.h:465
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWTRIANGLE ** geoms
Definition: liblwgeom.h:543
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)
LWPOINT * lwcircstring_get_lwpoint(LWCIRCSTRING *circ, int where)
Definition: lwcircstring.c:287
uint8_t flags
Definition: liblwgeom.h:447
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:646
uint8_t type
Definition: liblwgeom.h:396
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1645
GBOX * bbox
Definition: liblwgeom.h:526
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:41
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:280
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:35
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:641
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
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:596
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:172
LWPOINT * lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:173
POINTARRAY ** rings
Definition: liblwgeom.h:413
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:955
double e
Definition: liblwgeom.h:272
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition: lwgeom.c:234
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:294
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:42
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:140
LWPOINT ** geoms
Definition: liblwgeom.h:426
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:619
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
LWCURVEPOLY * lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwcurvepoly.c:23
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:375
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:107
int maxgeoms
Definition: liblwgeom.h:529
int nrings
Definition: liblwgeom.h:411
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:26
int32_t srid
Definition: liblwgeom.h:462
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:91
double ymax
Definition: liblwgeom.h:251
int lwgeom_has_arc(const LWGEOM *geom)
Definition: lwsegmentize.c:42
void printLWLINE(LWLINE *line)
Definition: lwline.c:75
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:244
char * s
Definition: cu_in_wkt.c:24
double y
Definition: liblwgeom.h:284
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:84
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:434
uint8_t flags
Definition: liblwgeom.h:486
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:1662
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:273
double z
Definition: liblwgeom.h:308
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:178
tuple x
Definition: pixval.py:53
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:27
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't already there) interpolating the measure betwe...
Definition: lwmline.c:43
uint8_t type
Definition: liblwgeom.h:537
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:351
Datum distance(PG_FUNCTION_ARGS)
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:47
double y
Definition: liblwgeom.h:302
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:1924
int ngeoms
Definition: liblwgeom.h:450
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:814
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
int32_t srid
Definition: liblwgeom.h:366
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:38
uint8_t flags
Definition: liblwgeom.h:247
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:451
char * gserialized_to_string(const GSERIALIZED *g)
Return a WKT representation of the gserialized geometry.
Definition: g_serialized.c:154
int lw_asprintf(result, va_alist)
void lwtriangle_free(LWTRIANGLE *triangle)
Definition: lwtriangle.c:56
LWCOLLECTION * lwcollection_segmentize2d(LWCOLLECTION *coll, double dist)
Definition: lwcollection.c:220
void *(* lwreallocator)(void *mem, size_t size)
Definition: liblwgeom.h:176
void lwpsurface_free(LWPSURFACE *psurf)
Definition: lwpsurface.c:26
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:753
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:98
unsigned int geohash_point_as_int(POINT2D *pt)
Definition: lwalgorithm.c:648
int lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition: lwgeom.c:1181
int maxgeoms
Definition: liblwgeom.h:542
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:215
uint8_t type
Definition: liblwgeom.h:524
GBOX * bbox
Definition: liblwgeom.h:398
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
void lwcollection_release(LWCOLLECTION *lwcollection)
Definition: lwcollection.c:23
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:362
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:604
uint8_t flags
Definition: liblwgeom.h:364
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:193
void lwpoly_reverse(LWPOLY *poly)
Definition: lwpoly.c:201
LWLINE ** geoms
Definition: liblwgeom.h:439
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
Definition: ptarray.c:1614
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
Definition: lwgeodetic.c:2473
char lwtriangle_is_repeated_points(LWTRIANGLE *triangle)
Definition: lwtriangle.c:150
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition: lwgeom.c:1544
void lwgeom_reverse(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition: lwgeom.c:51
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:134
int ngeoms
Definition: liblwgeom.h:515
double lwgeom_maxdistance3d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfyllywithin calculations.
Definition: measures3d.c:132
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:250
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:152
int maxrings
Definition: liblwgeom.h:412
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:80
int maxgeoms
Definition: liblwgeom.h:438
void lwline_reverse(LWLINE *line)
Definition: lwline.c:127
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
Definition: g_box.c:155
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
Definition: lwalgorithm.c:828
GBOX * bbox
Definition: liblwgeom.h:365
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:2459
void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1443
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:472
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:563
void ptarray_longitude_shift(POINTARRAY *pa)
Longitude shift for a pointarray.
Definition: ptarray.c:1378
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
double a
Definition: liblwgeom.h:269
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition: lwgeom.c:618
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:1638
LWPOINT * lwpoint_make4d(int srid, double x, double y, double z, double m)
Definition: lwpoint.c:162
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition: lwpoint.c:37
int32_t srid
Definition: liblwgeom.h:410
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
Definition: ptarray.c:443
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition: lwgeom.c:199
uint32_t size
Definition: liblwgeom.h:337
int maxgeoms
Definition: liblwgeom.h:477
LWGEOM ** geoms
Definition: liblwgeom.h:517
int ptarray_remove_point(POINTARRAY *pa, int where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:246
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1499
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:1124
void 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...
Definition: lwutil.c:151
LWGEOM * lw_dist3d_distanceline(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode)
Function initializing 3dshortestline and 3dlongestline calculations.
Definition: measures3d.c:30
double mmin
Definition: liblwgeom.h:254
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:607
int ngeoms
Definition: liblwgeom.h:476
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:369
double zmin
Definition: liblwgeom.h:252
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:87
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:819
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:32
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:1559
LWGEOM ** geoms
Definition: liblwgeom.h:504
double lwgeom_length(const LWGEOM *geom)
Definition: lwgeom.c:1566
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:183
LWGEOM * lwgeom_segmentize2d(LWGEOM *line, double dist)
Definition: lwgeom.c:624
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:152
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
void printLWPOINT(LWPOINT *point)
Definition: lwpoint.c:191
void ptarray_reverse(POINTARRAY *pa)
Definition: ptarray.c:328
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: g_box.c:471
int32_t srid
Definition: liblwgeom.h:514
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:328
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:34
uint8_t type
Definition: liblwgeom.h:352
uint8_t type
Definition: liblwgeom.h:472
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: g_serialized.c:40
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:59
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:58
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist)
Definition: lwgeom.c:1478
double mmax
Definition: liblwgeom.h:255
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:316
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition: lwgeom.c:194
POINTARRAY * points
Definition: liblwgeom.h:400
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
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:658
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:513
CG_LINE_CROSS_TYPE
The return values of lwline_crossing_direction()
Definition: liblwgeom.h:1333
LWGEOM * lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj)
Definition: lwgeom.c:229
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:154
int maxgeoms
Definition: liblwgeom.h:425
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:2078
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2133
double lwgeom_maxdistance2d(LWGEOM *lw1, LWGEOM *lw2)
Function initialazing max distance calculation.
Definition: measures.c:129
int maxpoints
Definition: liblwgeom.h:328
uint8_t flags
Definition: liblwgeom.h:408
LWPOLY * lwpoly_segmentize2d(LWPOLY *line, double dist)
Definition: lwpoly.c:210
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition: ptarray.c:540
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:711
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:96
void * lwalloc(size_t size)
Definition: lwutil.c:175
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:1229
uint8_t flags
Definition: liblwgeom.h:538
void lwmline_release(LWMLINE *lwline)
Definition: lwmline.c:19
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:312
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1072
GBOX * bbox
Definition: liblwgeom.h:448
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:728
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2197
int ngeoms
Definition: liblwgeom.h:424
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:50
uint8_t flags
Definition: liblwgeom.h:375
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2233
int32_t srid
Definition: liblwgeom.h:527
double lwgeom_mindistance3d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
Definition: measures3d.c:164
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:333
void lwline_release(LWLINE *lwline)
Definition: lwline.c:121
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:26
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:145
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
Definition: lwpoly.c:229
int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
int ngeoms
Definition: liblwgeom.h:528
int32_t srid
Definition: liblwgeom.h:423
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:799
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:174
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1059
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:204
char lwline_same(const LWLINE *p1, const LWLINE *p2)
Definition: lwline.c:142
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:34
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:68
int32_t srid
Definition: liblwgeom.h:540
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:449
int maxgeoms
Definition: liblwgeom.h:516
tuple y
Definition: pixval.py:54
LWGEOM * lwgeom_remove_repeated_points(LWGEOM *in)
Remove repeated points!
Definition: lwgeom.c:1339
int32_t srid
Definition: liblwgeom.h:388
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:328
GBOX * bbox
Definition: liblwgeom.h:435
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition: lwcompound.c:75
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:665
uint8_t type
Definition: liblwgeom.h:446
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1611
double next_double_up(float d)
Definition: lwgeom_api.c:176
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:32
uint8_t flags
Definition: liblwgeom.h:339
double zmax
Definition: liblwgeom.h:234
int32_t srid
Definition: liblwgeom.h:436
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition: lwtriangle.c:69
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
uint8_t flags
Definition: liblwgeom.h:386
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:70
POINTARRAY * points
Definition: liblwgeom.h:378
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:510
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219
double zmin
Definition: liblwgeom.h:233
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:214
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition: ptarray.c:588