PostGIS  3.0.6dev-r@@SVN_REVISION@@
liblwgeom.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright 2011 Sandro Santilli <strk@kbt.io>
22  * Copyright 2011 Paul Ramsey <pramsey@cleverelephant.ca>
23  * Copyright 2007-2008 Mark Cave-Ayland
24  * Copyright 2001-2006 Refractions Research Inc.
25  *
26  **********************************************************************/
27 
28 
29 #ifndef _LIBLWGEOM_H
30 #define _LIBLWGEOM_H 1
31 
32 #include <stdarg.h>
33 #include <stdint.h>
34 #include <stdio.h>
35 
36 #include "../postgis_config.h"
37 
38 #if POSTGIS_PROJ_VERSION < 60
39 #include "proj_api.h"
40 typedef struct PJ
41 {
42  projPJ pj_from;
43  projPJ pj_to;
44 } PJ;
45 
46 typedef PJ LWPROJ;
47 
48 #else
49 #include "proj.h"
50 
51 /* For PROJ6 we cache several extra values to avoid calls to proj_get_source_crs
52  * or proj_get_target_crs since those are very costly
53  */
54 typedef struct LWPROJ
55 {
56  PJ* pj;
57  /* CRSs are swapped: Used in transformation calls */
58  uint8_t source_swapped;
59  uint8_t target_swapped;
60  /* Source crs is geographic: Used in geography calls (source srid == dst srid) */
62 
63  /* Source ellipsoid parameters */
67 #endif
68 
69 #if POSTGIS_PROJ_VERSION < 49
70 /* Use the old (pre-2.2) geodesic functions */
71 #undef PROJ_GEODESIC
72 #else
73 /* Enable new geodesic functions API */
74 #define PROJ_GEODESIC
75 #endif
76 
96 #define LIBLWGEOM_VERSION "3.0.12dev"
97 #define LIBLWGEOM_VERSION_MAJOR "3"
98 #define LIBLWGEOM_VERSION_MINOR "0"
99 #define LIBLWGEOM_GEOS_VERSION "38"
100 
102 const char* lwgeom_version(void);
103 
107 #define LW_TRUE 1
108 #define LW_FALSE 0
109 #define LW_UNKNOWN 2
110 #define LW_FAILURE 0
111 #define LW_SUCCESS 1
112 
116 #define POINTTYPE 1
117 #define LINETYPE 2
118 #define POLYGONTYPE 3
119 #define MULTIPOINTTYPE 4
120 #define MULTILINETYPE 5
121 #define MULTIPOLYGONTYPE 6
122 #define COLLECTIONTYPE 7
123 #define CIRCSTRINGTYPE 8
124 #define COMPOUNDTYPE 9
125 #define CURVEPOLYTYPE 10
126 #define MULTICURVETYPE 11
127 #define MULTISURFACETYPE 12
128 #define POLYHEDRALSURFACETYPE 13
129 #define TRIANGLETYPE 14
130 #define TINTYPE 15
131 
132 #define NUMTYPES 16
133 
138 #define WKBZOFFSET 0x80000000
139 #define WKBMOFFSET 0x40000000
140 #define WKBSRIDFLAG 0x20000000
141 #define WKBBBOXFLAG 0x10000000
142 
144 typedef enum LWORD_T {
145  LWORD_X = 0,
146  LWORD_Y = 1,
147  LWORD_Z = 2,
148  LWORD_M = 3
150 
151 /**********************************************************************
152 ** Spherical radius.
153 ** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
154 ** the XVII General Assembly of the IUGG in Canberra.
155 ** http://en.wikipedia.org/wiki/Earth_radius
156 ** http://en.wikipedia.org/wiki/World_Geodetic_System
157 */
158 
159 #define WGS84_MAJOR_AXIS 6378137.0
160 #define WGS84_INVERSE_FLATTENING 298.257223563
161 #define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
162 #define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
163 #define WGS84_SRID 4326
164 
165 
172 #define LWFLAG_Z 0x01
173 #define LWFLAG_M 0x02
174 #define LWFLAG_BBOX 0x04
175 #define LWFLAG_GEODETIC 0x08
176 #define LWFLAG_READONLY 0x10
177 #define LWFLAG_SOLID 0x20
178 
179 #define FLAGS_GET_Z(flags) ((flags) & LWFLAG_Z)
180 #define FLAGS_GET_M(flags) (((flags) & LWFLAG_M)>>1)
181 #define FLAGS_GET_BBOX(flags) (((flags) & LWFLAG_BBOX)>>2)
182 #define FLAGS_GET_GEODETIC(flags) (((flags) & LWFLAG_GEODETIC)>>3)
183 #define FLAGS_GET_READONLY(flags) (((flags) & LWFLAG_READONLY)>>4)
184 #define FLAGS_GET_SOLID(flags) (((flags) & LWFLAG_SOLID)>>5)
185 
186 #define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_Z) : ((flags) & ~LWFLAG_Z))
187 #define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_M) : ((flags) & ~LWFLAG_M))
188 #define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_BBOX) : ((flags) & ~LWFLAG_BBOX))
189 #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_GEODETIC) : ((flags) & ~LWFLAG_GEODETIC))
190 #define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_READONLY) : ((flags) & ~LWFLAG_READONLY))
191 #define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_SOLID) : ((flags) & ~LWFLAG_SOLID))
192 
193 #define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
194 #define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
195 #define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
196 
206 #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
207 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
208 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
209 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
210 #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
211 #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
212 #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
213 #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
214 #define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
215 
220 #define SRID_MAXIMUM 999999
221 
226 #define SRID_USER_MAXIMUM 998999
227 
229 #define SRID_UNKNOWN 0
230 #define SRID_IS_UNKNOWN(x) ((int)x<=0)
231 
232 /* Invalid SRID value, for internal use */
233 #define SRID_INVALID (999999 + 2)
234 
235 /*
236 ** EPSG WGS84 geographics, OGC standard default SRS, better be in
237 ** the SPATIAL_REF_SYS table!
238 */
239 #define SRID_DEFAULT 4326
240 
241 #ifndef __GNUC__
242 # define __attribute__(x)
243 #endif
244 
251 extern int32_t clamp_srid(int32_t srid);
252 
256 typedef void* (*lwallocator)(size_t size);
257 typedef void* (*lwreallocator)(void *mem, size_t size);
258 typedef void (*lwfreeor)(void* mem);
259 typedef void (*lwreporter)(const char* fmt, va_list ap)
260  __attribute__ (( format(printf, 1, 0) ));
261 typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
262  __attribute__ (( format(printf, 2,0) ));
263 
270 extern void lwgeom_set_handlers(lwallocator allocator,
271  lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
272  lwreporter noticereporter);
273 
274 extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
275 
288 extern void lwgeom_request_interrupt(void);
289 
293 extern void lwgeom_cancel_interrupt(void);
294 
305 typedef void (lwinterrupt_callback)();
307 
308 
309 /******************************************************************
310 * LWGEOM and GBOX both use LWFLAGS bit mask.
311 * Serializations (may) use different bit mask schemes.
312 */
313 typedef uint16_t lwflags_t;
314 
315 /******************************************************************/
316 
317 typedef struct {
318  double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
319 } AFFINE;
320 
321 /******************************************************************/
322 
323 typedef struct
324 {
325  double xmin, ymin, zmin;
326  double xmax, ymax, zmax;
327  int32_t srid;
328 }
329 BOX3D;
330 
331 /******************************************************************
332 * GBOX structure.
333 * We include the flags (information about dimensionality),
334 * so we don't have to constantly pass them
335 * into functions that use the GBOX.
336 */
337 typedef struct
338 {
340  double xmin;
341  double xmax;
342  double ymin;
343  double ymax;
344  double zmin;
345  double zmax;
346  double mmin;
347  double mmax;
348 } GBOX;
349 
350 
351 /******************************************************************
352 * SPHEROID
353 *
354 * Standard definition of an ellipsoid (what wkt calls a spheroid)
355 * f = (a-b)/a
356 * e_sq = (a*a - b*b)/(a*a)
357 * b = a - fa
358 */
359 typedef struct
360 {
361  double a; /* semimajor axis */
362  double b; /* semiminor axis b = (a - fa) */
363  double f; /* flattening f = (a-b)/a */
364  double e; /* eccentricity (first) */
365  double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
366  double radius; /* spherical average radius = (2*a+b)/3 */
367  char name[20]; /* name of ellipse */
368 }
369 SPHEROID;
370 
371 /******************************************************************
372 * POINT2D, POINT3D, POINT3DM, POINT4D
373 */
374 typedef struct
375 {
376  double x, y;
377 }
378 POINT2D;
379 
380 typedef struct
381 {
382  double x, y, z;
383 }
384 POINT3DZ;
385 
386 typedef struct
387 {
388  double x, y, z;
389 }
390 POINT3D;
391 
392 typedef struct
393 {
394  double x, y, m;
395 }
396 POINT3DM;
397 
398 typedef struct
399 {
400  double x, y, z, m;
401 }
402 POINT4D;
403 
404 /******************************************************************
405 * POINTARRAY
406 * Point array abstracts a lot of the complexity of points and point lists.
407 * It handles 2d/3d translation
408 * (2d points converted to 3d will have z=0 or NaN)
409 * DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
410 */
411 typedef struct
412 {
413  uint32_t npoints; /* how many points we are currently storing */
414  uint32_t maxpoints; /* how many points we have space for in serialized_pointlist */
415 
416  /* Use FLAGS_* macros to handle */
418 
419  /* Array of POINT 2D, 3D or 4D, possibly misaligned. */
421 }
422 POINTARRAY;
423 
424 /******************************************************************
425 * GSERIALIZED
426 */
427 
428 typedef struct
429 {
430  uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
431  uint8_t srid[3]; /* 24 bits of SRID */
432  uint8_t gflags; /* HasZ, HasM, HasBBox, IsGeodetic */
433  uint8_t data[1]; /* See gserialized.txt */
434 } GSERIALIZED;
435 
436 /******************************************************************
437 * LWGEOM (any geometry type)
438 *
439 * Abstract type, note that 'type', 'bbox' and 'srid' are available in
440 * all geometry variants.
441 */
442 typedef struct
443 {
445  void *data;
446  int32_t srid;
448  uint8_t type;
449  char pad[1]; /* Padding to 24 bytes (unused) */
450 }
451 LWGEOM;
452 
453 /* POINTYPE */
454 typedef struct
455 {
457  POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
458  int32_t srid;
460  uint8_t type; /* POINTTYPE */
461  char pad[1]; /* Padding to 24 bytes (unused) */
462 }
463 LWPOINT; /* "light-weight point" */
464 
465 /* LINETYPE */
466 typedef struct
467 {
469  POINTARRAY *points; /* array of POINT3D */
470  int32_t srid;
472  uint8_t type; /* LINETYPE */
473  char pad[1]; /* Padding to 24 bytes (unused) */
474 }
475 LWLINE; /* "light-weight line" */
476 
477 /* TRIANGLE */
478 typedef struct
479 {
482  int32_t srid;
484  uint8_t type;
485  char pad[1]; /* Padding to 24 bytes (unused) */
486 }
487 LWTRIANGLE;
488 
489 /* CIRCSTRINGTYPE */
490 typedef struct
491 {
493  POINTARRAY *points; /* array of POINT(3D/3DM) */
494  int32_t srid;
496  uint8_t type; /* CIRCSTRINGTYPE */
497  char pad[1]; /* Padding to 24 bytes (unused) */
498 }
499 LWCIRCSTRING; /* "light-weight circularstring" */
500 
501 /* POLYGONTYPE */
502 typedef struct
503 {
505  POINTARRAY **rings; /* list of rings (list of points) */
506  int32_t srid;
508  uint8_t type; /* POLYGONTYPE */
509  char pad[1]; /* Padding to 24 bytes (unused) */
510  uint32_t nrings; /* how many rings we are currently storing */
511  uint32_t maxrings; /* how many rings we have space for in **rings */
512 }
513 LWPOLY; /* "light-weight polygon" */
514 
515 /* MULTIPOINTTYPE */
516 typedef struct
517 {
520  int32_t srid;
522  uint8_t type; /* MULTYPOINTTYPE */
523  char pad[1]; /* Padding to 24 bytes (unused) */
524  uint32_t ngeoms; /* how many geometries we are currently storing */
525  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
526 }
527 LWMPOINT;
528 
529 /* MULTILINETYPE */
530 typedef struct
531 {
534  int32_t srid;
536  uint8_t type; /* MULTILINETYPE */
537  char pad[1]; /* Padding to 24 bytes (unused) */
538  uint32_t ngeoms; /* how many geometries we are currently storing */
539  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
540 }
541 LWMLINE;
542 
543 /* MULTIPOLYGONTYPE */
544 typedef struct
545 {
548  int32_t srid;
550  uint8_t type; /* MULTIPOLYGONTYPE */
551  char pad[1]; /* Padding to 24 bytes (unused) */
552  uint32_t ngeoms; /* how many geometries we are currently storing */
553  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
554 }
555 LWMPOLY;
556 
557 /* COLLECTIONTYPE */
558 typedef struct
559 {
562  int32_t srid;
564  uint8_t type; /* COLLECTIONTYPE */
565  char pad[1]; /* Padding to 24 bytes (unused) */
566  uint32_t ngeoms; /* how many geometries we are currently storing */
567  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
568 }
570 
571 /* COMPOUNDTYPE */
572 typedef struct
573 {
576  int32_t srid;
578  uint8_t type; /* COLLECTIONTYPE */
579  char pad[1]; /* Padding to 24 bytes (unused) */
580  uint32_t ngeoms; /* how many geometries we are currently storing */
581  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
582 }
583 LWCOMPOUND; /* "light-weight compound line" */
584 
585 /* CURVEPOLYTYPE */
586 typedef struct
587 {
590  int32_t srid;
592  uint8_t type; /* CURVEPOLYTYPE */
593  char pad[1]; /* Padding to 24 bytes (unused) */
594  uint32_t nrings; /* how many rings we are currently storing */
595  uint32_t maxrings; /* how many rings we have space for in **rings */
596 }
597 LWCURVEPOLY; /* "light-weight polygon" */
598 
599 /* MULTICURVE */
600 typedef struct
601 {
604  int32_t srid;
606  uint8_t type; /* MULTICURVE */
607  char pad[1]; /* Padding to 24 bytes (unused) */
608  uint32_t ngeoms; /* how many geometries we are currently storing */
609  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
610 }
611 LWMCURVE;
612 
613 /* MULTISURFACETYPE */
614 typedef struct
615 {
618  int32_t srid;
620  uint8_t type; /* MULTISURFACETYPE */
621  char pad[1]; /* Padding to 24 bytes (unused) */
622  uint32_t ngeoms; /* how many geometries we are currently storing */
623  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
624 }
625 LWMSURFACE;
626 
627 /* POLYHEDRALSURFACETYPE */
628 typedef struct
629 {
632  int32_t srid;
634  uint8_t type; /* POLYHEDRALSURFACETYPE */
635  char pad[1]; /* Padding to 24 bytes (unused) */
636  uint32_t ngeoms; /* how many geometries we are currently storing */
637  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
638 }
639 LWPSURFACE;
640 
641 /* TINTYPE */
642 typedef struct
643 {
646  int32_t srid;
648  uint8_t type; /* TINTYPE */
649  char pad[1]; /* Padding to 24 bytes (unused) */
650  uint32_t ngeoms; /* how many geometries we are currently storing */
651  uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
652 }
653 LWTIN;
654 
655 /* Casts LWGEOM->LW* (return NULL if cast is illegal) */
656 extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
657 extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
658 extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
659 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
660 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
661 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
662 
663 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
664 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
665 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
666 extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
667 extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
668 extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
669 extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
670 extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
671 
672 /* Casts LW*->LWGEOM (always cast) */
673 extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
674 extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
675 extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
676 extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
677 extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
678 extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
679 extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
680 extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
681 extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
682 extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
683 extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
684 extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
685 extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
686 
687 
688 extern LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom);
689 extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
690 extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
691 extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
692 extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
693 extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
694 
696 
700 extern lwflags_t lwflags(int hasz, int hasm, int geodetic);
701 
702 
703 
704 /***********************************************************************
705 ** GSERIALIZED API
706 */
707 
712 
717 extern const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims);
718 
723 extern uint32_t gserialized_get_type(const GSERIALIZED *g);
724 
729 extern uint32_t gserialized_max_header_size(void);
730 
736 extern int32_t gserialized_hash(const GSERIALIZED *g);
737 
742 extern int32_t gserialized_get_srid(const GSERIALIZED *g);
743 
748 extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
749 
756 extern int gserialized_is_empty(const GSERIALIZED *g);
757 
761 extern int gserialized_has_bbox(const GSERIALIZED *gser);
762 
766 extern int gserialized_has_z(const GSERIALIZED *gser);
767 
771 extern int gserialized_has_m(const GSERIALIZED *gser);
772 
776 extern int gserialized_is_geodetic(const GSERIALIZED *gser);
777 
781 extern int gserialized_ndims(const GSERIALIZED *gser);
782 
792 extern int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2);
793 
801 extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
802 
807 extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g);
808 
814 extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box);
815 
820 extern int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box);
821 
828 
834 
838 extern uint32_t gserialized_get_version(const GSERIALIZED *g);
839 
843 extern int gserialized_peek_first_point(const GSERIALIZED *g, POINT4D *out_point);
844 
845 /*****************************************************************************/
846 
847 
854 extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
855 extern void lwgeom_drop_srid(LWGEOM *lwgeom);
856 
863 extern void lwgeom_add_bbox(LWGEOM *lwgeom);
867 extern void lwgeom_refresh_bbox(LWGEOM *lwgeom);
871 extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
872 
880 extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
881 
885 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
886 
890 extern int lwgeom_isfinite(const LWGEOM *lwgeom);
891 
892 
893 /******************************************************************/
894 /* Functions that work on type numbers */
895 
899 extern int lwtype_is_collection(uint8_t type);
900 
904 extern uint32_t lwtype_get_collectiontype(uint8_t type);
905 
910 extern const char *lwtype_name(uint8_t type);
911 extern uint8_t lwtype_multitype(uint8_t type);
912 
913 /******************************************************************/
914 
915 /*
916  * copies a point from the point array into the parameter point
917  * will set point's z=0 (or NaN) if pa is 2d
918  * will set point's m=0 (or NaN) if pa is 3d or 2d
919  * NOTE: point is a real POINT3D *not* a pointer
920  */
921 extern POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n);
922 
923 /*
924  * copies a point from the point array into the parameter point
925  * will set point's z=0 (or NaN) if pa is 2d
926  * will set point's m=0 (or NaN) if pa is 3d or 2d
927  * NOTE: this will modify the point4d pointed to by 'point'.
928  */
929 extern int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point);
930 
931 /*
932  * copies a point from the point array into the parameter point
933  * will set point's z=0 (or NaN) if pa is 2d
934  * NOTE: point is a real POINT3D *not* a pointer
935  */
936 extern POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n);
937 extern POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n);
938 
939 /*
940  * copies a point from the point array into the parameter point
941  * will set point's z=0 (or NaN) if pa is 2d
942  * NOTE: this will modify the point3d pointed to by 'point'.
943  */
944 extern int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point);
945 extern int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point);
946 
947 
948 /*
949  * copies a point from the point array into the parameter point
950  * z value (if present is not returned)
951  * NOTE: point is a real POINT3D *not* a pointer
952  */
953 extern POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n);
954 
955 /*
956  * copies a point from the point array into the parameter point
957  * z value (if present is not returned)
958  * NOTE: this will modify the point2d pointed to by 'point'.
959  */
960 extern int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point);
961 
962 /*
963  * set point N to the given value
964  * NOTE that the pointarray can be of any
965  * dimension, the appropriate ordinate values
966  * will be extracted from it
967  *
968  * N must be a valid point index
969  */
970 extern void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d);
971 
977 extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
978 
982 extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
983 
987 extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
988 
994 extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
995 
1001 extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
1002 
1014 extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
1015 
1020 extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where);
1021 
1026 extern int ptarray_remove_point(POINTARRAY *pa, uint32_t where);
1027 
1039 extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
1040 
1046 extern POINTARRAY *ptarray_removePoint(POINTARRAY *pa, uint32_t where);
1047 
1054 extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
1055 
1056 extern int ptarray_is_closed(const POINTARRAY *pa);
1057 extern int ptarray_is_closed_2d(const POINTARRAY *pa);
1058 extern int ptarray_is_closed_3d(const POINTARRAY *pa);
1059 extern int ptarray_is_closed_z(const POINTARRAY *pa);
1061 
1067 extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
1068  double tolerance);
1069 
1070 
1074 extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
1075 extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
1076 extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
1077 extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
1078 
1079 extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
1080 extern LWGEOM* lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint);
1081 extern LWGEOM* lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm);
1082 
1083 /*
1084  * Force to use SFS 1.1 geometry type
1085  * (rather than SFS 1.2 and/or SQL/MM)
1086  */
1087 extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
1088 
1089 
1090 /*--------------------------------------------------------
1091  * all the base types (point/line/polygon) will have a
1092  * basic constructor, basic de-serializer, basic serializer,
1093  * bounding box finder and (TODO) serialized form size finder.
1094  *--------------------------------------------------------*/
1095 
1096 /*
1097  * convenience functions to hide the POINTARRAY
1098  */
1099 extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
1100 extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
1101 extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
1102 extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
1103 
1104 /******************************************************************
1105  * LWLINE functions
1106  ******************************************************************/
1107 
1111 extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1112 
1116 extern POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat);
1117 
1121 extern LWPOINT* lwline_interpolate_point_3d(const LWLINE *line, double distance);
1122 
1123 /******************************************************************
1124  * LWPOLY functions
1125  ******************************************************************/
1126 
1131 extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1132 
1137 extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1138 
1143 extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1144 
1149 extern LWCOMPOUND* lwcompound_construct_from_lwline(const LWLINE *lwpoly);
1150 
1156 
1157 
1158 /******************************************************************
1159  * LWGEOM functions
1160  ******************************************************************/
1161 
1162 extern int lwcollection_ngeoms(const LWCOLLECTION *col);
1163 
1164 /* Given a generic geometry/collection, return the "simplest" form.
1165  * The elements of the homogenized collection are references to the
1166  * input geometry; a deep clone is not performed.
1167  * TODO: consider returning a geometry that does not reference the
1168  * input
1169  * */
1170 extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
1171 
1172 
1173 /******************************************************************
1174  * LWMULTIx and LWCOLLECTION functions
1175  ******************************************************************/
1176 
1178 
1179 /* WARNING: the output will contain references to geometries in the input, */
1180 /* so the result must be carefully released, not freed. */
1182 
1183 
1184 /******************************************************************
1185  * SERIALIZED FORM functions
1186  ******************************************************************/
1187 
1193 extern void lwgeom_set_srid(LWGEOM *geom, int32_t srid);
1194 
1195 /*------------------------------------------------------
1196  * other stuff
1197  *
1198  * handle the double-to-float conversion. The results of this
1199  * will usually be a slightly bigger box because of the difference
1200  * between float8 and float4 representations.
1201  */
1202 
1203 extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1204 extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1205 
1206 void expand_box3d(BOX3D *box, double d);
1207 
1208 
1209 /****************************************************************
1210  * MEMORY MANAGEMENT
1211  ****************************************************************/
1212 
1213 /*
1214 * The *_free family of functions frees *all* memory associated
1215 * with the pointer. When the recursion gets to the level of the
1216 * POINTARRAY, the POINTARRAY is only freed if it is not flagged
1217 * as "read only". LWGEOMs constructed on top of GSERIALIZED
1218 * from PgSQL use read only point arrays.
1219 */
1220 
1221 extern void ptarray_free(POINTARRAY *pa);
1222 extern void lwpoint_free(LWPOINT *pt);
1223 extern void lwline_free(LWLINE *line);
1224 extern void lwpoly_free(LWPOLY *poly);
1225 extern void lwtriangle_free(LWTRIANGLE *triangle);
1226 extern void lwmpoint_free(LWMPOINT *mpt);
1227 extern void lwmline_free(LWMLINE *mline);
1228 extern void lwmpoly_free(LWMPOLY *mpoly);
1229 extern void lwpsurface_free(LWPSURFACE *psurf);
1230 extern void lwtin_free(LWTIN *tin);
1231 extern void lwcollection_free(LWCOLLECTION *col);
1232 extern void lwcircstring_free(LWCIRCSTRING *curve);
1233 extern void lwgeom_free(LWGEOM *geom);
1234 
1235 /*
1236 * The *_release family of functions frees the LWGEOM structures
1237 * surrounding the POINTARRAYs but leaves the POINTARRAYs
1238 * intact. Useful when re-shaping geometries between types,
1239 * or splicing geometries together.
1240 */
1241 
1242 extern void lwpoint_release(LWPOINT *lwpoint);
1243 extern void lwline_release(LWLINE *lwline);
1244 extern void lwpoly_release(LWPOLY *lwpoly);
1245 extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1246 extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1247 extern void lwmpoint_release(LWMPOINT *lwpoint);
1248 extern void lwmline_release(LWMLINE *lwline);
1249 extern void lwmpoly_release(LWMPOLY *lwpoly);
1250 extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1251 extern void lwtin_release(LWTIN *lwtin);
1252 extern void lwcollection_release(LWCOLLECTION *lwcollection);
1253 extern void lwgeom_release(LWGEOM *lwgeom);
1254 
1255 
1256 /****************************************************************
1257 * Utility
1258 ****************************************************************/
1259 
1260 extern void printBOX3D(BOX3D *b);
1261 extern void printPA(POINTARRAY *pa);
1262 extern void printLWPOINT(LWPOINT *point);
1263 extern void printLWLINE(LWLINE *line);
1264 extern void printLWPOLY(LWPOLY *poly);
1265 extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1266 extern void printLWPSURFACE(LWPSURFACE *psurf);
1267 extern void printLWTIN(LWTIN *tin);
1268 
1269 extern float next_float_down(double d);
1270 extern float next_float_up(double d);
1271 
1272 /* general utilities 2D */
1273 extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1274 extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1275 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1276 extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1277 extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1278 extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1279 extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1280 extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1281 extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1282 extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1283 
1284 /* 3D */
1285 extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1286 extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1287 
1288 extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1289 extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1290 extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1291 
1292 
1293 extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1294 extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1295 extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1296 extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1297 
1298 extern double lwgeom_area(const LWGEOM *geom);
1299 extern double lwgeom_length(const LWGEOM *geom);
1300 extern double lwgeom_length_2d(const LWGEOM *geom);
1301 extern double lwgeom_perimeter(const LWGEOM *geom);
1302 extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1303 extern int lwgeom_dimension(const LWGEOM *geom);
1304 
1305 extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, uint32_t where);
1306 extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where);
1307 
1308 extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1309 extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1310 extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where);
1311 
1312 extern double ptarray_length_2d(const POINTARRAY *pts);
1313 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1314 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1315 extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1316 
1317 extern LWGEOM* lwgeom_reverse(const LWGEOM *lwgeom);
1318 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1319 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1320 extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1321 
1322 extern void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F);
1323 
1328 extern int lwgeom_is_clockwise(LWGEOM *lwgeom);
1329 
1330 
1334 extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
1335 extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1336 
1340 typedef struct gridspec_t
1341 {
1342  double ipx;
1343  double ipy;
1344  double ipz;
1345  double ipm;
1346  double xsize;
1347  double ysize;
1348  double zsize;
1349  double msize;
1350 }
1352 
1353 extern LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid);
1354 extern void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid);
1355 
1356 
1357 /****************************************************************
1358 * READ/WRITE FUNCTIONS
1359 *
1360 * Coordinate writing functions, which will alter the coordinates
1361 * and potentially the structure of the input geometry. When
1362 * called from within PostGIS, the LWGEOM argument should be built
1363 * on top of a gserialized copy, created using
1364 * PG_GETARG_GSERIALIZED_P_COPY()
1365 ****************************************************************/
1366 
1367 extern void lwgeom_reverse_in_place(LWGEOM *lwgeom);
1368 extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1369 extern void lwgeom_longitude_shift(LWGEOM *lwgeom);
1370 extern int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed);
1371 extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1372 extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1373 extern int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance);
1374 
1375 
1388 LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1389 
1390 
1400 extern int lwgeom_needs_bbox(const LWGEOM *geom);
1401 
1405 extern uint32_t lwgeom_count_vertices(const LWGEOM *geom);
1406 
1411 extern uint32_t lwgeom_count_rings(const LWGEOM *geom);
1412 
1417 extern int lwgeom_has_srid(const LWGEOM *geom);
1418 
1423 extern int lwgeom_is_closed(const LWGEOM *geom);
1424 
1428 extern int lwgeom_dimensionality(const LWGEOM *geom);
1429 
1430 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
1431 extern char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1432 
1433 
1441 extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1442 
1446 extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1447 extern POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1448 
1449 
1450 /*
1451 * Geometry constructors. These constructors to not copy the point arrays
1452 * passed to them, they just take references, so do not free them out
1453 * from underneath the geometries.
1454 */
1455 extern LWPOINT* lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point);
1456 extern LWMPOINT *lwmpoint_construct(int32_t srid, const POINTARRAY *pa);
1457 extern LWLINE* lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1458 extern LWCIRCSTRING* lwcircstring_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1459 extern LWPOLY* lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1460 extern LWCURVEPOLY* lwcurvepoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1461 extern LWTRIANGLE* lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1462 extern LWCOLLECTION* lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1463 /*
1464 * Empty geometry constructors.
1465 */
1466 extern LWGEOM* lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm);
1467 extern LWPOINT* lwpoint_construct_empty(int32_t srid, char hasz, char hasm);
1468 extern LWLINE* lwline_construct_empty(int32_t srid, char hasz, char hasm);
1469 extern LWPOLY* lwpoly_construct_empty(int32_t srid, char hasz, char hasm);
1470 extern LWCURVEPOLY* lwcurvepoly_construct_empty(int32_t srid, char hasz, char hasm);
1471 extern LWCIRCSTRING* lwcircstring_construct_empty(int32_t srid, char hasz, char hasm);
1472 extern LWCOMPOUND* lwcompound_construct_empty(int32_t srid, char hasz, char hasm);
1473 extern LWTRIANGLE* lwtriangle_construct_empty(int32_t srid, char hasz, char hasm);
1474 extern LWMPOINT* lwmpoint_construct_empty(int32_t srid, char hasz, char hasm);
1475 extern LWMLINE* lwmline_construct_empty(int32_t srid, char hasz, char hasm);
1476 extern LWMPOLY* lwmpoly_construct_empty(int32_t srid, char hasz, char hasm);
1477 extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm);
1478 
1479 
1480 /* Other constructors */
1481 extern LWPOINT *lwpoint_make2d(int32_t srid, double x, double y);
1482 extern LWPOINT *lwpoint_make3dz(int32_t srid, double x, double y, double z);
1483 extern LWPOINT *lwpoint_make3dm(int32_t srid, double x, double y, double m);
1484 extern LWPOINT *lwpoint_make4d(int32_t srid, double x, double y, double z, double m);
1485 extern LWPOINT *lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p);
1486 extern LWLINE *lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms);
1487 extern LWLINE *lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1488 extern LWLINE *lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint);
1489 extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1490 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1491 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1492 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1493 extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1494 extern LWPOLY *lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2);
1495 extern LWPOLY *lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1496 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1497 extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1498 
1499 /* Some point accessors */
1500 extern double lwpoint_get_x(const LWPOINT *point);
1501 extern double lwpoint_get_y(const LWPOINT *point);
1502 extern double lwpoint_get_z(const LWPOINT *point);
1503 extern double lwpoint_get_m(const LWPOINT *point);
1504 
1508 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1509 
1513 extern int lwgeom_has_z(const LWGEOM *geom);
1514 
1518 extern int lwgeom_has_m(const LWGEOM *geom);
1519 
1523 extern int lwgeom_is_solid(const LWGEOM *geom);
1524 
1528 extern int lwgeom_ndims(const LWGEOM *geom);
1529 
1530 /*
1531  * Given a point, returns the location of closest point on pointarray
1532  * as a fraction of total length (0: first point -- 1: last point).
1533  *
1534  * If not-null, the third argument will be set to the actual distance
1535  * of the point from the pointarray.
1536  */
1537 extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1538 
1543 extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1544 extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1545 
1550 extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1551 
1557 extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1558 
1562 extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1563 
1574 extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1575 
1581 extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1582 
1587 extern int lwgeom_is_trajectory(const LWGEOM *geom);
1588 extern int lwline_is_trajectory(const LWLINE *geom);
1589 
1590 /*
1591  * Ensure every segment is at most 'dist' long.
1592  * Returned LWGEOM might is unchanged if a POINT.
1593  */
1594 extern LWGEOM *lwgeom_segmentize2d(const LWGEOM *line, double dist);
1595 extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1596 extern LWLINE *lwline_segmentize2d(const LWLINE *line, double dist);
1597 extern LWPOLY *lwpoly_segmentize2d(const LWPOLY *line, double dist);
1598 extern LWCOLLECTION *lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist);
1599 
1600 /*
1601  * Point density functions
1602  */
1603 extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, uint32_t npoints, int32_t seed);
1604 extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints, int32_t seed);
1605 extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed);
1606 
1607 /*
1608  * Geometric median
1609  */
1610 extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1611 extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1612 
1616 char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1617 unsigned int geohash_point_as_int(POINT2D *pt);
1618 
1619 
1631 };
1632 
1636 int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1637 
1641 LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1642 
1648 #define LW_GML_IS_DIMS (1<<0)
1650 #define LW_GML_IS_DEGREE (1<<1)
1652 #define LW_GML_SHORTLINE (1<<2)
1654 #define LW_GML_EXTENT (1<<4)
1655 
1656 
1657 #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1658 #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1666 #define LW_X3D_FLIP_XY (1<<0)
1667 #define LW_X3D_USE_GEOCOORDS (1<<1)
1668 #define X3D_USE_GEOCOORDS(x) ((x) & LW_X3D_USE_GEOCOORDS)
1669 
1670 
1671 
1672 extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1673 extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1677 extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1678 extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1679 extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1680 extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1681 extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1682 extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1683 extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1684 
1694 extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1695 
1701 extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1702 
1706 extern void spheroid_init(SPHEROID *s, double a, double b);
1707 
1713 extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1714 
1718 extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1719 
1724 extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1725 
1729 extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1730 
1735 extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1736 
1741 extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1742 
1747 extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1748 
1753 extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1754 
1755 typedef struct {
1757  double radius;
1759 
1761 
1762 /* Calculates the minimum circle that encloses all of the points in g, using a
1763  * two-dimensional implementation of the algorithm proposed in:
1764  *
1765  * Welzl, Emo (1991), "Smallest enclosing disks (balls and elipsoids)."
1766  * New Results and Trends in Computer Science (H. Maurer, Ed.), Lecture Notes
1767  * in Computer Science, 555 (1991) 359-370.
1768  *
1769  * Available online at the time of this writing at
1770  * https://www.inf.ethz.ch/personal/emo/PublFiles/SmallEnclDisk_LNCS555_91.pdf
1771  *
1772  * Returns NULL if the circle could not be calculated.
1773  */
1774 extern LWBOUNDINGCIRCLE* lwgeom_calculate_mbc(const LWGEOM* g);
1775 
1788 extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1789 
1790 
1791 struct LWPOINTITERATOR;
1792 typedef struct LWPOINTITERATOR LWPOINTITERATOR;
1793 
1798 
1804 
1809 
1814 
1820 extern int lwpointiterator_modify_next(LWPOINTITERATOR* s, const POINT4D* p);
1821 
1829 
1835 
1836 
1840 extern uint8_t parse_hex(char *str);
1841 
1845 extern void deparse_hex(uint8_t str, char *result);
1846 
1847 
1848 
1849 /***********************************************************************
1850 ** Functions for managing serialized forms and bounding boxes.
1851 */
1852 
1856 extern int lwgeom_check_geodetic(const LWGEOM *geom);
1857 
1861 extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1862 
1866 extern int lwgeom_force_geodetic(LWGEOM *geom);
1867 
1871 extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1872 
1879 extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1880 
1886 extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1887 
1892 extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1893 
1898 extern int getPoint2d_p_ro(const POINTARRAY *pa, uint32_t n, POINT2D **point);
1899 
1903 extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1904 
1908 extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1909 
1913 int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1914 
1919 extern GBOX* gbox_new(lwflags_t flags);
1920 
1925 extern void gbox_init(GBOX *gbox);
1926 
1930 extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1931 
1935 extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1936 
1940 extern void gbox_expand(GBOX *g, double d);
1941 
1945 extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
1946 
1950 extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1951 
1955 extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1956 
1960 extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1961 
1965 extern char* gbox_to_string(const GBOX *gbox);
1966 
1970 extern GBOX* gbox_copy(const GBOX *gbox);
1971 
1975 extern GBOX* gbox_from_string(const char *str);
1976 
1980 extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1981 
1985 extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1986 
1990 extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
1991 
1995 extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1996 
2001 extern size_t gbox_serialized_size(lwflags_t flags);
2002 
2006 extern int gbox_same(const GBOX *g1, const GBOX *g2);
2007 
2011 extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
2012 
2017 extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
2018 
2025 extern void gbox_float_round(GBOX *gbox);
2026 
2030 extern int gbox_is_valid(const GBOX *gbox);
2031 
2035 extern uint64_t gbox_get_sortable_hash(const GBOX *g, const int32_t srid);
2036 
2040 extern uint64_t gserialized_get_sortable_hash(const GSERIALIZED *g);
2041 
2046 extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
2047 
2055 #define LW_PARSER_CHECK_MINPOINTS 1
2056 #define LW_PARSER_CHECK_ODD 2
2057 #define LW_PARSER_CHECK_CLOSURE 4
2058 #define LW_PARSER_CHECK_ZCLOSURE 8
2059 
2060 #define LW_PARSER_CHECK_NONE 0
2061 #define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
2062 
2068 {
2069  const char *wkinput; /* Copy of pointer to input WKT/WKB */
2070  uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
2071  size_t size; /* Size of serialized LWGEOM in bytes */
2072  LWGEOM *geom; /* Pointer to LWGEOM struct */
2073  const char *message; /* Error/warning message */
2074  int errcode; /* Error/warning number */
2075  int errlocation; /* Location of error */
2076  int parser_check_flags; /* Bitmask of validity checks run during this parse */
2077 }
2079 
2080 /*
2081  * Parser error messages (these must match the message array in lwgparse.c)
2082  */
2083 #define PARSER_ERROR_MOREPOINTS 1
2084 #define PARSER_ERROR_ODDPOINTS 2
2085 #define PARSER_ERROR_UNCLOSED 3
2086 #define PARSER_ERROR_MIXDIMS 4
2087 #define PARSER_ERROR_INVALIDGEOM 5
2088 #define PARSER_ERROR_INVALIDWKBTYPE 6
2089 #define PARSER_ERROR_INCONTINUOUS 7
2090 #define PARSER_ERROR_TRIANGLEPOINTS 8
2091 #define PARSER_ERROR_LESSPOINTS 9
2092 #define PARSER_ERROR_OTHER 10
2093 
2094 
2095 
2096 /*
2097  * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
2098  */
2100 {
2101  uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
2102  char *wkoutput; /* Pointer to WKT or WKB output */
2103  size_t size; /* Size of serialized LWGEOM in bytes */
2104  const char *message; /* Error/warning message */
2105  int errlocation; /* Location of error */
2106 }
2108 
2109 /*
2110  * Unparser error messages (these must match the message array in lwgunparse.c)
2111  */
2112 #define UNPARSER_ERROR_MOREPOINTS 1
2113 #define UNPARSER_ERROR_ODDPOINTS 2
2114 #define UNPARSER_ERROR_UNCLOSED 3
2115 
2116 
2117 /*
2118 ** Variants available for WKB and WKT output types
2119 */
2120 
2121 #define WKB_ISO 0x01
2122 #define WKB_SFSQL 0x02
2123 #define WKB_EXTENDED 0x04
2124 #define WKB_NDR 0x08
2125 #define WKB_XDR 0x10
2126 #define WKB_HEX 0x20
2127 #define WKB_NO_NPOINTS 0x40 /* Internal use only */
2128 #define WKB_NO_SRID 0x80 /* Internal use only */
2129 
2130 #define WKT_ISO 0x01
2131 #define WKT_SFSQL 0x02
2132 #define WKT_EXTENDED 0x04
2133 
2134 
2135 /*
2136 ** Variants available for TWKB
2137 */
2138 #define TWKB_BBOX 0x01 /* User wants bboxes */
2139 #define TWKB_SIZE 0x02 /* User wants sizes */
2140 #define TWKB_ID 0x04 /* User wants id */
2141 #define TWKB_NO_TYPE 0x10 /* No type because it is a sub geometry */
2142 #define TWKB_NO_ID 0x20 /* No ID because it is a subgeometry */
2143 #define TWKB_DEFAULT_PRECISION 0 /* Aim for 1m (or ft) rounding by default */
2144 
2145 /*
2146 ** New parsing and unparsing functions.
2147 */
2148 
2153 extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2154 
2160 extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2161 
2167 extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2168 
2172 extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2173 
2179 extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2180 
2185 extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2186 
2190 extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2191 
2192 extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2193 
2194 extern char* hexbytes_from_bytes(const uint8_t *bytes, size_t size);
2195 
2196 /*
2197 * WKT detailed parsing support
2198 */
2199 extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2200 void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
2201 void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
2202 
2203 
2204 /* Memory management */
2205 extern void *lwalloc(size_t size);
2206 extern void *lwrealloc(void *mem, size_t size);
2207 extern void lwfree(void *mem);
2208 
2209 /* Utilities */
2210 extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2211 
2212 /*
2213 * TWKB functions
2214 */
2215 
2220 extern LWGEOM* lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check);
2221 
2227 extern uint8_t* lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size);
2228 
2229 extern uint8_t* lwgeom_to_twkb_with_idlist(const LWGEOM *geom, int64_t *idlist, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size);
2230 
2243 extern void lwgeom_trim_bits_in_place(LWGEOM *geom, int32_t prec_x, int32_t prec_y, int32_t prec_z, int32_t prec_m);
2244 
2245 /*******************************************************************************
2246  * SQLMM internal functions
2247  ******************************************************************************/
2248 
2249 int lwgeom_has_arc(const LWGEOM *geom);
2250 LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2251 LWGEOM *lwgeom_unstroke(const LWGEOM *geom);
2252 
2257 typedef enum {
2280 
2281 typedef enum {
2288 
2309 
2318 extern LWGEOM* lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags);
2319 
2320 /*******************************************************************************
2321  * GEOS proxy functions on LWGEOM
2322  ******************************************************************************/
2323 
2325 const char* lwgeom_geos_version(void);
2326 
2328 LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ;
2329 
2330 LWGEOM *lwgeom_normalize(const LWGEOM *geom);
2331 LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2332 LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2333 LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2334 LWGEOM *lwgeom_pointonsurface(const LWGEOM* geom);
2335 LWGEOM *lwgeom_centroid(const LWGEOM* geom);
2336 LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2337 LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2338 LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2339 LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2340 LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices);
2341 
2349 LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
2350 
2351 /*
2352  * Return the set of paths shared between two linear geometries,
2353  * and their direction (same or opposite).
2354  *
2355  * @param geom1 a lineal geometry
2356  * @param geom2 another lineal geometry
2357  */
2358 LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
2359 
2360 /*
2361  * An offset curve against the input line.
2362  *
2363  * @param geom a lineal geometry or collection of them
2364  * @param size offset distance. Offset left if negative and right if positive
2365  * @param quadsegs number of quadrature segments in curves (try 8)
2366  * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
2367  * @param mitreLimit (try 5.0)
2368  * @return derived geometry (linestring or multilinestring)
2369  *
2370  */
2371 LWGEOM* lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit);
2372 
2373 /*
2374  * Return true if the input geometry is "simple" as per OGC defn.
2375  *
2376  * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called
2377  * in that case)
2378  */
2379 int lwgeom_is_simple(const LWGEOM *lwgeom);
2380 
2381 
2382 /*******************************************************************************
2383  * PROJ4-dependent extra functions on LWGEOM
2384  ******************************************************************************/
2385 
2386 int lwgeom_transform_from_str(LWGEOM *geom, const char* instr, const char* outstr);
2387 
2388 #if POSTGIS_PROJ_VERSION < 60
2394 projPJ projpj_from_string(const char* txt);
2395 
2396 #endif
2402 int lwgeom_transform(LWGEOM *geom, LWPROJ* pj);
2403 int ptarray_transform(POINTARRAY *pa, LWPROJ* pj);
2404 
2405 #if POSTGIS_PROJ_VERSION >= 60
2406 
2412 LWPROJ *lwproj_from_PJ(PJ *pj, int8_t extra_geography_data);
2413 
2414 #endif
2415 
2416 
2417 /*******************************************************************************
2418  * GEOS-dependent extra functions on LWGEOM
2419  ******************************************************************************/
2420 
2428 LWGEOM* lwgeom_buildarea(const LWGEOM *geom) ;
2429 
2434 
2435 /*
2436  * Split (multi)polygon by line; (multi)line by (multi)line,
2437  * (multi)point or (multi)polygon boundary.
2438  *
2439  * Collections are accepted as first argument.
2440  * Returns all obtained pieces as a collection.
2441  */
2442 LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
2443 
2444 /*
2445  * Fully node a set of linestrings, using the least nodes preserving
2446  * all the input ones.
2447  */
2448 LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2449 
2459 LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly);
2460 
2470 LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2471 
2480 int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k);
2481 
2482 #include "lwinline.h"
2483 
2484 #endif /* !defined _LIBLWGEOM_H */
2485 
static uint8_t variant
Definition: cu_in_twkb.c:26
static uint8_t precision
Definition: cu_in_twkb.c:25
char * s
Definition: cu_in_wkt.c:23
char * r
Definition: cu_in_wkt.c:24
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoint.c:151
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition: lwgeom_api.c:624
LWPOLY * lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
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:1035
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:283
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:251
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:689
LW_LINEARIZE_TOLERANCE_TYPE
Semantic of the tolerance argument passed to lwcurve_linearize.
Definition: liblwgeom.h:2257
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_ANGLE
Tolerance expresses the maximum angle between the radii generating approximation line vertices,...
Definition: liblwgeom.h:2278
@ LW_LINEARIZE_TOLERANCE_TYPE_SEGS_PER_QUAD
Tolerance expresses the number of segments to use for each quarter of circle (quadrant).
Definition: liblwgeom.h:2263
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_DEVIATION
Tolerance expresses the maximum distance between an arbitrary point on the curve and the closest poin...
Definition: liblwgeom.h:2270
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:56
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition: lwgeom.c:306
LWPOINT * lwline_interpolate_point_3d(const LWLINE *line, double distance)
Interpolate one point along a line in 3D.
Definition: lwline.c:602
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where)
Definition: lwcircstring.c:286
LWCURVEPOLY * lwcurvepoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms)
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:946
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:297
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:108
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:321
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Simplification.
Definition: lwgeom.c:1848
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:573
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: gbox.c:164
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
Definition: gbox.c:135
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:670
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:291
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: lwgeom.c:937
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition: lwgeom.c:1114
LWORD_T
Ordinate names.
Definition: liblwgeom.h:144
@ LWORD_Z
Definition: liblwgeom.h:147
@ LWORD_M
Definition: liblwgeom.h:148
@ LWORD_Y
Definition: liblwgeom.h:146
@ LWORD_X
Definition: liblwgeom.h:145
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition: lwgeom_api.c:674
void(*) typedef void(*) voi lwgeom_set_handlers)(lwallocator allocator, lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, lwreporter noticereporter)
Install custom memory management and error handling functions you want your application to use.
size_t gbox_serialized_size(lwflags_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form.
Definition: gbox.c:440
void lwmpoly_release(LWMPOLY *lwpoly)
Definition: lwmpoly.c:34
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:909
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:261
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: gbox.c:433
LWPOINT * lwpoint_make4d(int32_t srid, double x, double y, double z, double m)
Definition: lwpoint.c:195
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:409
LWGEOM * lwgeom_locate_along(const LWGEOM *lwin, double m, double offset)
Determine the location(s) along a measured line where m occurs and return as a multipoint.
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2397
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1715
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:52
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing max distance calculation.
Definition: measures.c:165
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: gbox.c:179
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:2113
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:679
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2461
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition: gbox.c:80
LWPOINT * lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth)
Calculate the location of a point on a spheroid, give a start point, bearing and distance.
Definition: lwgeodetic.c:2099
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
Definition: liblwgeom.h:305
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
struct struct_lwgeom_unparser_result LWGEOM_UNPARSER_RESULT
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: gbox.c:97
uint8_t * lwgeom_to_twkb_with_idlist(const LWGEOM *geom, int64_t *idlist, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size)
Convert LWGEOM to a char* in TWKB format.
Definition: lwout_twkb.c:589
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length)
Derive a new geometry with vertices added to ensure no vertex is more than max_seg_length (in radians...
Definition: lwgeodetic.c:1743
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:242
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:177
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: gbox.c:247
LWGEOM * lwgeom_force_4d(const LWGEOM *geom)
Definition: lwgeom.c:793
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:849
int ptarray_transform(POINTARRAY *pa, LWPROJ *pj)
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: gserialized.c:126
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
Definition: lwgeom.c:1530
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:107
void lwgeom_trim_bits_in_place(LWGEOM *geom, int32_t prec_x, int32_t prec_y, int32_t prec_z, int32_t prec_m)
Trim the bits of an LWGEOM in place, to optimize it for compression.
Definition: lwgeom.c:2508
LWLINE * lwline_segmentize2d(const LWLINE *line, double dist)
Definition: lwline.c:132
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:228
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
void lwgeom_longitude_shift(LWGEOM *lwgeom)
Definition: lwgeom.c:990
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Definition: lwgeodetic.c:2187
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: gbox.c:774
POINTARRAY * ptarray_substring(POINTARRAY *pa, double d1, double d2, double tolerance)
@d1 start location (distance from start / total distance) @d2 end location (distance from start / tot...
Definition: ptarray.c:1058
LWCOLLECTION * lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist)
Definition: lwcollection.c:251
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
void lwpoint_release(LWPOINT *lwpoint)
Definition: lwpoint.c:256
int lwgeom_transform(LWGEOM *geom, LWPROJ *pj)
Transform (reproject) a geometry in-place.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:706
LWGEOM * lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags)
Definition: lwstroke.c:826
char * hexbytes_from_bytes(const uint8_t *bytes, size_t size)
Definition: lwout_wkb.c:39
double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfullywithin calculations.
Definition: measures3d.c:310
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1552
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
LWGEOM * lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm)
Definition: lwmval.c:221
LWPOINT * lwpoint_make3dm(int32_t srid, double x, double y, double m)
Definition: lwpoint.c:184
uint32_t gserialized_get_version(const GSERIALIZED *g)
Return the serialization version.
Definition: gserialized.c:42
void(* lwfreeor)(void *mem)
Definition: liblwgeom.h:258
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition: lwgeom.c:362
LWCURVEPOLY * lwcurvepoly_construct_from_lwpoly(LWPOLY *lwpoly)
Construct an equivalent curve polygon from a polygon.
Definition: lwcurvepoly.c:52
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition: lwtin.c:34
LWGEOM * lwgeom_unstroke(const LWGEOM *geom)
Definition: lwstroke.c:1259
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition: lwgeom.c:1908
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point.
Definition: lwiterator.c:210
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition: lwcompound.c:213
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition: lwgeom.c:644
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F)
Find interpolation point I between point A and point B so that the len(AI) == len(AB)*F and I falls o...
Definition: lwgeom_api.c:656
void lwtin_free(LWTIN *tin)
Definition: lwtin.c:39
LWGEOM * lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_twkb.c:654
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:114
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition: ptarray.c:553
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition: lwpoint.c:52
void printLWPOLY(LWPOLY *poly)
Definition: lwpoly.c:193
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:281
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition: lwgeom.c:753
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition: lwutil.c:171
double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt)
Find the measure value at the location on the line closest to the point.
POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:201
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:3028
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
Definition: gbox.c:228
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
Definition: ptarray.c:501
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
Definition: measures3d.c:82
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:88
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: gbox.c:53
int gserialized_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
Pull the first point values of a GSERIALIZED.
Definition: gserialized.c:257
uint16_t lwflags_t
Definition: liblwgeom.h:313
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: gserialized.c:174
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:286
unsigned int geohash_point_as_int(POINT2D *pt)
Definition: lwalgorithm.c:663
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:311
void lwline_release(LWLINE *lwline)
Definition: lwline.c:125
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:647
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition: lwstroke.c:859
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: gbox.c:740
int lwgeom_is_trajectory(const LWGEOM *geom)
Return LW_TRUE or LW_FALSE depending on whether or not a geometry is a linestring with measure value ...
Definition: lwgeom.c:2462
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
Definition: gbox.c:283
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:36
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:880
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:831
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition: lwutil.c:268
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
LWGEOM * lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:58
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
Definition: lwalgorithm.c:462
int lwgeom_is_simple(const LWGEOM *lwgeom)
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
int lwpointiterator_peek(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assigns the next point in the iterator to p.
Definition: lwiterator.c:193
void lwtin_release(LWTIN *lwtin)
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:626
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:44
void printPA(POINTARRAY *pa)
Definition: lwgeom_api.c:447
LWGEOM * lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision)
Create an LWGEOM object from an Encoded Polyline representation.
int lwgeom_check_geodetic(const LWGEOM *geom)
Check that coordinates of LWGEOM are all within the geodetic range (-180, -90, 180,...
Definition: lwgeodetic.c:3131
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:511
GBOX * gbox_new(lwflags_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: gbox.c:32
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:790
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition: lwin_wkb.c:92
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition: lwmline.c:46
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:267
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: gbox.c:323
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:247
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1303
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:242
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition: lwgeom.c:1554
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:349
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1387
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: gbox.c:40
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:51
double lwgeom_length(const LWGEOM *geom)
Definition: lwgeom.c:1930
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition: lwgeom.c:1454
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
Definition: gbox.c:115
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
Definition: lwgeom_api.c:39
const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims)
Access to the float bounding box, if there is one.
Definition: gserialized.c:248
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: gserialized.c:138
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1191
LWMLINE * lwmline_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwmline.c:38
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: gserialized.c:65
LWGEOM * lwgeom_reverse(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
LWMPOINT * lwpoly_to_points(const LWPOLY *poly, uint32_t npoints, int32_t seed)
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition: ptarray.c:1700
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition: lwgeom.c:271
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
Definition: lwgeodetic.c:2413
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:916
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:276
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition: lwgeom.c:1087
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:547
void printBOX3D(BOX3D *b)
Definition: lwgeom_api.c:441
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:664
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition: lwgeom.c:2529
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:248
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Utility function to get type number from string.
Definition: lwutil.c:489
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:2029
LWTRIANGLE * lwtriangle_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwtriangle.c:58
LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell)
Definition: lwtriangle.c:153
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:166
double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist)
Find the time of closest point of approach.
void lwmline_release(LWMLINE *lwline)
Definition: lwmline.c:32
LWGEOM * lwgeom_pointonsurface(const LWGEOM *geom)
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition: gbox.c:239
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
Definition: lwalgorithm.c:282
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
void(* lwreporter)(const char *fmt, va_list ap) __attribute__((format(printf
Definition: liblwgeom.h:259
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1863
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition: lwgeom.c:233
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:47
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
Definition: ptarray.c:85
LWPOLY * lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2)
Definition: lwpoly.c:98
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition: lwpsurface.c:33
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:716
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1229
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
Definition: lwalgorithm.c:861
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
Definition: gserialized.c:196
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition: gbox.c:601
void printLWTIN(LWTIN *tin)
Definition: lwtin.c:57
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:213
LW_LINEARIZE_FLAGS
Definition: liblwgeom.h:2281
@ LW_LINEARIZE_FLAG_SYMMETRIC
Symmetric linearization means that the output vertices would be the same no matter the order of the p...
Definition: liblwgeom.h:2287
@ LW_LINEARIZE_FLAG_RETAIN_ANGLE
Retain angle instructs the engine to try its best to retain the requested angle between generating ra...
Definition: liblwgeom.h:2307
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
Definition: measures3d.c:1032
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:215
int lwpointiterator_modify_next(LWPOINTITERATOR *s, const POINT4D *p)
Attempts to replace the next point int the iterator with p, and advances the iterator to the next poi...
Definition: lwiterator.c:224
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition: lwline.c:525
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:1281
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices)
Definition: lwgeom.c:2439
LWGEOM * lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint)
Definition: lwchaikins.c:182
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
Definition: lwpoint.c:47
uint64_t gbox_get_sortable_hash(const GBOX *g, const int32_t srid)
Return a sortable key based on the center point of the GBOX.
Definition: gbox.c:893
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
Definition: lwhomogenize.c:208
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:326
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:207
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:402
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
Definition: lwgeodetic.c:2889
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1079
LWPOINT * lwpoint_make3dz(int32_t srid, double x, double y, double z)
Definition: lwpoint.c:173
void lwcircstring_free(LWCIRCSTRING *curve)
Definition: lwcircstring.c:97
LWMPOINT * lwmpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwmpoint.c:39
uint64_t gserialized_get_sortable_hash(const GSERIALIZED *g)
Return a sortable key based on gserialized.
Definition: gserialized.c:391
double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
Definition: measures3d.c:442
int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: gserialized.c:77
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1461
int lwgeom_transform_from_str(LWGEOM *geom, const char *instr, const char *outstr)
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1975
LWCOLLECTION * lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset)
Given a geometry clip based on the from/to range of one of its ordinates (x, y, z,...
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition: gserialized.c:207
LWMPOINT * lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints, int32_t seed)
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:40
uint8_t lwtype_multitype(uint8_t type)
Definition: lwgeom.c:352
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
#define __attribute__(x)
Definition: liblwgeom.h:242
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
void lwtriangle_free(LWTRIANGLE *triangle)
Definition: lwtriangle.c:69
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:71
void *(* lwreallocator)(void *mem, size_t size)
Definition: liblwgeom.h:257
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:188
LWPOINTITERATOR * lwpointiterator_create_rw(LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM* Supports modification of coordinates during iterat...
Definition: lwiterator.c:251
CG_LINE_CROSS_TYPE
The return values of lwline_crossing_direction()
Definition: liblwgeom.h:1623
@ LINE_MULTICROSS_END_RIGHT
Definition: liblwgeom.h:1628
@ LINE_MULTICROSS_END_SAME_FIRST_LEFT
Definition: liblwgeom.h:1629
@ LINE_MULTICROSS_END_LEFT
Definition: liblwgeom.h:1627
@ LINE_CROSS_LEFT
Definition: liblwgeom.h:1625
@ LINE_MULTICROSS_END_SAME_FIRST_RIGHT
Definition: liblwgeom.h:1630
@ LINE_CROSS_RIGHT
Definition: liblwgeom.h:1626
@ LINE_NO_CROSS
Definition: liblwgeom.h:1624
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition: liblwgeom.h:256
void lwcollection_release(LWCOLLECTION *lwcollection)
Definition: lwcollection.c:36
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
LWPROJ * lwproj_from_PJ(PJ *pj, int8_t extra_geography_data)
Allocate a new LWPROJ containing the reference to the PROJ's PJ If extra_geography_data is true,...
GSERIALIZED * gserialized_set_gbox(GSERIALIZED *g, GBOX *gbox)
Copy a new bounding box into an existing gserialized.
Definition: gserialized.c:31
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:874
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: gserialized.c:185
double lwgeom_length_2d(const LWGEOM *geom)
Definition: lwgeom.c:1952
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition: lwgeom.c:1339
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3222
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
Definition: measures.c:197
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:719
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition: lwprint.c:428
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:187
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
Definition: lwgeom.c:37
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: gserialized.c:163
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:357
void printLWLINE(LWLINE *line)
Definition: lwline.c:79
int lwgeom_is_solid(const LWGEOM *geom)
Return LW_TRUE if geometry has SOLID flag.
Definition: lwgeom.c:930
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: gserialized.c:101
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition: gbox.c:364
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
int lwcollection_ngeoms(const LWCOLLECTION *col)
Definition: lwcollection.c:319
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2407
LWCOLLECTION * lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset)
Determine the segments along a measured line that fall within the m-range given.
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
Definition: lwline.c:275
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:3404
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom)
Definition: lwgeom.c:787
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:725
GSERIALIZED * gserialized_drop_gbox(GSERIALIZED *g)
Remove the bounding box from a GSERIALIZED.
Definition: gserialized.c:52
void lwcircstring_release(LWCIRCSTRING *lwcirc)
Definition: lwcircstring.c:91
LWGEOM * lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area)
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition: lwgeom.c:266
LWPOLY * lwpoly_segmentize2d(const LWPOLY *line, double dist)
Definition: lwpoly.c:312
POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:335
LWGEOM * lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj)
Definition: lwgeom.c:301
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition: lwgeom.c:259
void lwpoly_release(LWPOLY *lwpoly)
Definition: lwpoly.c:306
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:473
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:737
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition: lwgeom.c:296
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:198
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition: lwgeom.c:251
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:364
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:905
LWCOLLECTION * lwcollection_concat_in_place(LWCOLLECTION *col1, const LWCOLLECTION *col2)
Appends all geometries from col2 to col1 in place.
Definition: lwcollection.c:241
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:147
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition: lwmpoint.c:93
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:387
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
Definition: lwgeom_box3d.c:336
void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox)
Compute a box for geom and all sub-geometries, if not already computed.
Definition: lwgeom.c:696
int lwpointiterator_has_next(LWPOINTITERATOR *s)
Returns LW_TRUE if there is another point available in the iterator.
Definition: lwiterator.c:202
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:188
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3297
LWPOINT * lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged)
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
LWGEOM * lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:46
void printLWPOINT(LWPOINT *point)
Definition: lwpoint.c:224
void * lwalloc(size_t size)
Definition: lwutil.c:227
int lwgeom_dimensionality(const LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1409
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:489
LWCOMPOUND * lwcompound_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwcompound.c:123
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:42
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition: lwcompound.c:88
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:693
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfullywithin calculations.
Definition: measures.c:177
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:215
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:379
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:316
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:169
void lwpsurface_free(LWPSURFACE *psurf)
Definition: lwpsurface.c:39
float next_float_up(double d)
Definition: lwgeom_api.c:75
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:175
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition: lwutil.c:471
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed)
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:89
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
void lwpsurface_release(LWPSURFACE *lwpsurface)
int lwline_is_trajectory(const LWLINE *geom)
Definition: lwline.c:454
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition: lwtriangle.c:82
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:197
int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point)
Definition: lwgeom_api.c:268
double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d max distance calculation.
Definition: measures3d.c:300
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
Definition: lwout_gml.c:231
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: gbox.c:187
LWMLINE * lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end)
Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure betwe...
Definition: lwmline.c:56
LWCURVEPOLY * lwcurvepoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwcurvepoly.c:35
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:450
double lwgeom_perimeter(const LWGEOM *geom)
Definition: lwgeom.c:1886
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:49
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:360
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_wkb.c:825
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:923
struct LWPROJ LWPROJ
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
Definition: gbox.c:197
struct gridspec_t gridspec
Snap-to-grid.
LWCOMPOUND * lwcompound_construct_from_lwline(const LWLINE *lwpoly)
Construct an equivalent compound curve from a linestring.
Definition: lwcompound.c:204
double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid)
Calculate the bearing between two points on a spheroid.
Definition: lwgeodetic.c:2156
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: gserialized.c:222
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
lwflags_t gserialized_get_lwflags(const GSERIALIZED *g)
Read standard lwflags from gserialized.
Definition: gserialized.c:18
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwgeom.c:2083
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition: lwgeom.c:781
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2245
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:65
LWCIRCSTRING * lwcircstring_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwcircstring.c:79
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:376
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:347
LWMPOINT * lwmpoint_construct(int32_t srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
int32_t gserialized_hash(const GSERIALIZED *g)
Returns a hash code for the srid/type/geometry information in the GSERIALIZED.
Definition: gserialized.c:114
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition: ptarray.c:595
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition: lwpoint.c:40
LWMPOLY * lwmpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwmpoly.c:40
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:677
float next_float_down(double d)
Definition: lwgeom_api.c:54
void lwline_free(LWLINE *line)
Definition: lwline.c:67
int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2)
Return -1 if g1 is "less than" g2, 1 if g1 is "greater than" g2 and 0 if g1 and g2 are the "same".
Definition: gserialized.c:313
LWCIRCSTRING * lwcircstring_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:50
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:360
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwline.c:55
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:886
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
Definition: gbox.c:339
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:151
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:405
int lwgeom_has_arc(const LWGEOM *geom)
Definition: lwstroke.c:55
int32_t clamp_srid(int32_t srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition: lwutil.c:333
void lwmpoint_release(LWMPOINT *lwpoint)
Definition: lwmpoint.c:33
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: gbox.c:392
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition: lwcompound.c:254
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition: lwtriangle.c:119
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:2031
int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition: lwkmeans.c:244
void printLWPSURFACE(LWPSURFACE *psurf)
Definition: lwpsurface.c:57
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures3d.c:76
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:775
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
Definition: lwline.c:327
int getPoint2d_p_ro(const POINTARRAY *pa, uint32_t n, POINT2D **point)
New function to read doubles directly from the double* coordinate array of an aligned lwgeom POINTARR...
Definition: lwgeodetic.c:2875
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition: lwgeom.c:747
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2144
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:680
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition: lwgeom.c:102
uint8_t * lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size)
Definition: lwout_twkb.c:636
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition: measures3d.c:335
int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
Is the closest point of approach within a distance ?
int gbox_merge(const GBOX *new_box, GBOX *merged_box)
Update the merged GBOX to be large enough to include itself and the new box.
Definition: gbox.c:257
LWPOINT * lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
enum LWORD_T LWORD
Ordinate names.
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:309
#define str(s)
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
int value
Definition: genraster.py:62
opts
Definition: ovdump.py:45
type
Definition: ovdump.py:42
data
Definition: ovdump.py:104
def fmt
Definition: pixval.py:93
double afac
Definition: liblwgeom.h:318
double xmax
Definition: liblwgeom.h:326
double xmin
Definition: liblwgeom.h:325
int32_t srid
Definition: liblwgeom.h:327
double ymax
Definition: liblwgeom.h:343
double zmax
Definition: liblwgeom.h:345
double xmax
Definition: liblwgeom.h:341
double zmin
Definition: liblwgeom.h:344
double mmax
Definition: liblwgeom.h:347
double ymin
Definition: liblwgeom.h:342
double xmin
Definition: liblwgeom.h:340
double mmin
Definition: liblwgeom.h:346
lwflags_t flags
Definition: liblwgeom.h:339
uint32_t size
Definition: liblwgeom.h:430
uint8_t gflags
Definition: liblwgeom.h:432
POINT2D * center
Definition: liblwgeom.h:1756
uint8_t type
Definition: liblwgeom.h:496
int32_t srid
Definition: liblwgeom.h:494
lwflags_t flags
Definition: liblwgeom.h:495
POINTARRAY * points
Definition: liblwgeom.h:493
GBOX * bbox
Definition: liblwgeom.h:492
lwflags_t flags
Definition: liblwgeom.h:563
uint32_t ngeoms
Definition: liblwgeom.h:566
uint32_t maxgeoms
Definition: liblwgeom.h:567
uint8_t type
Definition: liblwgeom.h:564
GBOX * bbox
Definition: liblwgeom.h:560
LWGEOM ** geoms
Definition: liblwgeom.h:561
int32_t srid
Definition: liblwgeom.h:562
uint32_t maxgeoms
Definition: liblwgeom.h:581
lwflags_t flags
Definition: liblwgeom.h:577
int32_t srid
Definition: liblwgeom.h:576
GBOX * bbox
Definition: liblwgeom.h:574
uint32_t ngeoms
Definition: liblwgeom.h:580
uint8_t type
Definition: liblwgeom.h:578
LWGEOM ** geoms
Definition: liblwgeom.h:575
int32_t srid
Definition: liblwgeom.h:590
GBOX * bbox
Definition: liblwgeom.h:588
uint8_t type
Definition: liblwgeom.h:592
LWGEOM ** rings
Definition: liblwgeom.h:589
lwflags_t flags
Definition: liblwgeom.h:591
uint32_t nrings
Definition: liblwgeom.h:594
uint32_t maxrings
Definition: liblwgeom.h:595
void * data
Definition: liblwgeom.h:445
uint8_t type
Definition: liblwgeom.h:448
GBOX * bbox
Definition: liblwgeom.h:444
int32_t srid
Definition: liblwgeom.h:446
lwflags_t flags
Definition: liblwgeom.h:447
lwflags_t flags
Definition: liblwgeom.h:471
GBOX * bbox
Definition: liblwgeom.h:468
POINTARRAY * points
Definition: liblwgeom.h:469
uint8_t type
Definition: liblwgeom.h:472
int32_t srid
Definition: liblwgeom.h:470
uint32_t maxgeoms
Definition: liblwgeom.h:609
LWGEOM ** geoms
Definition: liblwgeom.h:603
GBOX * bbox
Definition: liblwgeom.h:602
lwflags_t flags
Definition: liblwgeom.h:605
uint32_t ngeoms
Definition: liblwgeom.h:608
int32_t srid
Definition: liblwgeom.h:604
uint8_t type
Definition: liblwgeom.h:606
uint32_t maxgeoms
Definition: liblwgeom.h:539
lwflags_t flags
Definition: liblwgeom.h:535
GBOX * bbox
Definition: liblwgeom.h:532
int32_t srid
Definition: liblwgeom.h:534
LWLINE ** geoms
Definition: liblwgeom.h:533
uint8_t type
Definition: liblwgeom.h:536
uint32_t ngeoms
Definition: liblwgeom.h:538
uint32_t maxgeoms
Definition: liblwgeom.h:525
int32_t srid
Definition: liblwgeom.h:520
GBOX * bbox
Definition: liblwgeom.h:518
lwflags_t flags
Definition: liblwgeom.h:521
uint32_t ngeoms
Definition: liblwgeom.h:524
LWPOINT ** geoms
Definition: liblwgeom.h:519
uint8_t type
Definition: liblwgeom.h:522
uint8_t type
Definition: liblwgeom.h:550
GBOX * bbox
Definition: liblwgeom.h:546
uint32_t maxgeoms
Definition: liblwgeom.h:553
uint32_t ngeoms
Definition: liblwgeom.h:552
LWPOLY ** geoms
Definition: liblwgeom.h:547
lwflags_t flags
Definition: liblwgeom.h:549
int32_t srid
Definition: liblwgeom.h:548
uint8_t type
Definition: liblwgeom.h:620
int32_t srid
Definition: liblwgeom.h:618
uint32_t maxgeoms
Definition: liblwgeom.h:623
GBOX * bbox
Definition: liblwgeom.h:616
uint32_t ngeoms
Definition: liblwgeom.h:622
lwflags_t flags
Definition: liblwgeom.h:619
LWGEOM ** geoms
Definition: liblwgeom.h:617
POINTARRAY * point
Definition: liblwgeom.h:457
uint8_t type
Definition: liblwgeom.h:460
lwflags_t flags
Definition: liblwgeom.h:459
GBOX * bbox
Definition: liblwgeom.h:456
int32_t srid
Definition: liblwgeom.h:458
POINTARRAY ** rings
Definition: liblwgeom.h:505
uint8_t type
Definition: liblwgeom.h:508
uint32_t maxrings
Definition: liblwgeom.h:511
uint32_t nrings
Definition: liblwgeom.h:510
GBOX * bbox
Definition: liblwgeom.h:504
lwflags_t flags
Definition: liblwgeom.h:507
int32_t srid
Definition: liblwgeom.h:506
uint8_t source_is_latlong
Definition: liblwgeom.h:61
uint8_t source_swapped
Definition: liblwgeom.h:58
uint8_t target_swapped
Definition: liblwgeom.h:59
double source_semi_major_metre
Definition: liblwgeom.h:64
double source_semi_minor_metre
Definition: liblwgeom.h:65
PJ * pj
Definition: liblwgeom.h:56
lwflags_t flags
Definition: liblwgeom.h:633
uint32_t maxgeoms
Definition: liblwgeom.h:637
LWPOLY ** geoms
Definition: liblwgeom.h:631
uint32_t ngeoms
Definition: liblwgeom.h:636
uint8_t type
Definition: liblwgeom.h:634
int32_t srid
Definition: liblwgeom.h:632
GBOX * bbox
Definition: liblwgeom.h:630
uint32_t ngeoms
Definition: liblwgeom.h:650
int32_t srid
Definition: liblwgeom.h:646
uint8_t type
Definition: liblwgeom.h:648
lwflags_t flags
Definition: liblwgeom.h:647
LWTRIANGLE ** geoms
Definition: liblwgeom.h:645
uint32_t maxgeoms
Definition: liblwgeom.h:651
GBOX * bbox
Definition: liblwgeom.h:644
int32_t srid
Definition: liblwgeom.h:482
uint8_t type
Definition: liblwgeom.h:484
GBOX * bbox
Definition: liblwgeom.h:480
lwflags_t flags
Definition: liblwgeom.h:483
POINTARRAY * points
Definition: liblwgeom.h:481
double x
Definition: liblwgeom.h:376
double m
Definition: liblwgeom.h:394
double x
Definition: liblwgeom.h:382
double x
Definition: liblwgeom.h:388
double m
Definition: liblwgeom.h:400
lwflags_t flags
Definition: liblwgeom.h:417
uint32_t maxpoints
Definition: liblwgeom.h:414
uint32_t npoints
Definition: liblwgeom.h:413
uint8_t * serialized_pointlist
Definition: liblwgeom.h:420
double e_sq
Definition: liblwgeom.h:365
double e
Definition: liblwgeom.h:364
double radius
Definition: liblwgeom.h:366
double a
Definition: liblwgeom.h:361
double b
Definition: liblwgeom.h:362
double f
Definition: liblwgeom.h:363
double ipm
Definition: liblwgeom.h:1345
double zsize
Definition: liblwgeom.h:1348
double ysize
Definition: liblwgeom.h:1347
double xsize
Definition: liblwgeom.h:1346
double ipx
Definition: liblwgeom.h:1342
double msize
Definition: liblwgeom.h:1349
double ipy
Definition: liblwgeom.h:1343
double ipz
Definition: liblwgeom.h:1344
Snap-to-grid.
Definition: liblwgeom.h:1341
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
Definition: liblwgeom.h:2068