PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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"
40typedef struct PJ
41{
42 projPJ pj_from;
43 projPJ pj_to;
44} PJ;
45
46typedef 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 */
54typedef struct LWPROJ
55{
56 PJ* pj;
57 /* CRSs are swapped: Used in transformation calls */
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
102const 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
144typedef enum LWORD_T {
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
251extern int32_t clamp_srid(int32_t srid);
252
256typedef void* (*lwallocator)(size_t size);
257typedef void* (*lwreallocator)(void *mem, size_t size);
258typedef void (*lwfreeor)(void* mem);
259typedef void (*lwreporter)(const char* fmt, va_list ap)
260 __attribute__ (( format(printf, 1, 0) ));
261typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
262 __attribute__ (( format(printf, 2,0) ));
263
270extern void lwgeom_set_handlers(lwallocator allocator,
271 lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
272 lwreporter noticereporter);
273
274extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
275
288extern void lwgeom_request_interrupt(void);
289
293extern void lwgeom_cancel_interrupt(void);
294
305typedef void (lwinterrupt_callback)();
307
308
309/******************************************************************
310* LWGEOM and GBOX both use LWFLAGS bit mask.
311* Serializations (may) use different bit mask schemes.
312*/
313typedef uint16_t lwflags_t;
314
315/******************************************************************/
316
317typedef struct {
318 double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
319} AFFINE;
320
321/******************************************************************/
322
323typedef struct
324{
325 double xmin, ymin, zmin;
326 double xmax, ymax, zmax;
327 int32_t srid;
328}
329BOX3D;
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*/
337typedef 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*/
359typedef 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}
370
371/******************************************************************
372* POINT2D, POINT3D, POINT3DM, POINT4D
373*/
374typedef struct
375{
376 double x, y;
377}
378POINT2D;
379
380typedef struct
381{
382 double x, y, z;
383}
385
386typedef struct
387{
388 double x, y, z;
389}
390POINT3D;
391
392typedef struct
393{
394 double x, y, m;
395}
397
398typedef struct
399{
400 double x, y, z, m;
401}
402POINT4D;
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*/
411typedef 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}
423
424/******************************************************************
425* GSERIALIZED
426*/
427
428typedef 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 */
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*/
442typedef struct
443{
445 void *data;
446 int32_t srid;
448 uint8_t type;
449 char pad[1]; /* Padding to 24 bytes (unused) */
450}
451LWGEOM;
452
453/* POINTYPE */
454typedef 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}
463LWPOINT; /* "light-weight point" */
464
465/* LINETYPE */
466typedef 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}
475LWLINE; /* "light-weight line" */
476
477/* TRIANGLE */
478typedef struct
479{
482 int32_t srid;
484 uint8_t type;
485 char pad[1]; /* Padding to 24 bytes (unused) */
486}
488
489/* CIRCSTRINGTYPE */
490typedef 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}
499LWCIRCSTRING; /* "light-weight circularstring" */
500
501/* POLYGONTYPE */
502typedef 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}
513LWPOLY; /* "light-weight polygon" */
514
515/* MULTIPOINTTYPE */
516typedef 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}
528
529/* MULTILINETYPE */
530typedef 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}
541LWMLINE;
542
543/* MULTIPOLYGONTYPE */
544typedef 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}
555LWMPOLY;
556
557/* COLLECTIONTYPE */
558typedef 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 */
572typedef 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}
583LWCOMPOUND; /* "light-weight compound line" */
584
585/* CURVEPOLYTYPE */
586typedef 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}
597LWCURVEPOLY; /* "light-weight polygon" */
598
599/* MULTICURVE */
600typedef 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}
612
613/* MULTISURFACETYPE */
614typedef 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}
626
627/* POLYHEDRALSURFACETYPE */
628typedef 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}
640
641/* TINTYPE */
642typedef 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}
653LWTIN;
654
655/* Casts LWGEOM->LW* (return NULL if cast is illegal) */
656extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
657extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
658extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
659extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
660extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
661extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
662
663extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
664extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
665extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
666extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
667extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
668extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
669extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
670extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
671
672/* Casts LW*->LWGEOM (always cast) */
673extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
674extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
675extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
676extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
677extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
678extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
679extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
680extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
681extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
682extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
683extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
684extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
685extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
686
687
689extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
690extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
691extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
692extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
693extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
694
696
700extern lwflags_t lwflags(int hasz, int hasm, int geodetic);
701
702
703
704/***********************************************************************
705** GSERIALIZED API
706*/
707
712
717extern const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims);
718
723extern uint32_t gserialized_get_type(const GSERIALIZED *g);
724
729extern uint32_t gserialized_max_header_size(void);
730
736extern int32_t gserialized_hash(const GSERIALIZED *g);
737
742extern int32_t gserialized_get_srid(const GSERIALIZED *g);
743
748extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
749
756extern int gserialized_is_empty(const GSERIALIZED *g);
757
761extern int gserialized_has_bbox(const GSERIALIZED *gser);
762
766extern int gserialized_has_z(const GSERIALIZED *gser);
767
771extern int gserialized_has_m(const GSERIALIZED *gser);
772
776extern int gserialized_is_geodetic(const GSERIALIZED *gser);
777
781extern int gserialized_ndims(const GSERIALIZED *gser);
782
792extern int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2);
793
801extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
802
808
814extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box);
815
820extern int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box);
821
828
834
838extern uint32_t gserialized_get_version(const GSERIALIZED *g);
839
843extern int gserialized_peek_first_point(const GSERIALIZED *g, POINT4D *out_point);
844
845/*****************************************************************************/
846
847
854extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
855extern void lwgeom_drop_srid(LWGEOM *lwgeom);
856
863extern void lwgeom_add_bbox(LWGEOM *lwgeom);
867extern void lwgeom_refresh_bbox(LWGEOM *lwgeom);
871extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
872
880extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
881
885extern int lwgeom_is_collection(const LWGEOM *lwgeom);
886
890extern int lwgeom_isfinite(const LWGEOM *lwgeom);
891
892
893/******************************************************************/
894/* Functions that work on type numbers */
895
899extern int lwtype_is_collection(uint8_t type);
900
904extern uint32_t lwtype_get_collectiontype(uint8_t type);
905
910extern const char *lwtype_name(uint8_t type);
911extern 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 */
921extern 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 */
929extern 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 */
936extern POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n);
937extern 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 */
944extern int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point);
945extern 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 */
953extern 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 */
960extern 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 */
970extern void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d);
971
977extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
978
982extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
983
987extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
988
994extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
995
1001extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
1002
1014extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
1015
1020extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where);
1021
1026extern int ptarray_remove_point(POINTARRAY *pa, uint32_t where);
1027
1039extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
1040
1046extern POINTARRAY *ptarray_removePoint(POINTARRAY *pa, uint32_t where);
1047
1054extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
1055
1056extern int ptarray_is_closed(const POINTARRAY *pa);
1057extern int ptarray_is_closed_2d(const POINTARRAY *pa);
1058extern int ptarray_is_closed_3d(const POINTARRAY *pa);
1059extern int ptarray_is_closed_z(const POINTARRAY *pa);
1061
1067extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
1068 double tolerance);
1069
1070
1074extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
1075extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom);
1076extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom);
1077extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom);
1078
1079extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
1080extern LWGEOM* lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint);
1081extern 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 */
1087extern 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 */
1099extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
1100extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
1101extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
1102extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
1103
1104/******************************************************************
1105 * LWLINE functions
1106 ******************************************************************/
1107
1111extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1112
1116extern POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat);
1117
1121extern LWPOINT* lwline_interpolate_point_3d(const LWLINE *line, double distance);
1122
1123/******************************************************************
1124 * LWPOLY functions
1125 ******************************************************************/
1126
1131extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1132
1137extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1138
1143extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1144
1150
1156
1157
1158/******************************************************************
1159 * LWGEOM functions
1160 ******************************************************************/
1161
1162extern 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 * */
1170extern 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
1193extern 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
1203extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1204extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1205
1206void 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
1221extern void ptarray_free(POINTARRAY *pa);
1222extern void lwpoint_free(LWPOINT *pt);
1223extern void lwline_free(LWLINE *line);
1224extern void lwpoly_free(LWPOLY *poly);
1225extern void lwtriangle_free(LWTRIANGLE *triangle);
1226extern void lwmpoint_free(LWMPOINT *mpt);
1227extern void lwmline_free(LWMLINE *mline);
1228extern void lwmpoly_free(LWMPOLY *mpoly);
1229extern void lwpsurface_free(LWPSURFACE *psurf);
1230extern void lwtin_free(LWTIN *tin);
1231extern void lwcollection_free(LWCOLLECTION *col);
1232extern void lwcircstring_free(LWCIRCSTRING *curve);
1233extern 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
1242extern void lwpoint_release(LWPOINT *lwpoint);
1243extern void lwline_release(LWLINE *lwline);
1244extern void lwpoly_release(LWPOLY *lwpoly);
1245extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1246extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1247extern void lwmpoint_release(LWMPOINT *lwpoint);
1248extern void lwmline_release(LWMLINE *lwline);
1249extern void lwmpoly_release(LWMPOLY *lwpoly);
1250extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1251extern void lwtin_release(LWTIN *lwtin);
1252extern void lwcollection_release(LWCOLLECTION *lwcollection);
1253extern void lwgeom_release(LWGEOM *lwgeom);
1254
1255
1256/****************************************************************
1257* Utility
1258****************************************************************/
1259
1260extern void printBOX3D(BOX3D *b);
1261extern void printPA(POINTARRAY *pa);
1262extern void printLWPOINT(LWPOINT *point);
1263extern void printLWLINE(LWLINE *line);
1264extern void printLWPOLY(LWPOLY *poly);
1265extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1266extern void printLWPSURFACE(LWPSURFACE *psurf);
1267extern void printLWTIN(LWTIN *tin);
1268
1269extern float next_float_down(double d);
1270extern float next_float_up(double d);
1271
1272/* general utilities 2D */
1273extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1274extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1275extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1276extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1277extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1278extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1279extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1280extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1281extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1282extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1283
1284/* 3D */
1285extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1286extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1287
1288extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1289extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1290extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1291
1292
1293extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1294extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1295extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1296extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1297
1298extern double lwgeom_area(const LWGEOM *geom);
1299extern double lwgeom_length(const LWGEOM *geom);
1300extern double lwgeom_length_2d(const LWGEOM *geom);
1301extern double lwgeom_perimeter(const LWGEOM *geom);
1302extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1303extern int lwgeom_dimension(const LWGEOM *geom);
1304
1305extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, uint32_t where);
1306extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where);
1307
1308extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1309extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1310extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where);
1311
1312extern double ptarray_length_2d(const POINTARRAY *pts);
1313extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1314extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1315extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1316
1317extern LWGEOM* lwgeom_reverse(const LWGEOM *lwgeom);
1318extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1319extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1320extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1321
1322extern void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F);
1323
1328extern int lwgeom_is_clockwise(LWGEOM *lwgeom);
1329
1330
1334extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
1335extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1336
1340typedef 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
1353extern LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid);
1354extern 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
1367extern void lwgeom_reverse_in_place(LWGEOM *lwgeom);
1368extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1369extern void lwgeom_longitude_shift(LWGEOM *lwgeom);
1370extern int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed);
1371extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1372extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1373extern int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance);
1374
1375
1388LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1389
1390
1400extern int lwgeom_needs_bbox(const LWGEOM *geom);
1401
1405extern uint32_t lwgeom_count_vertices(const LWGEOM *geom);
1406
1411extern uint32_t lwgeom_count_rings(const LWGEOM *geom);
1412
1417extern int lwgeom_has_srid(const LWGEOM *geom);
1418
1423extern int lwgeom_is_closed(const LWGEOM *geom);
1424
1428extern int lwgeom_dimensionality(const LWGEOM *geom);
1429
1430/* Is lwgeom1 geometrically equal to lwgeom2 ? */
1431extern char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1432
1433
1441extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1442
1446extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1447extern 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*/
1455extern LWPOINT* lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point);
1456extern LWMPOINT *lwmpoint_construct(int32_t srid, const POINTARRAY *pa);
1457extern LWLINE* lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1458extern LWCIRCSTRING* lwcircstring_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1459extern LWPOLY* lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1460extern LWCURVEPOLY* lwcurvepoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1461extern LWTRIANGLE* lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1462extern LWCOLLECTION* lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1463/*
1464* Empty geometry constructors.
1465*/
1466extern LWGEOM* lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm);
1467extern LWPOINT* lwpoint_construct_empty(int32_t srid, char hasz, char hasm);
1468extern LWLINE* lwline_construct_empty(int32_t srid, char hasz, char hasm);
1469extern LWPOLY* lwpoly_construct_empty(int32_t srid, char hasz, char hasm);
1470extern LWCURVEPOLY* lwcurvepoly_construct_empty(int32_t srid, char hasz, char hasm);
1471extern LWCIRCSTRING* lwcircstring_construct_empty(int32_t srid, char hasz, char hasm);
1472extern LWCOMPOUND* lwcompound_construct_empty(int32_t srid, char hasz, char hasm);
1473extern LWTRIANGLE* lwtriangle_construct_empty(int32_t srid, char hasz, char hasm);
1474extern LWMPOINT* lwmpoint_construct_empty(int32_t srid, char hasz, char hasm);
1475extern LWMLINE* lwmline_construct_empty(int32_t srid, char hasz, char hasm);
1476extern LWMPOLY* lwmpoly_construct_empty(int32_t srid, char hasz, char hasm);
1477extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm);
1478
1479
1480/* Other constructors */
1481extern LWPOINT *lwpoint_make2d(int32_t srid, double x, double y);
1482extern LWPOINT *lwpoint_make3dz(int32_t srid, double x, double y, double z);
1483extern LWPOINT *lwpoint_make3dm(int32_t srid, double x, double y, double m);
1484extern LWPOINT *lwpoint_make4d(int32_t srid, double x, double y, double z, double m);
1485extern LWPOINT *lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p);
1486extern LWLINE *lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms);
1487extern LWLINE *lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1488extern LWLINE *lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint);
1489extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1490extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1491extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1492extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1493extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1494extern LWPOLY *lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2);
1495extern LWPOLY *lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1496extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1497extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1498
1499/* Some point accessors */
1500extern double lwpoint_get_x(const LWPOINT *point);
1501extern double lwpoint_get_y(const LWPOINT *point);
1502extern double lwpoint_get_z(const LWPOINT *point);
1503extern double lwpoint_get_m(const LWPOINT *point);
1504
1508extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1509
1513extern int lwgeom_has_z(const LWGEOM *geom);
1514
1518extern int lwgeom_has_m(const LWGEOM *geom);
1519
1523extern int lwgeom_is_solid(const LWGEOM *geom);
1524
1528extern 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 */
1537extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1538
1543extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1544extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1545
1550extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1551
1557extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1558
1562extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1563
1574extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1575
1581extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1582
1587extern int lwgeom_is_trajectory(const LWGEOM *geom);
1588extern 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 */
1594extern LWGEOM *lwgeom_segmentize2d(const LWGEOM *line, double dist);
1595extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1596extern LWLINE *lwline_segmentize2d(const LWLINE *line, double dist);
1597extern LWPOLY *lwpoly_segmentize2d(const LWPOLY *line, double dist);
1598extern LWCOLLECTION *lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist);
1599
1600/*
1601 * Point density functions
1602 */
1603extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, uint32_t npoints, int32_t seed);
1604extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints, int32_t seed);
1605extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed);
1606
1607/*
1608 * Geometric median
1609 */
1610extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1611extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1612
1616char *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1617unsigned int geohash_point_as_int(POINT2D *pt);
1618
1619
1632
1636int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1637
1641LWCOLLECTION* 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
1672extern char* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1673extern char* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1677extern char* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1678extern char* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1679extern char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1680extern char* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
1681extern char* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1682extern char* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
1683extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1684
1694extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1695
1701extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1702
1706extern void spheroid_init(SPHEROID *s, double a, double b);
1707
1713extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1714
1718extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1719
1724extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1725
1729extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1730
1735extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1736
1741extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1742
1747extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1748
1753extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1754
1755typedef 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 */
1775
1788extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1789
1790
1791struct LWPOINTITERATOR;
1793
1798
1804
1809
1814
1821
1829
1835
1836
1840extern uint8_t parse_hex(char *str);
1841
1845extern void deparse_hex(uint8_t str, char *result);
1846
1847
1848
1849/***********************************************************************
1850** Functions for managing serialized forms and bounding boxes.
1851*/
1852
1856extern int lwgeom_check_geodetic(const LWGEOM *geom);
1857
1861extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1862
1866extern int lwgeom_force_geodetic(LWGEOM *geom);
1867
1871extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1872
1879extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1880
1886extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1887
1892extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1893
1898extern int getPoint2d_p_ro(const POINTARRAY *pa, uint32_t n, POINT2D **point);
1899
1903extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1904
1908extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1909
1913int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1914
1919extern GBOX* gbox_new(lwflags_t flags);
1920
1925extern void gbox_init(GBOX *gbox);
1926
1930extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
1931
1935extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
1936
1940extern void gbox_expand(GBOX *g, double d);
1941
1945extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
1946
1950extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
1951
1955extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
1956
1960extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
1961
1965extern char* gbox_to_string(const GBOX *gbox);
1966
1970extern GBOX* gbox_copy(const GBOX *gbox);
1971
1975extern GBOX* gbox_from_string(const char *str);
1976
1980extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
1981
1985extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
1986
1990extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
1991
1995extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
1996
2001extern size_t gbox_serialized_size(lwflags_t flags);
2002
2006extern int gbox_same(const GBOX *g1, const GBOX *g2);
2007
2011extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
2012
2017extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
2018
2025extern void gbox_float_round(GBOX *gbox);
2026
2030extern int gbox_is_valid(const GBOX *gbox);
2031
2035extern uint64_t gbox_get_sortable_hash(const GBOX *g, const int32_t srid);
2036
2040extern uint64_t gserialized_get_sortable_hash(const GSERIALIZED *g);
2041
2046extern 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
2153extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2154
2160extern uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2161
2167extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out);
2168
2172extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2173
2179extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2180
2185extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2186
2190extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2191
2192extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2193
2194extern char* hexbytes_from_bytes(const uint8_t *bytes, size_t size);
2195
2196/*
2197* WKT detailed parsing support
2198*/
2199extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2202
2203
2204/* Memory management */
2205extern void *lwalloc(size_t size);
2206extern void *lwrealloc(void *mem, size_t size);
2207extern void lwfree(void *mem);
2208
2209/* Utilities */
2210extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2211
2212/*
2213* TWKB functions
2214*/
2215
2220extern LWGEOM* lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check);
2221
2227extern 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
2229extern 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
2243extern 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
2249int lwgeom_has_arc(const LWGEOM *geom);
2250LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2251LWGEOM *lwgeom_unstroke(const LWGEOM *geom);
2252
2280
2309
2318extern 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
2325const char* lwgeom_geos_version(void);
2326
2328LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ;
2329
2330LWGEOM *lwgeom_normalize(const LWGEOM *geom);
2331LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2332LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2333LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2334LWGEOM *lwgeom_pointonsurface(const LWGEOM* geom);
2335LWGEOM *lwgeom_centroid(const LWGEOM* geom);
2336LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2337LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2338LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2339LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2340LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices);
2341
2349LWGEOM* 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 */
2358LWGEOM* 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 */
2371LWGEOM* 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 */
2379int lwgeom_is_simple(const LWGEOM *lwgeom);
2380
2381
2382/*******************************************************************************
2383 * PROJ4-dependent extra functions on LWGEOM
2384 ******************************************************************************/
2385
2386int lwgeom_transform_from_str(LWGEOM *geom, const char* instr, const char* outstr);
2387
2388#if POSTGIS_PROJ_VERSION < 60
2394projPJ projpj_from_string(const char* txt);
2395
2396#endif
2402int lwgeom_transform(LWGEOM *geom, LWPROJ* pj);
2403int ptarray_transform(POINTARRAY *pa, LWPROJ* pj);
2404
2405#if POSTGIS_PROJ_VERSION >= 60
2406
2412LWPROJ *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
2428LWGEOM* 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 */
2442LWGEOM* 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 */
2448LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2449
2459LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly);
2460
2470LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2471
2480int * 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
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition lwgeom_api.c:624
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition lwprint.c:428
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
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims)
Access to the float bounding box, if there is one.
GSERIALIZED * gserialized_set_gbox(GSERIALIZED *g, GBOX *gbox)
Copy a new bounding box into an existing gserialized.
Definition gserialized.c:31
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition lwline.c:347
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition lwgeom.c:286
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
Definition ptarray.c:259
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
LWPOINT * lwline_interpolate_point_3d(const LWLINE *line, double distance)
Interpolate one point along a line in 3D.
Definition lwline.c:602
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition lwpoint.c:57
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, 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
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition gbox.c:364
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom)
Definition lwgeom.c:787
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition lwgeom_api.c:108
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:326
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
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition lwgeom_api.c:670
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition lwgeom.c:259
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.
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
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
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition lwout_wkb.c:874
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition lwline.c:151
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition lwgeom.c:909
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition lwline.c:525
void * lwrealloc(void *mem, size_t size)
Definition lwutil.c:235
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition liblwgeom.h:261
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
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
GBOX * gbox_new(lwflags_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition gbox.c:32
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
LWMPOINT * lwmpoint_construct(int32_t srid, const POINTARRAY *pa)
Definition lwmpoint.c:52
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
GBOX * box3d_to_gbox(const BOX3D *b3d)
Definition gbox.c:80
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition ptarray.c:687
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition lwout_x3d.c:36
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_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures.c:52
LWPOINT * lwpoint_make3dz(int32_t srid, double x, double y, double z)
Definition lwpoint.c:173
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition measures.c:2461
LWMPOLY * lwmpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwmpoly.c:40
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
Definition liblwgeom.h:305
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
Definition lwtin.c:34
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
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
LWGEOM * lwgeom_pointonsurface(const LWGEOM *geom)
LWGEOM * lwtin_as_lwgeom(const LWTIN *obj)
Definition lwgeom.c:266
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 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_linemerge(const LWGEOM *geom1)
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)...
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
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
Definition lwpsurface.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
void lwpoint_free(LWPOINT *pt)
Definition lwpoint.c:213
void lwgeom_longitude_shift(LWGEOM *lwgeom)
Definition lwgeom.c:990
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
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.
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition gbox.c:774
double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B)
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
Definition lwgeom_api.c:39
LWMPOINT * lwpoly_to_points(const LWPOLY *poly, uint32_t npoints, int32_t seed)
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
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures.c:40
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition ptarray.c:714
GSERIALIZED * gserialized_drop_gbox(GSERIALIZED *g)
Remove the bounding box from a GSERIALIZED.
Definition gserialized.c:52
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition lwgeom.c:362
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
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
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,...
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
LWMLINE * lwmline_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwmline.c:38
int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
void lwmpoly_free(LWMPOLY *mpoly)
Definition lwmpoly.c:53
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition lwiterator.c:242
LWCURVEPOLY * lwcurvepoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwcurvepoly.c:35
uint32_t gserialized_get_version(const GSERIALIZED *g)
Return the serialization version.
Definition gserialized.c:42
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:309
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition lwout_svg.c:56
void(* lwfreeor)(void *mem)
Definition liblwgeom.h:258
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWGEOM * lwgeom_reverse(const LWGEOM *lwgeom)
Definition lwgeom.c:93
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition lwpoly.c:360
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Simplification.
Definition lwgeom.c:1848
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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:291
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_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
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
Definition lwgeom.c:644
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:215
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
LWCURVEPOLY * lwcurvepoly_construct_from_lwpoly(LWPOLY *lwpoly)
Construct an equivalent curve polygon from a polygon.
Definition lwcurvepoly.c:52
void lwtin_free(LWTIN *tin)
Definition lwtin.c:39
void *(* lwallocator)(size_t size)
Global functions for memory/logging handlers.
Definition liblwgeom.h:256
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
Definition lwpoint.c:52
void printLWPOLY(LWPOLY *poly)
Definition lwpoly.c:193
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
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.
LWMPOINT * lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints, int32_t seed)
LWPOINTITERATOR * lwpointiterator_create_rw(LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM* Supports modification of coordinates during iterat...
Definition lwiterator.c:251
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
Definition gbox.c:228
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:1066
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where)
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition lwgeom.c:306
struct struct_lwgeom_parser_result LWGEOM_PARSER_RESULT
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition lwpoint.c:129
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 gserialized_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
Pull the first point values of a GSERIALIZED.
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition lwmpoint.c:45
uint16_t lwflags_t
Definition liblwgeom.h:313
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition lwout_wkt.c:676
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
unsigned int geohash_point_as_int(POINT2D *pt)
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
Definition measures3d.c:82
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
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
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition lwin_wkt.c:880
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.
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,...
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 lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
int lwgeom_is_simple(const LWGEOM *lwgeom)
double lwpoint_get_x(const LWPOINT *point)
Definition lwpoint.c:63
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition lwgeom.c:402
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition lwgeom.c:271
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)
void printPA(POINTARRAY *pa)
Definition lwgeom_api.c:447
int lwgeom_check_geodetic(const LWGEOM *geom)
Check that coordinates of LWGEOM are all within the geodetic range (-180, -90, 180,...
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
Definition lwcompound.c:213
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:1311
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition lwgeom.c:1554
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition lwgeom.c:831
char * hexbytes_from_bytes(const uint8_t *bytes, size_t size)
Definition lwout_wkb.c:39
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition lwgeom_api.c:349
LWCOLLECTION * lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist)
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures3d.c:88
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
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition lwgeom.c:775
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition gbox.c:40
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition ptarray.c:59
double lwgeom_length(const LWGEOM *geom)
Definition lwgeom.c:1930
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
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).
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
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
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
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition ptarray.c:1708
LWPOLY * lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2)
Definition lwpoly.c:98
LWPOINT * lwpoint_make3dm(int32_t srid, double x, double y, double m)
Definition lwpoint.c:184
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition lwgeom.c:473
int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
Calculate covers predicate for two lwgeoms on the sphere.
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition lwgeom.c:188
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition lwgeom.c:547
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:916
LWTRIANGLE * lwtriangle_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwtriangle.c:58
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Definition lwgeom.c:1087
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
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
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
void * lwalloc(size_t size)
Definition lwutil.c:227
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
Definition lwin_wkb.c:92
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
Definition gbox.c:239
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition lwgeom.c:197
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition lwcompound.c:254
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition ptarray.c:368
void(* lwreporter)(const char *fmt, va_list ap) __attribute__((format(printf
Definition liblwgeom.h:259
double lwgeom_area(const LWGEOM *geom)
Definition lwgeom.c:1863
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
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
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
Definition ptarray.c:85
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition lwgeom.c:1229
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition lwout_kml.c:44
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
Definition gbox.c:601
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition lwout_gml.c:198
void printLWTIN(LWTIN *tin)
Definition lwtin.c:57
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)
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
LWGEOM * lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj)
Definition lwgeom.c:301
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
LWGEOM * lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision)
Create an LWGEOM object from an Encoded Polyline representation.
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
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
void lwfree(void *mem)
Definition lwutil.c:242
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition measures.c:207
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition lwgeom.c:206
int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox)
Calculate geodetic (x/y/z) box and add values to gbox.
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition lwpoint.c:163
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition lwgeom.c:179
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition lwgeom.c:316
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition lwgeom.c:1079
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition ptarray.c:603
void lwcircstring_free(LWCIRCSTRING *curve)
void *(* lwreallocator)(void *mem, size_t size)
Definition liblwgeom.h:257
uint64_t gserialized_get_sortable_hash(const GSERIALIZED *g)
Return a sortable key based on gserialized.
LWCOMPOUND * lwcompound_construct_from_lwline(const LWLINE *lwpoly)
Construct an equivalent compound curve from a linestring.
Definition lwcompound.c:204
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom)
Definition lwgeom.c:781
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
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition lwcompound.c:248
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition lwgeom.c:1461
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:321
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
Definition lwmline.c:46
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
LWPOINT * lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged)
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition lwgeom.c:233
int gserialized_ndims(const GSERIALIZED *gser)
Return the number of dimensions (2, 3, 4) in a geometry.
uint8_t lwtype_multitype(uint8_t type)
Definition lwgeom.c:352
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition lwgeom.c:242
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition lwgeom.c:170
LWLINE * lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where)
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.
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
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_from_hexwkb(const char *hexwkb, const char check)
Definition lwin_wkb.c:857
void lwtriangle_free(LWTRIANGLE *triangle)
Definition lwtriangle.c:69
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:413
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition lwcurvepoly.c:71
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
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
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
void lwcollection_release(LWCOLLECTION *lwcollection)
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
LWCURVEPOLY * lwcurvepoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms)
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
LWPOLY * lwpoly_segmentize2d(const LWPOLY *line, double dist)
Definition lwpoly.c:312
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)
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:727
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition lwgeom.c:2245
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoint.c:151
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t where)
Remove a point from a pointarray.
Definition ptarray.c:561
POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n)
Definition lwgeom_api.c:187
LWCOMPOUND * lwcompound_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwcompound.c:123
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition lwmpoly.c:47
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition lwgeom_api.c:680
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
Definition lwgeom.c:37
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
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
void lwcollection_free(LWCOLLECTION *col)
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
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
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...
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition lwgeom_api.c:125
int lwcollection_ngeoms(const LWCOLLECTION *col)
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition measures.c:2407
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition gbox.c:426
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition lwgeom.c:281
void ptarray_free(POINTARRAY *pa)
Definition ptarray.c:327
LWGEOM * lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area)
LWLINE * lwline_segmentize2d(const LWLINE *line, double dist)
Definition lwline.c:132
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
LWMPOINT * lwmpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwmpoint.c:39
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition lwpoly.c:80
void lwcircstring_release(LWCIRCSTRING *lwcirc)
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
Definition ptarray.c:509
POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n)
Definition lwgeom_api.c:335
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition lwgeom.c:296
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition lwpoly.c:43
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed)
void lwpoly_release(LWPOLY *lwpoly)
Definition lwpoly.c:306
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
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition lwgeom.c:161
LWPOINT * lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p)
Definition lwpoint.c:206
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition lwline.c:364
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
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
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition lwgeom.c:2083
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
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
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
LWCIRCSTRING * lwcircstring_construct_empty(int32_t srid, char hasz, char hasm)
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
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition lwgeom.c:224
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:305
void printLWPOINT(LWPOINT *point)
Definition lwpoint.c:224
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.
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
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition lwcompound.c:88
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:701
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfullywithin calculations.
Definition measures.c:177
LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell)
Definition lwtriangle.c:153
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
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
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition gbox.c:53
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices)
Definition lwgeom.c:2439
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.
LWGEOM * lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures.c:46
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition lwutil.c:471
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition lwgeom.c:251
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
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition lwstroke.c:859
void printLWTRIANGLE(LWTRIANGLE *triangle)
Definition lwtriangle.c:82
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition lwmpoint.c:93
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
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
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
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
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
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition lwgeom.c:450
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
double lwgeom_perimeter(const LWGEOM *geom)
Definition lwgeom.c:1886
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwline.c:55
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:923
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.
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition lwgeom.c:276
double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid)
Calculate the bearing between two points on a spheroid.
LWCIRCSTRING * lwcircstring_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:905
LWGEOM * lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint)
Definition lwchaikins.c:182
lwflags_t gserialized_get_lwflags(const GSERIALIZED *g)
Read standard lwflags from gserialized.
Definition gserialized.c:18
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition lwgeom.c:65
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition lwgeom_api.c:376
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition lwgeom.c:311
int32_t gserialized_hash(const GSERIALIZED *g)
Returns a hash code for the srid/type/geometry information in the GSERIALIZED.
int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
Definition lwpoint.c:40
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:833
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition lwout_gml.c:213
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
LWGEOM * lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags)
Definition lwstroke.c:826
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".
LWGEOM * lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures.c:58
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition lwin_wkt.c:886
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWCOLLECTION * lwcollection_concat_in_place(LWCOLLECTION *col1, const LWCOLLECTION *col2)
Appends all geometries from col2 to col1 in place.
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
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_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition lwline.c:228
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures3d.c:76
int lwgeom_has_arc(const LWGEOM *geom)
Definition lwstroke.c:55
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwtriangle.c:40
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
LWGEOM * lwgeom_force_4d(const LWGEOM *geom)
Definition lwgeom.c:793
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
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...
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
Definition lwline.c:275
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition lwtriangle.c:119
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:291
LWGEOM * lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm)
Definition lwmval.c:221
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.
void printLWPSURFACE(LWPSURFACE *psurf)
Definition lwpsurface.c:57
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition lwgeom.c:753
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
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition ptarray.c:634
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition lwgeom.c:1454
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...
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition lwgeom.c:747
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition lwgeom.c:2144
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition lwgeom.c:102
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition measures3d.c:335
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
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
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition lwgeom.c:511
enum LWORD_T LWORD
Ordinate names.
#define str(s)
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032
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