PostGIS 3.7.0dev-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#include <stdbool.h>
36
37#include "../postgis_config.h"
38
39#include "proj.h"
40
41/* For PROJ6 we cache several extra values to avoid calls to proj_get_source_crs
42 * or proj_get_target_crs since those are very costly
43 */
44typedef struct LWPROJ
45{
46 PJ* pj;
47
48 /* for pipeline transforms, whether to do a forward or inverse */
50
51 /* Source crs is geographic: Used in geography calls (source srid == dst srid) */
53 /* Source ellipsoid parameters */
57
58
59
60/* Enable new geodesic functions API */
61#define PROJ_GEODESIC
62
82#define LIBLWGEOM_VERSION "3.7.0dev"
83#define LIBLWGEOM_VERSION_MAJOR "3"
84#define LIBLWGEOM_VERSION_MINOR "7"
85#define LIBLWGEOM_GEOS_VERSION "31202"
86
88const char* lwgeom_version(void);
89
93#define LW_TRUE 1
94#define LW_FALSE 0
95#define LW_UNKNOWN 2
96#define LW_FAILURE 0
97#define LW_SUCCESS 1
98
102#define POINTTYPE 1
103#define LINETYPE 2
104#define POLYGONTYPE 3
105#define MULTIPOINTTYPE 4
106#define MULTILINETYPE 5
107#define MULTIPOLYGONTYPE 6
108#define COLLECTIONTYPE 7
109#define CIRCSTRINGTYPE 8
110#define COMPOUNDTYPE 9
111#define CURVEPOLYTYPE 10
112#define MULTICURVETYPE 11
113#define MULTISURFACETYPE 12
114#define POLYHEDRALSURFACETYPE 13
115#define TRIANGLETYPE 14
116#define TINTYPE 15
117
118#define NUMTYPES 16
119
124#define WKBZOFFSET 0x80000000
125#define WKBMOFFSET 0x40000000
126#define WKBSRIDFLAG 0x20000000
127#define WKBBBOXFLAG 0x10000000
128
130typedef enum LWORD_T {
134 LWORD_M = 3
136
137/**********************************************************************
138** Spherical radius.
139** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
140** the XVII General Assembly of the IUGG in Canberra.
141** http://en.wikipedia.org/wiki/Earth_radius
142** http://en.wikipedia.org/wiki/World_Geodetic_System
143*/
144
145#define WGS84_MAJOR_AXIS 6378137.0
146#define WGS84_INVERSE_FLATTENING 298.257223563
147#define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
148#define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
149#define WGS84_SRID 4326
150
151
158#define LWFLAG_Z 0x01
159#define LWFLAG_M 0x02
160#define LWFLAG_BBOX 0x04
161#define LWFLAG_GEODETIC 0x08
162#define LWFLAG_READONLY 0x10
163#define LWFLAG_SOLID 0x20
164
165#define FLAGS_GET_Z(flags) ((flags) & LWFLAG_Z)
166#define FLAGS_GET_M(flags) (((flags) & LWFLAG_M)>>1)
167#define FLAGS_GET_BBOX(flags) (((flags) & LWFLAG_BBOX)>>2)
168#define FLAGS_GET_GEODETIC(flags) (((flags) & LWFLAG_GEODETIC)>>3)
169#define FLAGS_GET_READONLY(flags) (((flags) & LWFLAG_READONLY)>>4)
170#define FLAGS_GET_SOLID(flags) (((flags) & LWFLAG_SOLID)>>5)
171
172#define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_Z) : ((flags) & ~LWFLAG_Z))
173#define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_M) : ((flags) & ~LWFLAG_M))
174#define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_BBOX) : ((flags) & ~LWFLAG_BBOX))
175#define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_GEODETIC) : ((flags) & ~LWFLAG_GEODETIC))
176#define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_READONLY) : ((flags) & ~LWFLAG_READONLY))
177#define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_SOLID) : ((flags) & ~LWFLAG_SOLID))
178
179#define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
180#define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
181#define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
182
192#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
193#define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
194#define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
195#define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
196#define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
197#define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
198#define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
199#define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
200#define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
201
206#define SRID_MAXIMUM 999999
207
212#define SRID_USER_MAXIMUM 998999
213
215#define SRID_UNKNOWN 0
216#define SRID_IS_UNKNOWN(x) ((int)x<=0)
217
218/* Invalid SRID value, for internal use */
219#define SRID_INVALID (999999 + 2)
220
221/*
222** EPSG WGS84 geographics, OGC standard default SRS, better be in
223** the SPATIAL_REF_SYS table!
224*/
225#define SRID_DEFAULT 4326
226
227#ifndef __GNUC__
228# define __attribute__(x)
229#endif
230
237extern int32_t clamp_srid(int32_t srid);
238
242typedef void* (*lwallocator)(size_t size);
243typedef void* (*lwreallocator)(void *mem, size_t size);
244typedef void (*lwfreeor)(void* mem);
245typedef void (*lwreporter)(const char* fmt, va_list ap)
246 __attribute__ (( format(printf, 1, 0) ));
247typedef void (*lwdebuglogger)(int level, const char* fmt, va_list ap)
248 __attribute__ (( format(printf, 2,0) ));
249
256extern void lwgeom_set_handlers(lwallocator allocator,
257 lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
258 lwreporter noticereporter);
259
260extern void lwgeom_set_debuglogger(lwdebuglogger debuglogger);
261
274extern void lwgeom_request_interrupt(void);
275
279extern void lwgeom_cancel_interrupt(void);
280
291typedef void (lwinterrupt_callback)(void);
293
294
295/******************************************************************
296* LWGEOM and GBOX both use LWFLAGS bit mask.
297* Serializations (may) use different bit mask schemes.
298*/
299typedef uint16_t lwflags_t;
300
301/******************************************************************
302* LWGEOM varlena equivalent type that contains both the size and
303* data(see Postgresql c.h)
304*/
305typedef struct lwvarlena_t
306{
307 uint32_t size; /* Do not touch this field directly! */
308 char data[]; /* Data content is here */
310
311#define LWVARHDRSZ ((int32_t) sizeof(int32_t))
312
319#ifdef WORDS_BIGENDIAN
320#define LWSIZE_GET(varsize) ((varsize) & 0x3FFFFFFF)
321#define LWSIZE_SET(varsize, len) ((varsize) = ((len) & 0x3FFFFFFF))
322#define IS_BIG_ENDIAN 1
323#else
324#define LWSIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF)
325#define LWSIZE_SET(varsize, len) ((varsize) = (((uint32_t)(len)) << 2))
326#define IS_BIG_ENDIAN 0
327#endif
328
329/******************************************************************/
330
331typedef struct {
332 double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
333} AFFINE;
334
335/******************************************************************/
336
337typedef struct
338{
339 double xmin, ymin, zmin;
340 double xmax, ymax, zmax;
341 int32_t srid;
342}
343BOX3D;
344
345/******************************************************************
346* GBOX structure.
347* We include the flags (information about dimensionality),
348* so we don't have to constantly pass them
349* into functions that use the GBOX.
350*/
351typedef struct
352{
354 double xmin;
355 double xmax;
356 double ymin;
357 double ymax;
358 double zmin;
359 double zmax;
360 double mmin;
361 double mmax;
362} GBOX;
363
364
365/******************************************************************
366* SPHEROID
367*
368* Standard definition of an ellipsoid (what wkt calls a spheroid)
369* f = (a-b)/a
370* e_sq = (a*a - b*b)/(a*a)
371* b = a - fa
372*/
373typedef struct
374{
375 double a; /* semimajor axis */
376 double b; /* semiminor axis b = (a - fa) */
377 double f; /* flattening f = (a-b)/a */
378 double e; /* eccentricity (first) */
379 double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
380 double radius; /* spherical average radius = (2*a+b)/3 */
381 char name[20]; /* name of ellipse */
382}
384
385/******************************************************************
386* POINT2D, POINT3D, POINT3DM, POINT4D
387*/
388typedef struct
389{
390 double x, y;
391}
392POINT2D;
393
394typedef struct
395{
396 double x, y, z;
397}
399
400typedef struct
401{
402 double x, y, z;
403}
404POINT3D;
405
406typedef struct
407{
408 double x, y, m;
409}
411
412typedef struct
413{
414 double x, y, z, m;
415}
416POINT4D;
417
418/******************************************************************
419* POINTARRAY
420* Point array abstracts a lot of the complexity of points and point lists.
421* It handles 2d/3d translation
422* (2d points converted to 3d will have z=0 or NaN)
423* DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
424*/
425typedef struct
426{
427 uint32_t npoints; /* how many points we are currently storing */
428 uint32_t maxpoints; /* how many points we have space for in serialized_pointlist */
429
430 /* Use FLAGS_* macros to handle */
432
433 /* Array of POINT 2D, 3D or 4D, possibly misaligned. */
435}
437
438/******************************************************************
439* GSERIALIZED
440*/
441
442typedef struct
443{
444 uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
445 uint8_t srid[3]; /* 24 bits of SRID */
446 uint8_t gflags; /* HasZ, HasM, HasBBox, IsGeodetic */
447 uint8_t data[1]; /* See gserialized.txt */
449
450/******************************************************************
451* LWGEOM (any geometry type)
452*
453* Abstract type, note that 'type', 'bbox' and 'srid' are available in
454* all geometry variants.
455*/
456typedef struct
457{
459 void *data;
460 int32_t srid;
462 uint8_t type;
463 char pad[1]; /* Padding to 24 bytes (unused) */
464}
465LWGEOM;
466
467/* POINTYPE */
468typedef struct
469{
471 POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
472 int32_t srid;
474 uint8_t type; /* POINTTYPE */
475 char pad[1]; /* Padding to 24 bytes (unused) */
476}
477LWPOINT; /* "light-weight point" */
478
479/* LINETYPE */
480typedef struct
481{
483 POINTARRAY *points; /* array of POINT3D */
484 int32_t srid;
486 uint8_t type; /* LINETYPE */
487 char pad[1]; /* Padding to 24 bytes (unused) */
488}
489LWLINE; /* "light-weight line" */
490
491/* TRIANGLE */
492typedef struct
493{
496 int32_t srid;
498 uint8_t type;
499 char pad[1]; /* Padding to 24 bytes (unused) */
500}
502
503/* CIRCSTRINGTYPE */
504typedef struct
505{
507 POINTARRAY *points; /* array of POINT(3D/3DM) */
508 int32_t srid;
510 uint8_t type; /* CIRCSTRINGTYPE */
511 char pad[1]; /* Padding to 24 bytes (unused) */
512}
513LWCIRCSTRING; /* "light-weight circularstring" */
514
515/* POLYGONTYPE */
516typedef struct
517{
519 POINTARRAY **rings; /* list of rings (list of points) */
520 int32_t srid;
522 uint8_t type; /* POLYGONTYPE */
523 char pad[1]; /* Padding to 24 bytes (unused) */
524 uint32_t nrings; /* how many rings we are currently storing */
525 uint32_t maxrings; /* how many rings we have space for in **rings */
526}
527LWPOLY; /* "light-weight polygon" */
528
529/* MULTIPOINTTYPE */
530typedef struct
531{
534 int32_t srid;
536 uint8_t type; /* MULTYPOINTTYPE */
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}
542
543/* MULTILINETYPE */
544typedef struct
545{
548 int32_t srid;
550 uint8_t type; /* MULTILINETYPE */
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}
555LWMLINE;
556
557/* MULTIPOLYGONTYPE */
558typedef struct
559{
562 int32_t srid;
564 uint8_t type; /* MULTIPOLYGONTYPE */
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}
569LWMPOLY;
570
571/* COLLECTIONTYPE */
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}
584
585/* COMPOUNDTYPE */
586typedef struct
587{
590 int32_t srid;
592 uint8_t type; /* COLLECTIONTYPE */
593 char pad[1]; /* Padding to 24 bytes (unused) */
594 uint32_t ngeoms; /* how many geometries we are currently storing */
595 uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
596}
597LWCOMPOUND; /* "light-weight compound line" */
598
599/* CURVEPOLYTYPE */
600typedef struct
601{
604 int32_t srid;
606 uint8_t type; /* CURVEPOLYTYPE */
607 char pad[1]; /* Padding to 24 bytes (unused) */
608 uint32_t nrings; /* how many rings we are currently storing */
609 uint32_t maxrings; /* how many rings we have space for in **rings */
610}
611LWCURVEPOLY; /* "light-weight polygon" */
612
613/* MULTICURVE */
614typedef struct
615{
618 int32_t srid;
620 uint8_t type; /* MULTICURVE */
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/* MULTISURFACETYPE */
628typedef struct
629{
632 int32_t srid;
634 uint8_t type; /* MULTISURFACETYPE */
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/* POLYHEDRALSURFACETYPE */
642typedef struct
643{
646 int32_t srid;
648 uint8_t type; /* POLYHEDRALSURFACETYPE */
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}
654
655/* TINTYPE */
656typedef struct
657{
660 int32_t srid;
662 uint8_t type; /* TINTYPE */
663 char pad[1]; /* Padding to 24 bytes (unused) */
664 uint32_t ngeoms; /* how many geometries we are currently storing */
665 uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
666}
667LWTIN;
668
669/* Casts LWGEOM->LW* (return NULL if cast is illegal) */
670extern LWMPOLY *lwgeom_as_lwmpoly(const LWGEOM *lwgeom);
671extern LWMLINE *lwgeom_as_lwmline(const LWGEOM *lwgeom);
672extern LWMPOINT *lwgeom_as_lwmpoint(const LWGEOM *lwgeom);
673extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
674extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
675extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
676
677extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
678extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
679extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
680extern LWPSURFACE *lwgeom_as_lwpsurface(const LWGEOM *lwgeom);
681extern LWTRIANGLE *lwgeom_as_lwtriangle(const LWGEOM *lwgeom);
682extern LWTIN *lwgeom_as_lwtin(const LWGEOM *lwgeom);
683extern LWGEOM *lwgeom_as_multi(const LWGEOM *lwgeom);
684extern LWGEOM *lwgeom_as_curve(const LWGEOM *lwgeom);
685
686/* Casts LW*->LWGEOM (always cast) */
687extern LWGEOM *lwtin_as_lwgeom(const LWTIN *obj);
688extern LWGEOM *lwtriangle_as_lwgeom(const LWTRIANGLE *obj);
689extern LWGEOM *lwpsurface_as_lwgeom(const LWPSURFACE *obj);
690extern LWGEOM *lwmpoly_as_lwgeom(const LWMPOLY *obj);
691extern LWGEOM *lwmline_as_lwgeom(const LWMLINE *obj);
692extern LWGEOM *lwmpoint_as_lwgeom(const LWMPOINT *obj);
693extern LWGEOM *lwcollection_as_lwgeom(const LWCOLLECTION *obj);
694extern LWGEOM *lwcircstring_as_lwgeom(const LWCIRCSTRING *obj);
695extern LWGEOM *lwcompound_as_lwgeom(const LWCOMPOUND *obj);
696extern LWGEOM *lwcurvepoly_as_lwgeom(const LWCURVEPOLY *obj);
697extern LWGEOM *lwpoly_as_lwgeom(const LWPOLY *obj);
698extern LWGEOM *lwline_as_lwgeom(const LWLINE *obj);
699extern LWGEOM *lwpoint_as_lwgeom(const LWPOINT *obj);
700
701
703extern LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj);
704extern LWMLINE* lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj);
705extern LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj);
706extern LWPSURFACE* lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj);
707extern LWTIN* lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj);
708
710
714extern lwflags_t lwflags(int hasz, int hasm, int geodetic);
715
716
717
718/***********************************************************************
719** GSERIALIZED API
720*/
721
726
731extern const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims);
732
737extern uint32_t gserialized_get_type(const GSERIALIZED *g);
738
743extern uint32_t gserialized_max_header_size(void);
744
750extern int32_t gserialized_hash(const GSERIALIZED *g);
751
756extern int32_t gserialized_get_srid(const GSERIALIZED *g);
757
762extern void gserialized_set_srid(GSERIALIZED *g, int32_t srid);
763
770extern int gserialized_is_empty(const GSERIALIZED *g);
771
775extern int gserialized_has_bbox(const GSERIALIZED *gser);
776
780extern int gserialized_has_z(const GSERIALIZED *gser);
781
785extern int gserialized_has_m(const GSERIALIZED *gser);
786
790extern int gserialized_is_geodetic(const GSERIALIZED *gser);
791
795extern int gserialized_ndims(const GSERIALIZED *gser);
796
806extern int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2);
807
815extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size);
816
822
828extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box);
829
834extern int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box);
835
842
848
852extern uint32_t gserialized_get_version(const GSERIALIZED *g);
853
857extern int gserialized_peek_first_point(const GSERIALIZED *g, POINT4D *out_point);
858
859/*****************************************************************************/
860
861
868extern void lwgeom_drop_bbox(LWGEOM *lwgeom);
869extern void lwgeom_drop_srid(LWGEOM *lwgeom);
870
877extern void lwgeom_add_bbox(LWGEOM *lwgeom);
881extern void lwgeom_refresh_bbox(LWGEOM *lwgeom);
885extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
886
894extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
895
901extern int lwgeom_is_collection(const LWGEOM *lwgeom);
902
908extern int lwgeom_is_unitary(const LWGEOM *geom);
909extern int lwtype_is_unitary(uint32_t lwtype);
910
911/*
912 * Check if geometry type contains patches
913 */
914extern int lwgeom_has_patches(const LWGEOM *geom);
915
920extern int lwgeom_has_rings(const LWGEOM *geom);
921
925extern int lwgeom_isfinite(const LWGEOM *lwgeom);
926
927
928/******************************************************************/
929/* Functions that work on type numbers */
930
934extern int lwtype_is_collection(uint8_t type);
935
939extern uint32_t lwtype_get_collectiontype(uint8_t type);
940
945extern const char *lwtype_name(uint8_t type);
946extern uint8_t lwtype_multitype(uint8_t type);
947
948/******************************************************************/
949
950/*
951 * copies a point from the point array into the parameter point
952 * will set point's z=0 (or NaN) if pa is 2d
953 * will set point's m=0 (or NaN) if pa is 3d or 2d
954 * NOTE: point is a real POINT3D *not* a pointer
955 */
956extern POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n);
957
958/*
959 * copies a point from the point array into the parameter point
960 * will set point's z=0 (or NaN) if pa is 2d
961 * will set point's m=0 (or NaN) if pa is 3d or 2d
962 * NOTE: this will modify the point4d pointed to by 'point'.
963 */
964extern int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point);
965
966/*
967 * copies a point from the point array into the parameter point
968 * will set point's z=0 (or NaN) if pa is 2d
969 * NOTE: point is a real POINT3D *not* a pointer
970 */
971extern POINT3DZ getPoint3dz(const POINTARRAY *pa, uint32_t n);
972extern POINT3DM getPoint3dm(const POINTARRAY *pa, uint32_t n);
973
974/*
975 * copies a point from the point array into the parameter point
976 * will set point's z=0 (or NaN) if pa is 2d
977 * NOTE: this will modify the point3d pointed to by 'point'.
978 */
979extern int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point);
980extern int getPoint3dm_p(const POINTARRAY *pa, uint32_t n, POINT3DM *point);
981
982
983/*
984 * copies a point from the point array into the parameter point
985 * z value (if present is not returned)
986 * NOTE: point is a real POINT3D *not* a pointer
987 */
988extern POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n);
989
990/*
991 * copies a point from the point array into the parameter point
992 * z value (if present is not returned)
993 * NOTE: this will modify the point2d pointed to by 'point'.
994 */
995extern int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point);
996
997/*
998 * set point N to the given value
999 * NOTE that the pointarray can be of any
1000 * dimension, the appropriate ordinate values
1001 * will be extracted from it
1002 *
1003 * N must be a valid point index
1004 */
1005extern void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d);
1006
1012extern POINTARRAY* ptarray_construct(char hasz, char hasm, uint32_t npoints);
1013
1017extern POINTARRAY* ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist);
1018
1022extern POINTARRAY* ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist);
1023
1029extern POINTARRAY* ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints);
1030
1036extern int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates);
1037
1049extern int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance);
1050
1055extern int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where);
1056
1061extern int ptarray_remove_point(POINTARRAY *pa, uint32_t where);
1062
1074extern POINTARRAY *ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where);
1075
1081extern POINTARRAY *ptarray_removePoint(POINTARRAY *pa, uint32_t where);
1082
1089extern POINTARRAY *ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2);
1090
1091extern int ptarray_is_closed(const POINTARRAY *pa);
1092extern int ptarray_is_closed_2d(const POINTARRAY *pa);
1093extern int ptarray_is_closed_3d(const POINTARRAY *pa);
1094extern int ptarray_is_closed_z(const POINTARRAY *pa);
1096
1102extern POINTARRAY *ptarray_substring(POINTARRAY *pa, double d1, double d2,
1103 double tolerance);
1104
1110extern int ptarray_closest_vertex_2d(const POINTARRAY *pa,
1111 const POINT2D *qp, double *dist);
1112
1120extern int ptarray_closest_segment_2d(const POINTARRAY *pa,
1121 const POINT2D *qp, double *dist);
1122
1123
1124
1128extern LWGEOM* lwgeom_force_2d(const LWGEOM *geom);
1129extern LWGEOM* lwgeom_force_3dz(const LWGEOM *geom, double zval);
1130extern LWGEOM* lwgeom_force_3dm(const LWGEOM *geom, double mval);
1131extern LWGEOM* lwgeom_force_4d(const LWGEOM *geom, double zval, double mval);
1132
1133extern LWGEOM* lwgeom_set_effective_area(const LWGEOM *igeom, int set_area, double area);
1134extern LWGEOM* lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint);
1135extern LWGEOM* lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm);
1136
1137/*
1138 * Force to use SFS 1.1 geometry type
1139 * (rather than SFS 1.2 and/or SQL/MM)
1140 */
1141extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version);
1142
1143
1144/*--------------------------------------------------------
1145 * all the base types (point/line/polygon) will have a
1146 * basic constructor, basic de-serializer, basic serializer,
1147 * bounding box finder and (TODO) serialized form size finder.
1148 *--------------------------------------------------------*/
1149
1150/*
1151 * convenience functions to hide the POINTARRAY
1152 */
1153extern int lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out);
1154extern int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out);
1155extern int lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out);
1156extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
1157
1158/******************************************************************
1159 * LWLINE functions
1160 ******************************************************************/
1161
1165extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1166
1170extern POINTARRAY* lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat);
1171
1175extern LWPOINT* lwline_interpolate_point_3d(const LWLINE *line, double distance);
1176
1180extern LWLINE* lwline_extend(const LWLINE *line, double distance_forward, double distance_backward);
1181
1182/******************************************************************
1183 * LWPOLY functions
1184 ******************************************************************/
1185
1190extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
1191
1196extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
1197
1202extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
1203
1209
1215
1216
1217/******************************************************************
1218 * LWGEOM functions
1219 ******************************************************************/
1220
1221extern int lwcollection_ngeoms(const LWCOLLECTION *col);
1222
1223/* Given a generic geometry/collection, return the "simplest" form.
1224 * The elements of the homogenized collection are deeply cloned
1225 * */
1226extern LWGEOM *lwgeom_homogenize(const LWGEOM *geom);
1227
1228
1229/******************************************************************
1230 * LWMULTIx and LWCOLLECTION functions
1231 ******************************************************************/
1232
1233const LWGEOM *lwcollection_getsubgeom(LWCOLLECTION *col, uint32_t gnum);
1234LWCOLLECTION* lwcollection_extract(const LWCOLLECTION *col, uint32_t type);
1235
1236
1237/******************************************************************
1238 * SERIALIZED FORM functions
1239 ******************************************************************/
1240
1246extern void lwgeom_set_srid(LWGEOM *geom, int32_t srid);
1247
1248/*------------------------------------------------------
1249 * other stuff
1250 *
1251 * handle the double-to-float conversion. The results of this
1252 * will usually be a slightly bigger box because of the difference
1253 * between float8 and float4 representations.
1254 */
1255
1256extern BOX3D* box3d_from_gbox(const GBOX *gbox);
1257extern GBOX* box3d_to_gbox(const BOX3D *b3d);
1258
1259void expand_box3d(BOX3D *box, double d);
1260
1261
1262/****************************************************************
1263 * MEMORY MANAGEMENT
1264 ****************************************************************/
1265
1266/*
1267* The *_free family of functions frees *all* memory associated
1268* with the pointer. When the recursion gets to the level of the
1269* POINTARRAY, the POINTARRAY is only freed if it is not flagged
1270* as "read only". LWGEOMs constructed on top of GSERIALIZED
1271* from PgSQL use read only point arrays.
1272*/
1273
1274extern void ptarray_free(POINTARRAY *pa);
1275extern void lwpoint_free(LWPOINT *pt);
1276extern void lwline_free(LWLINE *line);
1277extern void lwpoly_free(LWPOLY *poly);
1278extern void lwtriangle_free(LWTRIANGLE *triangle);
1279extern void lwmpoint_free(LWMPOINT *mpt);
1280extern void lwmline_free(LWMLINE *mline);
1281extern void lwmpoly_free(LWMPOLY *mpoly);
1282extern void lwpsurface_free(LWPSURFACE *psurf);
1283extern void lwtin_free(LWTIN *tin);
1284extern void lwcollection_free(LWCOLLECTION *col);
1285extern void lwcircstring_free(LWCIRCSTRING *curve);
1286extern void lwgeom_free(LWGEOM *geom);
1287
1288/*
1289* The *_release family of functions frees the LWGEOM structures
1290* surrounding the POINTARRAYs but leaves the POINTARRAYs
1291* intact. Useful when re-shaping geometries between types,
1292* or splicing geometries together.
1293*/
1294
1295extern void lwpoint_release(LWPOINT *lwpoint);
1296extern void lwline_release(LWLINE *lwline);
1297extern void lwpoly_release(LWPOLY *lwpoly);
1298extern void lwtriangle_release(LWTRIANGLE *lwtriangle);
1299extern void lwcircstring_release(LWCIRCSTRING *lwcirc);
1300extern void lwmpoint_release(LWMPOINT *lwpoint);
1301extern void lwmline_release(LWMLINE *lwline);
1302extern void lwmpoly_release(LWMPOLY *lwpoly);
1303extern void lwpsurface_release(LWPSURFACE *lwpsurface);
1304extern void lwtin_release(LWTIN *lwtin);
1305extern void lwcollection_release(LWCOLLECTION *lwcollection);
1306extern void lwgeom_release(LWGEOM *lwgeom);
1307
1308
1309/****************************************************************
1310* Utility
1311****************************************************************/
1312
1313extern void printBOX3D(BOX3D *b);
1314extern void printPA(POINTARRAY *pa);
1315extern void printLWPOINT(LWPOINT *point);
1316extern void printLWLINE(LWLINE *line);
1317extern void printLWPOLY(LWPOLY *poly);
1318extern void printLWTRIANGLE(LWTRIANGLE *triangle);
1319extern void printLWPSURFACE(LWPSURFACE *psurf);
1320extern void printLWTIN(LWTIN *tin);
1321
1322extern float next_float_down(double d);
1323extern float next_float_up(double d);
1324
1325/* general utilities 2D */
1326extern double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
1327extern double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
1328extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1329extern LWGEOM* lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2);
1330extern LWGEOM* lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1331extern LWGEOM* lwgeom_furthest_point(const LWGEOM *lw1, const LWGEOM *lw2);
1332extern double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1333extern double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1334extern double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2);
1335extern double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1336
1337/* 3D */
1338extern double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2);
1339extern double distance3d_pt_seg(const POINT3D *p, const POINT3D *A, const POINT3D *B);
1340
1341extern LWGEOM* lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2);
1342extern LWGEOM* lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1343extern LWGEOM* lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2);
1344
1345
1346extern double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1347extern double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1348extern double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2);
1349extern double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance);
1350
1351extern double lwgeom_area(const LWGEOM *geom);
1352extern double lwgeom_length(const LWGEOM *geom);
1353extern double lwgeom_length_2d(const LWGEOM *geom);
1354extern double lwgeom_perimeter(const LWGEOM *geom);
1355extern double lwgeom_perimeter_2d(const LWGEOM *geom);
1356extern int lwgeom_dimension(const LWGEOM *geom);
1357
1358extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, uint32_t where);
1359extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where);
1360
1361extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
1362extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
1363extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where);
1364extern uint32_t lwcompound_num_curves(const LWCOMPOUND *compound);
1365extern const LWGEOM *lwcollection_getsubcurve(const LWCOMPOUND *compound, uint32_t gnum);
1366
1367extern double ptarray_length_2d(const POINTARRAY *pts);
1368extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
1369extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
1370extern LWPOINT* lwpoint_project_lwpoint(const LWPOINT* lwpoint1, const LWPOINT* lwpoint2, double distance);
1371extern LWPOINT* lwpoint_project(const LWPOINT* lwpoint1, double distance, double azimuth);
1372extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
1373
1374extern LWGEOM* lwgeom_reverse(const LWGEOM *lwgeom);
1375extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
1376extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
1377extern int lwgeom_startpoint(const LWGEOM* lwgeom, POINT4D* pt);
1378
1379extern void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F);
1380
1387extern int lwgeom_has_orientation(const LWGEOM *lwgeom, int orientation);
1388
1389
1393extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed);
1394extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
1395
1399typedef struct gridspec_t
1400{
1401 double ipx;
1402 double ipy;
1403 double ipz;
1404 double ipm;
1405 double xsize;
1406 double ysize;
1407 double zsize;
1408 double msize;
1409 double xscale;
1410 double yscale;
1411 double zscale;
1412 double mscale;
1413}
1415
1416extern LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, gridspec *grid);
1417extern void lwgeom_grid_in_place(LWGEOM *lwgeom, gridspec *grid);
1418
1419
1420/****************************************************************
1421* READ/WRITE FUNCTIONS
1422*
1423* Coordinate writing functions, which will alter the coordinates
1424* and potentially the structure of the input geometry. When
1425* called from within PostGIS, the LWGEOM argument should be built
1426* on top of a gserialized copy, created using
1427* PG_GETARG_GSERIALIZED_P_COPY()
1428****************************************************************/
1429
1430extern void lwgeom_reverse_in_place(LWGEOM *lwgeom);
1431extern void lwgeom_force_clockwise(LWGEOM *lwgeom);
1432extern void lwgeom_force_counterclockwise(LWGEOM *lwgeom);
1433extern void lwgeom_longitude_shift(LWGEOM *lwgeom);
1434extern int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed);
1435extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
1436extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
1437extern int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance);
1438
1439
1452LWGEOM *lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount);
1453
1454
1464extern int lwgeom_needs_bbox(const LWGEOM *geom);
1465
1469extern uint32_t lwgeom_count_vertices(const LWGEOM *geom);
1470
1475extern uint32_t lwgeom_count_rings(const LWGEOM *geom);
1476
1481extern int lwgeom_has_srid(const LWGEOM *geom);
1482
1487extern int lwgeom_is_closed(const LWGEOM *geom);
1488
1492extern int lwgeom_dimensionality(const LWGEOM *geom);
1493
1494/* Is lwgeom1 geometrically equal to lwgeom2 ? */
1495extern char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1496
1497
1505extern LWGEOM *lwgeom_clone(const LWGEOM *lwgeom);
1506
1510extern LWGEOM *lwgeom_clone_deep(const LWGEOM *lwgeom);
1511extern POINTARRAY *ptarray_clone_deep(const POINTARRAY *ptarray);
1512
1513
1514/*
1515* Geometry constructors. These constructors to not copy the point arrays
1516* passed to them, they just take references, so do not free them out
1517* from underneath the geometries.
1518*/
1519extern LWPOINT* lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point);
1520extern LWMPOINT *lwmpoint_construct(int32_t srid, const POINTARRAY *pa);
1521extern LWLINE* lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1522extern LWCIRCSTRING* lwcircstring_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1523extern LWPOLY* lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points);
1524extern LWCURVEPOLY* lwcurvepoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, LWGEOM **geoms);
1525extern LWTRIANGLE* lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points);
1526extern LWCOLLECTION* lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms);
1527/*
1528* Empty geometry constructors.
1529*/
1530extern LWGEOM* lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm);
1531extern LWPOINT* lwpoint_construct_empty(int32_t srid, char hasz, char hasm);
1532extern LWLINE* lwline_construct_empty(int32_t srid, char hasz, char hasm);
1533extern LWPOLY* lwpoly_construct_empty(int32_t srid, char hasz, char hasm);
1534extern LWCURVEPOLY* lwcurvepoly_construct_empty(int32_t srid, char hasz, char hasm);
1535extern LWCIRCSTRING* lwcircstring_construct_empty(int32_t srid, char hasz, char hasm);
1536extern LWCOMPOUND* lwcompound_construct_empty(int32_t srid, char hasz, char hasm);
1537extern LWTRIANGLE* lwtriangle_construct_empty(int32_t srid, char hasz, char hasm);
1538extern LWMPOINT* lwmpoint_construct_empty(int32_t srid, char hasz, char hasm);
1539extern LWMLINE* lwmline_construct_empty(int32_t srid, char hasz, char hasm);
1540extern LWMPOLY* lwmpoly_construct_empty(int32_t srid, char hasz, char hasm);
1541extern LWCOLLECTION* lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm);
1542
1543
1544/* Other constructors */
1545extern LWPOINT *lwpoint_make2d(int32_t srid, double x, double y);
1546extern LWPOINT *lwpoint_make3dz(int32_t srid, double x, double y, double z);
1547extern LWPOINT *lwpoint_make3dm(int32_t srid, double x, double y, double m);
1548extern LWPOINT *lwpoint_make4d(int32_t srid, double x, double y, double z, double m);
1549extern LWPOINT *lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p);
1550extern LWLINE *lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms);
1551extern LWLINE *lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points); /* TODO: deprecate */
1552extern LWLINE *lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint);
1553extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
1554extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
1555extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
1556extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
1557extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
1558extern LWPOLY *lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2);
1559extern LWPOLY *lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
1560extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
1561extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
1562
1563/* Some point accessors */
1564extern double lwpoint_get_x(const LWPOINT *point);
1565extern double lwpoint_get_y(const LWPOINT *point);
1566extern double lwpoint_get_z(const LWPOINT *point);
1567extern double lwpoint_get_m(const LWPOINT *point);
1568
1572extern int32_t lwgeom_get_srid(const LWGEOM *geom);
1573
1577extern int lwgeom_has_z(const LWGEOM *geom);
1578
1582extern int lwgeom_has_m(const LWGEOM *geom);
1583
1587extern int lwgeom_is_solid(const LWGEOM *geom);
1588
1592extern int lwgeom_ndims(const LWGEOM *geom);
1593
1594/*
1595 * Given a point, returns the location of closest point on pointarray
1596 * as a fraction of total length (0: first point -- 1: last point).
1597 *
1598 * If not-null, the third argument will be set to the actual distance
1599 * of the point from the pointarray.
1600 */
1601extern double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located);
1602
1607extern LWLINE *lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end);
1608extern LWMLINE* lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end);
1609
1614extern LWGEOM* lwgeom_locate_along(const LWGEOM *lwin, double m, double offset);
1615
1621extern LWCOLLECTION* lwgeom_locate_between(const LWGEOM *lwin, double from, double to, double offset);
1622
1626extern double lwgeom_interpolate_point(const LWGEOM *lwin, const LWPOINT *lwpt);
1627
1638extern double lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist);
1639
1645extern int lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist);
1646
1651extern int lwgeom_is_trajectory(const LWGEOM *geom);
1652extern int lwline_is_trajectory(const LWLINE *geom);
1653
1654/*
1655 * Ensure every segment is at most 'dist' long.
1656 * Returned LWGEOM might is unchanged if a POINT.
1657 */
1658extern LWGEOM *lwgeom_segmentize2d(const LWGEOM *line, double dist);
1659extern POINTARRAY *ptarray_segmentize2d(const POINTARRAY *ipa, double dist);
1660extern LWLINE *lwline_segmentize2d(const LWLINE *line, double dist);
1661extern LWPOLY *lwpoly_segmentize2d(const LWPOLY *line, double dist);
1662extern LWCOLLECTION *lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist);
1663
1664/*
1665 * Point density functions
1666 */
1667extern LWMPOINT *lwpoly_to_points(const LWPOLY *poly, uint32_t npoints, int32_t seed);
1668extern LWMPOINT *lwmpoly_to_points(const LWMPOLY *mpoly, uint32_t npoints, int32_t seed);
1669extern LWMPOINT *lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed);
1670
1671/*
1672 * Geometric median
1673 */
1674extern LWPOINT* lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1675extern LWPOINT* lwmpoint_median(const LWMPOINT *g, double tol, uint32_t maxiter, char fail_if_not_converged);
1676
1680lwvarlena_t *lwgeom_geohash(const LWGEOM *lwgeom, int precision);
1681unsigned int geohash_point_as_int(POINT2D *pt);
1682
1683
1696
1700int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2);
1701
1705LWCOLLECTION* lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset);
1706
1712#define LW_GML_IS_DIMS (1<<0)
1714#define LW_GML_IS_DEGREE (1<<1)
1716#define LW_GML_SHORTLINE (1<<2)
1718#define LW_GML_EXTENT (1<<4)
1719
1720
1721#define IS_DIMS(x) ((x) & LW_GML_IS_DIMS)
1722#define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE)
1730#define LW_X3D_FLIP_XY (1<<0)
1731#define LW_X3D_USE_GEOCOORDS (1<<1)
1732#define X3D_USE_GEOCOORDS(x) ((x) & LW_X3D_USE_GEOCOORDS)
1733
1734
1735
1736extern lwvarlena_t* lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1737extern lwvarlena_t* lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix);
1741extern lwvarlena_t* lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix);
1742extern lwvarlena_t* lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id);
1743extern lwvarlena_t* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix);
1744extern lwvarlena_t* lwgeom_to_geojson(const LWGEOM *geo, const char *srs, int precision, int has_bbox);
1745extern lwvarlena_t* lwgeom_to_x3d3(const LWGEOM *geom, int precision, int opts, const char *defid);
1746extern lwvarlena_t* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
1747extern lwvarlena_t* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
1748
1758extern LWGEOM* lwgeom_from_geojson(const char *geojson, char **srs);
1759
1765extern LWGEOM* lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision);
1766
1770extern void spheroid_init(SPHEROID *s, double a, double b);
1771
1777extern double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance);
1778
1782extern LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth);
1783
1787extern LWPOINT* lwgeom_project_spheroid_lwpoint(const LWPOINT *from, const LWPOINT *to, const SPHEROID *spheroid, double distance);
1788
1793extern LWGEOM* lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length);
1794
1798extern double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid);
1799
1804extern double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1805
1810extern double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid);
1811
1816extern double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s);
1817
1822extern int lwgeom_covers_lwgeom_sphere(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
1823
1824
1825extern LWGEOM * geography_substring(const LWLINE *line,
1826 const SPHEROID *s,
1827 double from, double to,
1828 double tolerance);
1829
1831 const LWLINE *line,
1832 double length_fraction,
1833 const SPHEROID *s, char repeat);
1834
1835extern double
1837 const POINTARRAY *pa,
1838 const POINT4D *p4d,
1839 const SPHEROID *s,
1840 double tolerance,
1841 double *mindistout,
1842 POINT4D *proj4d);
1843
1844
1845typedef struct {
1847 double radius;
1849
1851
1852/* Calculates the minimum circle that encloses all of the points in g, using a
1853 * two-dimensional implementation of the algorithm proposed in:
1854 *
1855 * Welzl, Emo (1991), "Smallest enclosing disks (balls and elipsoids)."
1856 * New Results and Trends in Computer Science (H. Maurer, Ed.), Lecture Notes
1857 * in Computer Science, 555 (1991) 359-370.
1858 *
1859 * Available online at the time of this writing at
1860 * https://www.inf.ethz.ch/personal/emo/PublFiles/SmallEnclDisk_LNCS555_91.pdf
1861 *
1862 * Returns NULL if the circle could not be calculated.
1863 */
1865
1878extern void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2);
1879
1880
1881struct LWPOINTITERATOR;
1883
1888
1894
1899
1904
1911
1919
1925
1926
1930extern uint8_t parse_hex(char *str);
1931
1935extern void deparse_hex(uint8_t str, char *result);
1936
1937
1938
1939/***********************************************************************
1940** Functions for managing serialized forms and bounding boxes.
1941*/
1942
1946extern int lwgeom_check_geodetic(const LWGEOM *geom);
1947
1951extern int lwgeom_nudge_geodetic(LWGEOM *geom);
1952
1956extern int lwgeom_force_geodetic(LWGEOM *geom);
1957
1961extern void lwgeom_set_geodetic(LWGEOM *geom, int value);
1962
1969extern int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox);
1970
1976extern int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox);
1977
1982extern int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox);
1983
1987extern int ptarray_calculate_gbox_geodetic(const POINTARRAY *pa, GBOX *gbox);
1988
1992extern int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox );
1993
1997int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside);
1998
2003extern GBOX* gbox_new(lwflags_t flags);
2004
2009extern void gbox_init(GBOX *gbox);
2010
2014extern int gbox_merge(const GBOX *new_box, GBOX *merged_box);
2015
2019extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout);
2020
2024extern void gbox_expand(GBOX *g, double d);
2025
2029extern void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm);
2030
2034extern int gbox_init_point3d(const POINT3D *p, GBOX *gbox);
2035
2039extern int gbox_merge_point3d(const POINT3D *p, GBOX *gbox);
2040
2044extern int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt);
2045
2049extern char* gbox_to_string(const GBOX *gbox);
2050
2054extern GBOX* gbox_copy(const GBOX *gbox);
2055
2059extern GBOX* gbox_from_string(const char *str);
2060
2064extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
2065
2069extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
2070
2074extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
2075
2079extern int gbox_within_2d(const GBOX *g1, const GBOX *g2);
2080
2084extern void gbox_duplicate(const GBOX *original, GBOX *duplicate);
2085
2090extern size_t gbox_serialized_size(lwflags_t flags);
2091
2095extern int gbox_same(const GBOX *g1, const GBOX *g2);
2096
2100extern int gbox_same_2d(const GBOX *g1, const GBOX *g2);
2101
2106extern int gbox_same_2d_float(const GBOX *g1, const GBOX *g2);
2107
2114extern void gbox_float_round(GBOX *gbox);
2115
2119extern int gbox_is_valid(const GBOX *gbox);
2120
2124extern uint64_t gbox_get_sortable_hash(const GBOX *g, const int32_t srid);
2125
2129extern uint64_t gserialized_get_sortable_hash(const GSERIALIZED *g);
2130
2135extern int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m);
2136
2144#define LW_PARSER_CHECK_MINPOINTS 1
2145#define LW_PARSER_CHECK_ODD 2
2146#define LW_PARSER_CHECK_CLOSURE 4
2147#define LW_PARSER_CHECK_ZCLOSURE 8
2148
2149#define LW_PARSER_CHECK_NONE 0
2150#define LW_PARSER_CHECK_ALL (LW_PARSER_CHECK_MINPOINTS | LW_PARSER_CHECK_ODD | LW_PARSER_CHECK_CLOSURE)
2151
2157{
2158 const char *wkinput; /* Copy of pointer to input WKT/WKB */
2159 uint8_t *serialized_lwgeom; /* Pointer to serialized LWGEOM */
2160 size_t size; /* Size of serialized LWGEOM in bytes */
2161 LWGEOM *geom; /* Pointer to LWGEOM struct */
2162 const char *message; /* Error/warning message */
2163 int errcode; /* Error/warning number */
2164 int errlocation; /* Location of error */
2165 int parser_check_flags; /* Bitmask of validity checks run during this parse */
2166}
2168
2169/*
2170 * Parser error messages (these must match the message array in lwgparse.c)
2171 */
2172#define PARSER_ERROR_MOREPOINTS 1
2173#define PARSER_ERROR_ODDPOINTS 2
2174#define PARSER_ERROR_UNCLOSED 3
2175#define PARSER_ERROR_MIXDIMS 4
2176#define PARSER_ERROR_INVALIDGEOM 5
2177#define PARSER_ERROR_INVALIDWKBTYPE 6
2178#define PARSER_ERROR_INCONTINUOUS 7
2179#define PARSER_ERROR_TRIANGLEPOINTS 8
2180#define PARSER_ERROR_LESSPOINTS 9
2181#define PARSER_ERROR_OTHER 10
2182
2183
2184
2185/*
2186 * Unparser result structure: returns the result of attempting to convert LWGEOM to (E)WKT/(E)WKB
2187 */
2189{
2190 uint8_t *serialized_lwgeom; /* Copy of pointer to input serialized LWGEOM */
2191 char *wkoutput; /* Pointer to WKT or WKB output */
2192 size_t size; /* Size of serialized LWGEOM in bytes */
2193 const char *message; /* Error/warning message */
2194 int errlocation; /* Location of error */
2195}
2197
2198/*
2199 * Unparser error messages (these must match the message array in lwgunparse.c)
2200 */
2201#define UNPARSER_ERROR_MOREPOINTS 1
2202#define UNPARSER_ERROR_ODDPOINTS 2
2203#define UNPARSER_ERROR_UNCLOSED 3
2204
2205
2206/*
2207** Variants available for WKB and WKT output types
2208*/
2209
2210#define WKB_ISO 0x01
2211#define WKB_SFSQL 0x02
2212#define WKB_EXTENDED 0x04
2213#define WKB_NDR 0x08
2214#define WKB_XDR 0x10
2215#define WKB_HEX 0x20
2216#define WKB_NO_NPOINTS 0x40 /* Internal use only */
2217#define WKB_NO_SRID 0x80 /* Internal use only */
2218
2219#define WKT_ISO 0x01
2220#define WKT_SFSQL 0x02
2221#define WKT_EXTENDED 0x04
2222
2223
2224/*
2225** Variants available for TWKB
2226*/
2227#define TWKB_BBOX 0x01 /* User wants bboxes */
2228#define TWKB_SIZE 0x02 /* User wants sizes */
2229#define TWKB_ID 0x04 /* User wants id */
2230#define TWKB_NO_TYPE 0x10 /* No type because it is a sub geometry */
2231#define TWKB_NO_ID 0x20 /* No ID because it is a subgeometry */
2232#define TWKB_DEFAULT_PRECISION 0 /* Aim for 1m (or ft) rounding by default */
2233
2234/*
2235** New parsing and unparsing functions.
2236*/
2237
2244extern char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out);
2245
2251extern lwvarlena_t* lwgeom_to_wkt_varlena(const LWGEOM *geom, uint8_t variant, int precision);
2252
2258extern uint8_t* lwgeom_to_wkb_buffer(const LWGEOM *geom, uint8_t variant);
2259extern lwvarlena_t* lwgeom_to_wkb_varlena(const LWGEOM *geom, uint8_t variant);
2260
2267extern char* lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant);
2268extern lwvarlena_t* lwgeom_to_hexwkb_varlena(const LWGEOM *geom, uint8_t variant);
2269
2273extern char *lwgeom_to_ewkt(const LWGEOM *lwgeom);
2274
2280extern LWGEOM* lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check);
2281
2286extern LWGEOM* lwgeom_from_wkt(const char *wkt, const char check);
2287
2291extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
2292
2293extern uint8_t* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
2294
2295extern char* hexbytes_from_bytes(const uint8_t *bytes, size_t size);
2296
2297/*
2298* WKT detailed parsing support
2299*/
2300extern int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
2303
2304
2305/* Memory management */
2306extern void *lwalloc(size_t size);
2307extern void *lwrealloc(void *mem, size_t size);
2308extern void lwfree(void *mem);
2309
2310/* Utilities */
2311extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection);
2312
2313/*
2314* TWKB functions
2315*/
2316
2322extern LWGEOM* lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check);
2323
2329extern lwvarlena_t* lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m);
2330
2331extern lwvarlena_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);
2332
2345extern void lwgeom_trim_bits_in_place(LWGEOM *geom, int32_t prec_x, int32_t prec_y, int32_t prec_z, int32_t prec_m);
2346
2347extern LWGEOM* lwgeom_boundary(LWGEOM* lwgeom);
2348
2349/*******************************************************************************
2350 * SQLMM internal functions
2351 ******************************************************************************/
2352
2356int lwgeom_has_arc(const LWGEOM *geom);
2362int lwgeom_type_arc(const LWGEOM *geom);
2366LWGEOM *lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad);
2371LWGEOM *lwgeom_unstroke(const LWGEOM *geom);
2372
2400
2429
2438extern LWGEOM* lwcurve_linearize(const LWGEOM *geom, double tol, LW_LINEARIZE_TOLERANCE_TYPE type, int flags);
2439
2440/*******************************************************************************
2441 * GEOS proxy functions on LWGEOM
2442 ******************************************************************************/
2443
2445const char* lwgeom_geos_version(void);
2446const char* lwgeom_geos_compiled_version(void);
2447
2449LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ;
2450
2451LWGEOM *lwgeom_normalize(const LWGEOM *geom);
2452LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2);
2453LWGEOM *lwgeom_intersection_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize);
2454LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2);
2455LWGEOM *lwgeom_difference_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize);
2456LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2);
2457LWGEOM *lwgeom_symdifference_prec(const LWGEOM* geom1, const LWGEOM* geom2, double gridSize);
2458LWGEOM *lwgeom_pointonsurface(const LWGEOM* geom);
2459LWGEOM *lwgeom_reduceprecision(const LWGEOM* geom, double gridSize);
2460LWGEOM *lwgeom_centroid(const LWGEOM* geom);
2461LWGEOM *lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2);
2462LWGEOM *lwgeom_union_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize);
2463LWGEOM *lwgeom_linemerge(const LWGEOM *geom1);
2464LWGEOM *lwgeom_linemerge_directed(const LWGEOM *geom1, int directed);
2465LWGEOM *lwgeom_unaryunion(const LWGEOM *geom1);
2466LWGEOM *lwgeom_unaryunion_prec(const LWGEOM *geom1, double gridSize);
2467LWGEOM *lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1);
2468LWCOLLECTION *lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices);
2469LWCOLLECTION *lwgeom_subdivide_prec(const LWGEOM *geom, uint32_t maxvertices, double gridSize);
2470
2478LWGEOM* lwgeom_snap(const LWGEOM* geom1, const LWGEOM* geom2, double tolerance);
2479
2480/*
2481 * Return the set of paths shared between two linear geometries,
2482 * and their direction (same or opposite).
2483 *
2484 * @param geom1 a lineal geometry
2485 * @param geom2 another lineal geometry
2486 */
2487LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
2488
2489/*
2490 * An offset curve against the input line.
2491 *
2492 * @param geom a lineal geometry or collection of them
2493 * @param size offset distance. Offset left if negative and right if positive
2494 * @param quadsegs number of quadrature segments in curves (try 8)
2495 * @param joinStyle (1 = round, 2 = mitre, 3 = bevel)
2496 * @param mitreLimit (try 5.0)
2497 * @return derived geometry (linestring or multilinestring)
2498 *
2499 */
2500LWGEOM* lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit);
2501
2502/*
2503 * Return true if the input geometry is "simple" as per OGC defn.
2504 *
2505 * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called
2506 * in that case)
2507 */
2508int lwgeom_is_simple(const LWGEOM *lwgeom);
2509
2510
2511/*******************************************************************************
2512 * PROJ4-dependent extra functions on LWGEOM
2513 ******************************************************************************/
2514
2515int lwgeom_transform_from_str(LWGEOM *geom, const char* instr, const char* outstr);
2521int lwgeom_transform(LWGEOM *geom, LWPROJ* pj);
2522int ptarray_transform(POINTARRAY *pa, LWPROJ* pj);
2523int box3d_transform(GBOX *box, LWPROJ *pj);
2524
2530LWPROJ *lwproj_from_str(const char* str_in, const char* str_out);
2531
2542int lwgeom_transform_pipeline(LWGEOM *geom, const char* pipeline, bool is_forward);
2543
2555LWPROJ *lwproj_from_str_pipeline(const char* str_pipeline, bool is_forward);
2556
2557
2558/*******************************************************************************
2559 * GEOS-dependent extra functions on LWGEOM
2560 ******************************************************************************/
2561
2569LWGEOM* lwgeom_buildarea(const LWGEOM *geom) ;
2570
2575LWGEOM* lwgeom_make_valid_params(LWGEOM* geom, char *make_valid_params);
2576
2577/*
2578 * Split (multi)polygon by line; (multi)line by (multi)line,
2579 * (multi)point or (multi)polygon boundary.
2580 *
2581 * Collections are accepted as first argument.
2582 * Returns all obtained pieces as a collection.
2583 */
2584LWGEOM* lwgeom_split(const LWGEOM* lwgeom_in, const LWGEOM* blade_in);
2585
2586/*
2587 * Fully node a set of linestrings, using the least nodes preserving
2588 * all the input ones.
2589 */
2590LWGEOM* lwgeom_node(const LWGEOM* lwgeom_in);
2591
2601LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly);
2602
2603
2613LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
2614
2615#if POSTGIS_GEOS_VERSION >= 31100
2626LWGEOM* lwgeom_concavehull(const LWGEOM* geom, double ratio, uint32_t allow_holes);
2627
2638LWGEOM*
2639lwgeom_simplify_polygonal(const LWGEOM* geom, double vertex_fraction, uint32_t is_outer);
2640
2648
2649#endif
2650
2660int * lwgeom_cluster_kmeans(const LWGEOM **geoms, uint32_t n, uint32_t k, double max_radius);
2661
2662#include "lwinline.h"
2663
2664#endif /* !defined _LIBLWGEOM_H */
2665
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
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
Definition lwgeom_api.c:614
lwvarlena_t * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
const LWGEOM * lwcollection_getsubcurve(const LWCOMPOUND *compound, uint32_t gnum)
Definition lwcompound.c:42
char * lwpoint_to_latlon(const LWPOINT *p, const char *format)
Definition lwprint.c:437
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:1081
LWGEOM * lwgeom_linemerge_directed(const LWGEOM *geom1, int directed)
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:60
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition lwline.c:357
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition lwgeom.c:332
lwvarlena_t * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition lwout_gml.c:1081
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:735
LW_LINEARIZE_TOLERANCE_TYPE
Semantic of the tolerance argument passed to lwcurve_linearize.
Definition liblwgeom.h:2377
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_ANGLE
Tolerance expresses the maximum angle between the radii generating approximation line vertices,...
Definition liblwgeom.h:2398
@ LW_LINEARIZE_TOLERANCE_TYPE_SEGS_PER_QUAD
Tolerance expresses the number of segments to use for each quarter of circle (quadrant).
Definition liblwgeom.h:2383
@ 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:2390
LWPOINT * lwline_interpolate_point_3d(const LWLINE *line, double distance)
Interpolate one point along a line in 3D.
Definition lwline.c:615
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)
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition lwout_wkb.c:845
LWGEOM * lwgeom_symdifference_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition lwgeom.c:992
GBOX * gbox_from_string(const char *str)
Warning, do not use this function, it is very particular about inputs.
Definition gbox.c:376
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition lwgeom_api.c:107
lwvarlena_t * lwgeom_to_x3d3(const LWGEOM *geom, int precision, int opts, const char *defid)
Definition lwout_x3d.c:37
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition lwgeom.c:619
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:658
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
LWTIN * lwgeom_as_lwtin(const LWGEOM *lwgeom)
Definition lwgeom.c:305
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition lwgeom.c:983
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
Definition lwgeom.c:1222
LWORD_T
Ordinate names.
Definition liblwgeom.h:130
@ LWORD_Z
Definition liblwgeom.h:133
@ LWORD_M
Definition liblwgeom.h:134
@ LWORD_Y
Definition liblwgeom.h:132
@ LWORD_X
Definition liblwgeom.h:131
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition lwgeom_api.c:662
void(*) typedef void(*) voi lwgeom_set_handlers)(lwallocator allocator, lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, lwreporter noticereporter)
Install custom memory management and error handling functions you want your application to use.
size_t gbox_serialized_size(lwflags_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form.
Definition gbox.c:452
void lwmpoly_release(LWMPOLY *lwpoly)
Definition lwmpoly.c:34
int ptarray_closest_segment_2d(const POINTARRAY *pa, const POINT2D *qp, double *dist)
Definition ptarray.c:1452
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:955
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition lwline.c:538
void * lwrealloc(void *mem, size_t size)
Definition lwutil.c:242
void(*) typedef void(* lwdebuglogger)(int level, const char *fmt, va_list ap) __attribute__((format(printf
Definition liblwgeom.h:247
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:445
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
int lwgeom_is_unitary(const LWGEOM *geom)
Determine whether a Geometry is a bag of sub-geometries.
Definition lwgeom.c:1168
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition measures.c:2344
int lwgeom_has_orientation(const LWGEOM *lwgeom, int orientation)
Tests that geometry is oriented LW_CLOCKWISE or LW_COUNTERCLOCKWISE.
Definition lwgeom.c:93
double ptarray_locate_point_spheroid(const POINTARRAY *pa, const POINT4D *p4d, const SPHEROID *s, double tolerance, double *mindistout, POINT4D *proj4d)
Locate a point along the point array defining a geographic line.
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition lwgeom.c:1851
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:180
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:2249
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:696
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:389
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures.c:55
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:2408
LWMPOLY * lwmpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwmpoly.c:40
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
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:312
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:1638
int lwgeom_has_rings(const LWGEOM *geom)
Is this a type that has rings enclosing an area, but is not a collection of areas?...
Definition lwgeom.c:1174
double lwpoint_get_m(const LWPOINT *point)
Definition lwpoint.c:107
void() lwinterrupt_callback(void)
Install a callback to be called periodically during algorithm execution.
Definition liblwgeom.h:291
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:2693
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:404
void lwpoint_free(LWPOINT *pt)
Definition lwpoint.c:213
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, gridspec *grid)
Definition lwgeom.c:2421
LWPOINT * lwpoint_project(const LWPOINT *lwpoint1, double distance, double azimuth)
Definition lwpoint.c:290
void lwgeom_longitude_shift(LWGEOM *lwgeom)
Definition lwgeom.c:1036
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:786
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:38
LWMPOINT * lwpoly_to_points(const LWPOLY *poly, uint32_t npoints, int32_t seed)
void lwpoint_release(LWPOINT *lwpoint)
Definition lwpoint.c:256
int ptarray_closest_vertex_2d(const POINTARRAY *pa, const POINT2D *qp, double *dist)
Definition ptarray.c:1485
int lwgeom_transform(LWGEOM *geom, LWPROJ *pj)
Transform (reproject) a geometry in-place.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures.c:43
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition ptarray.c:723
uint32_t lwcompound_num_curves(const LWCOMPOUND *compound)
Definition lwcompound.c:34
GSERIALIZED * gserialized_drop_gbox(GSERIALIZED *g)
Remove the bounding box from a GSERIALIZED.
Definition gserialized.c:81
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
Definition lwgeom.c:408
lwvarlena_t * lwgeom_to_hexwkb_varlena(const LWGEOM *geom, uint8_t variant)
Definition lwout_wkb.c:875
double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfullywithin calculations.
Definition measures3d.c:344
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:243
LWPOINT * lwgeom_project_spheroid_lwpoint(const LWPOINT *from, const LWPOINT *to, const SPHEROID *spheroid, double distance)
Calculate the location of a point on a spheroid, give a start point, end point and distance.
LWCURVEPOLY * lwcurvepoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwcurvepoly.c:35
LWGEOM * lwgeom_make_valid_params(LWGEOM *geom, char *make_valid_params)
uint32_t gserialized_get_version(const GSERIALIZED *g)
Return the serialization version.
Definition gserialized.c:71
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition lwline.c:319
LWGEOM * lwgeom_boundary(LWGEOM *lwgeom)
Definition lwgeom.c:2714
void(* lwfreeor)(void *mem)
Definition liblwgeom.h:244
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWGEOM * lwgeom_reverse(const LWGEOM *lwgeom)
Definition lwgeom.c:122
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition lwpoly.c:359
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Simplification.
Definition lwgeom.c:1984
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)
Convert linearized type into arc type, de-linearizing the strokes where possible.
Definition lwstroke.c:1271
double lwgeom_perimeter_2d(const LWGEOM *geom)
Definition lwgeom.c:2044
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:690
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:261
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:646
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:242
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
lwvarlena_t * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition lwout_kml.c:44
LWGEOM * geography_substring(const LWLINE *line, const SPHEROID *s, double from, double to, double tolerance)
Return the part of a line between two fractional locations.
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:252
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:1211
LWPOINT * lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, uint32_t where)
LWGEOM * lwcompound_as_lwgeom(const LWCOMPOUND *obj)
Definition lwgeom.c:352
lwvarlena_t * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition lwout_svg.c:559
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.
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom, double zval)
Definition lwgeom.c:827
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:299
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:708
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:116
const char * lwgeom_geos_compiled_version(void)
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:752
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:2650
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:915
char * lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection)
Definition lwutil.c:274
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
LWGEOM * lwgeom_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:448
LWGEOM * lwpsurface_as_lwgeom(const LWPSURFACE *obj)
Definition lwgeom.c:317
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:440
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:241
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition lwiterator.c:268
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
lwvarlena_t * lwgeom_to_wkb_varlena(const LWGEOM *geom, uint8_t variant)
Definition lwout_wkb.c:851
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition ptarray.c:1518
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:1695
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition lwgeom.c:877
char * hexbytes_from_bytes(const uint8_t *bytes, size_t size)
Definition lwout_wkb.c:40
LWGEOM * lwgeom_intersection_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition lwgeom_api.c:342
LWCOLLECTION * lwcollection_segmentize2d(const LWCOLLECTION *coll, double dist)
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures3d.c:122
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition lwgeom.c:1495
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition lwgeom.c:821
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
lwvarlena_t * lwgeom_to_geojson(const LWGEOM *geo, const char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
int box3d_transform(GBOX *box, LWPROJ *pj)
double lwgeom_length(const LWGEOM *geom)
Definition lwgeom.c:2066
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:1299
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:94
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition ptarray.c:1975
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:519
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:234
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition lwgeom.c:593
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:962
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:1196
void printBOX3D(BOX3D *b)
Definition lwgeom_api.c:434
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition lwgeom.c:710
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition lwgeom.c:2835
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:495
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition lwgeom.c:2165
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:243
LWGEOM * lwgeom_union_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
Definition lwcompound.c:282
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:245
double lwgeom_area(const LWGEOM *geom)
Definition lwgeom.c:1999
lwvarlena_t * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
int lwgeom_type_arc(const LWGEOM *geom)
Geometry type is one of the potentially "arc containing" types (circstring, multicurve,...
Definition lwstroke.c:89
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:1337
int lwgeom_has_patches(const LWGEOM *geom)
Definition lwgeom.c:1154
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:613
void printLWTIN(LWTIN *tin)
Definition lwtin.c:57
LW_LINEARIZE_FLAGS
Definition liblwgeom.h:2401
@ 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:2407
@ 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:2427
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
lwvarlena_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)
Convert LWGEOM to a char* in TWKB format.
Definition lwout_twkb.c:589
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:347
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:1389
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:808
int * lwgeom_cluster_kmeans(const LWGEOM **geoms, uint32_t n, uint32_t k, double max_radius)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition lwkmeans.c:321
void lwfree(void *mem)
Definition lwutil.c:248
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition measures.c:222
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
Definition lwgeom.c:252
LWGEOM * lwgeom_concavehull(const LWGEOM *geom, double ratio, uint32_t allow_holes)
Take a geometry and build the concave hull.
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:225
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition lwgeom.c:362
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
Definition lwgeom.c:1125
lwvarlena_t * lwgeom_to_wkt_varlena(const LWGEOM *geom, uint8_t variant, int precision)
Definition lwout_wkt.c:721
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
Definition ptarray.c:612
const LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, uint32_t gnum)
void lwcircstring_free(LWCIRCSTRING *curve)
void *(* lwreallocator)(void *mem, size_t size)
Definition liblwgeom.h:243
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:232
LWLINE * lwline_extend(const LWLINE *line, double distance_forward, double distance_backward)
Extend the ends of a line.
Definition lwline.c:682
double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
Definition measures3d.c:476
int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
LWPOINT * lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
Definition lwcompound.c:276
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition lwgeom.c:1569
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
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)
LWGEOM * lwgeom_triangulate_polygon(const LWGEOM *geom)
Take vertices of a polygon and build a constrained triangulation that respects the boundary of the po...
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition lwgeom.c:2111
LWPROJ * lwproj_from_str_pipeline(const char *str_pipeline, bool is_forward)
Allocate a new LWPROJ containing the reference to the PROJ's PJ using a PROJ pipeline definition:
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:279
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:398
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
Definition lwgeom.c:288
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition lwgeom.c:216
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:228
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition lwin_wkb.c:866
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:1687
@ LINE_MULTICROSS_END_RIGHT
Definition liblwgeom.h:1692
@ LINE_MULTICROSS_END_SAME_FIRST_LEFT
Definition liblwgeom.h:1693
@ LINE_MULTICROSS_END_LEFT
Definition liblwgeom.h:1691
@ LINE_CROSS_LEFT
Definition liblwgeom.h:1689
@ LINE_MULTICROSS_END_SAME_FIRST_RIGHT
Definition liblwgeom.h:1694
@ LINE_CROSS_RIGHT
Definition liblwgeom.h:1690
@ LINE_NO_CROSS
Definition liblwgeom.h:1688
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,...
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:311
double lwgeom_length_2d(const LWGEOM *geom)
Definition lwgeom.c:2088
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
Definition lwgeom.c:1447
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
lwvarlena_t * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition lwout_gml.c:920
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
Definition measures.c:212
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition ptarray.c:736
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
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:582
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:166
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:668
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Definition lwgeom.c:73
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:976
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)
int lwtype_is_unitary(uint32_t lwtype)
Definition lwgeom.c:1132
LWGEOM * lwgeom_reduceprecision(const LWGEOM *geom, double gridSize)
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition measures.c:2354
int gbox_within_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX is within the second on the 2d plane, LW_FALSE otherwise.
Definition gbox.c:351
GBOX * gbox_copy(const GBOX *gbox)
Return a copy of the GBOX, based on dimensionality of flags.
Definition gbox.c:438
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition lwgeom.c:327
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:530
POINT2D getPoint2d(const POINTARRAY *pa, uint32_t n)
Definition lwgeom_api.c:328
LWGEOM * lwcircstring_as_lwgeom(const LWCIRCSTRING *obj)
Definition lwgeom.c:342
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)
LWCOLLECTION * lwgeom_subdivide_prec(const LWGEOM *geom, uint32_t maxvertices, double gridSize)
Definition lwgeom.c:2619
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed)
void lwpoly_release(LWPOLY *lwpoly)
Definition lwpoly.c:305
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:783
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition lwgeom.c:207
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:374
LWGEOM * geography_interpolate_points(const LWLINE *line, double length_fraction, const SPHEROID *s, char repeat)
Interpolate a point along a geographic line.
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:2219
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:742
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)
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition lwgeom.c:270
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:1517
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition lwgeom_api.c:479
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
Add a component, allocating extra space if necessary.
Definition lwcompound.c:131
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:710
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfullywithin calculations.
Definition measures.c:192
lwvarlena_t * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition lwout_gml.c:1063
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:74
lwvarlena_t * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition lwout_gml.c:978
void lwpoly_free(LWPOLY *poly)
Definition lwpoly.c:175
int lwgeom_transform_pipeline(LWGEOM *geom, const char *pipeline, bool is_forward)
Transform (reproject) a geometry in-place using a PROJ pipeline.
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition gbox.c:53
void lwgeom_grid_in_place(LWGEOM *lwgeom, gridspec *grid)
Definition lwgeom.c:2317
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices)
Definition lwgeom.c:2642
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:49
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition lwutil.c:477
LWPSURFACE * lwgeom_as_lwpsurface(const LWGEOM *lwgeom)
Definition lwgeom.c:297
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:464
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Convert type with arcs into equivalent linearized type.
Definition lwstroke.c:871
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:771
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:334
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
LWGEOM * lwgeom_unaryunion_prec(const LWGEOM *geom1, double gridSize)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition lwgeom.c:496
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
double lwgeom_perimeter(const LWGEOM *geom)
Definition lwgeom.c:2022
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:969
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:322
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:940
LWGEOM * lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint)
Definition lwchaikins.c:182
LWGEOM * lwgeom_force_4d(const LWGEOM *geom, double zval, double mval)
Definition lwgeom.c:839
lwflags_t gserialized_get_lwflags(const GSERIALIZED *g)
Read standard lwflags from gserialized.
Definition gserialized.c:47
LWGEOM * lwgeom_simplify_polygonal(const LWGEOM *geom, double vertex_fraction, uint32_t is_outer)
Computes a boundary-respecting hull of a polygonal geometry, with hull shape determined by a target p...
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition lwgeom_api.c:369
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition lwgeom.c:357
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:842
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom, double mval)
Definition lwgeom.c:833
LWCOLLECTION * lwcollection_extract(const LWCOLLECTION *col, uint32_t type)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:723
float next_float_down(double d)
Definition lwgeom_api.c:53
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:838
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:61
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition lwin_wkt.c:921
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:238
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
Definition measures3d.c:110
int lwgeom_has_arc(const LWGEOM *geom)
Geometry includes at least one actual circular arc.
Definition lwstroke.c:55
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwtriangle.c:40
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:339
void lwmpoint_release(LWMPOINT *lwpoint)
Definition lwmpoint.c:33
LWPOINT * lwpoint_project_lwpoint(const LWPOINT *lwpoint1, const LWPOINT *lwpoint2, double distance)
Definition lwpoint.c:277
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...
LWPROJ * lwproj_from_str(const char *str_in, const char *str_out)
Allocate a new LWPROJ containing the reference to the PROJ's PJ If extra_geography_data is true,...
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
Definition lwline.c:285
void lwtriangle_release(LWTRIANGLE *lwtriangle)
Definition lwtriangle.c:119
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:337
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.
LWGEOM * lwgeom_difference_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
void printLWPSURFACE(LWPSURFACE *psurf)
Definition lwpsurface.c:57
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition lwgeom.c:799
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:643
void lwgeom_force_counterclockwise(LWGEOM *lwgeom)
Definition lwgeom.c:79
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
Definition lwgeom.c:1562
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
Definition lwline.c:337
void lwgeom_drop_srid(LWGEOM *lwgeom)
Definition lwgeom.c:793
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
Definition lwgeom.c:131
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
Definition measures3d.c:369
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:557
lwvarlena_t * lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m)
Definition lwout_twkb.c:636
enum LWORD_T LWORD
Ordinate names.
uint8_t * lwgeom_to_wkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition lwout_wkb.c:815
#define str(s)
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032
double afac
Definition liblwgeom.h:332
double xmax
Definition liblwgeom.h:340
double xmin
Definition liblwgeom.h:339
int32_t srid
Definition liblwgeom.h:341
double ymax
Definition liblwgeom.h:357
double zmax
Definition liblwgeom.h:359
double xmax
Definition liblwgeom.h:355
double zmin
Definition liblwgeom.h:358
double mmax
Definition liblwgeom.h:361
double ymin
Definition liblwgeom.h:356
double xmin
Definition liblwgeom.h:354
double mmin
Definition liblwgeom.h:360
lwflags_t flags
Definition liblwgeom.h:353
uint32_t size
Definition liblwgeom.h:444
uint8_t gflags
Definition liblwgeom.h:446
POINT2D * center
Definition liblwgeom.h:1846
uint8_t type
Definition liblwgeom.h:510
int32_t srid
Definition liblwgeom.h:508
lwflags_t flags
Definition liblwgeom.h:509
POINTARRAY * points
Definition liblwgeom.h:507
GBOX * bbox
Definition liblwgeom.h:506
lwflags_t flags
Definition liblwgeom.h:577
uint32_t ngeoms
Definition liblwgeom.h:580
uint32_t maxgeoms
Definition liblwgeom.h:581
uint8_t type
Definition liblwgeom.h:578
GBOX * bbox
Definition liblwgeom.h:574
LWGEOM ** geoms
Definition liblwgeom.h:575
int32_t srid
Definition liblwgeom.h:576
uint32_t maxgeoms
Definition liblwgeom.h:595
lwflags_t flags
Definition liblwgeom.h:591
int32_t srid
Definition liblwgeom.h:590
GBOX * bbox
Definition liblwgeom.h:588
uint32_t ngeoms
Definition liblwgeom.h:594
uint8_t type
Definition liblwgeom.h:592
LWGEOM ** geoms
Definition liblwgeom.h:589
int32_t srid
Definition liblwgeom.h:604
GBOX * bbox
Definition liblwgeom.h:602
uint8_t type
Definition liblwgeom.h:606
LWGEOM ** rings
Definition liblwgeom.h:603
lwflags_t flags
Definition liblwgeom.h:605
uint32_t nrings
Definition liblwgeom.h:608
uint32_t maxrings
Definition liblwgeom.h:609
void * data
Definition liblwgeom.h:459
uint8_t type
Definition liblwgeom.h:462
GBOX * bbox
Definition liblwgeom.h:458
int32_t srid
Definition liblwgeom.h:460
lwflags_t flags
Definition liblwgeom.h:461
lwflags_t flags
Definition liblwgeom.h:485
GBOX * bbox
Definition liblwgeom.h:482
POINTARRAY * points
Definition liblwgeom.h:483
uint8_t type
Definition liblwgeom.h:486
int32_t srid
Definition liblwgeom.h:484
uint32_t maxgeoms
Definition liblwgeom.h:623
LWGEOM ** geoms
Definition liblwgeom.h:617
GBOX * bbox
Definition liblwgeom.h:616
lwflags_t flags
Definition liblwgeom.h:619
uint32_t ngeoms
Definition liblwgeom.h:622
int32_t srid
Definition liblwgeom.h:618
uint8_t type
Definition liblwgeom.h:620
uint32_t maxgeoms
Definition liblwgeom.h:553
lwflags_t flags
Definition liblwgeom.h:549
GBOX * bbox
Definition liblwgeom.h:546
int32_t srid
Definition liblwgeom.h:548
LWLINE ** geoms
Definition liblwgeom.h:547
uint8_t type
Definition liblwgeom.h:550
uint32_t ngeoms
Definition liblwgeom.h:552
uint32_t maxgeoms
Definition liblwgeom.h:539
int32_t srid
Definition liblwgeom.h:534
GBOX * bbox
Definition liblwgeom.h:532
lwflags_t flags
Definition liblwgeom.h:535
uint32_t ngeoms
Definition liblwgeom.h:538
LWPOINT ** geoms
Definition liblwgeom.h:533
uint8_t type
Definition liblwgeom.h:536
uint8_t type
Definition liblwgeom.h:564
GBOX * bbox
Definition liblwgeom.h:560
uint32_t maxgeoms
Definition liblwgeom.h:567
uint32_t ngeoms
Definition liblwgeom.h:566
LWPOLY ** geoms
Definition liblwgeom.h:561
lwflags_t flags
Definition liblwgeom.h:563
int32_t srid
Definition liblwgeom.h:562
uint8_t type
Definition liblwgeom.h:634
int32_t srid
Definition liblwgeom.h:632
uint32_t maxgeoms
Definition liblwgeom.h:637
GBOX * bbox
Definition liblwgeom.h:630
uint32_t ngeoms
Definition liblwgeom.h:636
lwflags_t flags
Definition liblwgeom.h:633
LWGEOM ** geoms
Definition liblwgeom.h:631
POINTARRAY * point
Definition liblwgeom.h:471
uint8_t type
Definition liblwgeom.h:474
lwflags_t flags
Definition liblwgeom.h:473
GBOX * bbox
Definition liblwgeom.h:470
int32_t srid
Definition liblwgeom.h:472
POINTARRAY ** rings
Definition liblwgeom.h:519
uint8_t type
Definition liblwgeom.h:522
uint32_t maxrings
Definition liblwgeom.h:525
uint32_t nrings
Definition liblwgeom.h:524
GBOX * bbox
Definition liblwgeom.h:518
lwflags_t flags
Definition liblwgeom.h:521
int32_t srid
Definition liblwgeom.h:520
bool pipeline_is_forward
Definition liblwgeom.h:49
uint8_t source_is_latlong
Definition liblwgeom.h:52
double source_semi_major_metre
Definition liblwgeom.h:54
double source_semi_minor_metre
Definition liblwgeom.h:55
PJ * pj
Definition liblwgeom.h:46
lwflags_t flags
Definition liblwgeom.h:647
uint32_t maxgeoms
Definition liblwgeom.h:651
LWPOLY ** geoms
Definition liblwgeom.h:645
uint32_t ngeoms
Definition liblwgeom.h:650
uint8_t type
Definition liblwgeom.h:648
int32_t srid
Definition liblwgeom.h:646
GBOX * bbox
Definition liblwgeom.h:644
uint32_t ngeoms
Definition liblwgeom.h:664
int32_t srid
Definition liblwgeom.h:660
uint8_t type
Definition liblwgeom.h:662
lwflags_t flags
Definition liblwgeom.h:661
LWTRIANGLE ** geoms
Definition liblwgeom.h:659
uint32_t maxgeoms
Definition liblwgeom.h:665
GBOX * bbox
Definition liblwgeom.h:658
int32_t srid
Definition liblwgeom.h:496
uint8_t type
Definition liblwgeom.h:498
GBOX * bbox
Definition liblwgeom.h:494
lwflags_t flags
Definition liblwgeom.h:497
POINTARRAY * points
Definition liblwgeom.h:495
double x
Definition liblwgeom.h:390
double m
Definition liblwgeom.h:408
double x
Definition liblwgeom.h:396
double x
Definition liblwgeom.h:402
double m
Definition liblwgeom.h:414
lwflags_t flags
Definition liblwgeom.h:431
uint32_t maxpoints
Definition liblwgeom.h:428
uint32_t npoints
Definition liblwgeom.h:427
uint8_t * serialized_pointlist
Definition liblwgeom.h:434
double e_sq
Definition liblwgeom.h:379
double e
Definition liblwgeom.h:378
double radius
Definition liblwgeom.h:380
double a
Definition liblwgeom.h:375
double b
Definition liblwgeom.h:376
double f
Definition liblwgeom.h:377
double mscale
Definition liblwgeom.h:1412
double zscale
Definition liblwgeom.h:1411
double xscale
Definition liblwgeom.h:1409
double ipm
Definition liblwgeom.h:1404
double zsize
Definition liblwgeom.h:1407
double ysize
Definition liblwgeom.h:1406
double xsize
Definition liblwgeom.h:1405
double yscale
Definition liblwgeom.h:1410
double ipx
Definition liblwgeom.h:1401
double msize
Definition liblwgeom.h:1408
double ipy
Definition liblwgeom.h:1402
double ipz
Definition liblwgeom.h:1403
Snap-to-grid.
Definition liblwgeom.h:1400
uint32_t size
Definition liblwgeom.h:307
char data[]
Definition liblwgeom.h:308
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
Definition liblwgeom.h:2157