38 #define AUTOFIX LW_TRUE
39 #define LWGEOM_GEOS_ERRMSG_MAXSIZE 256
56 #define GEOS_FREE(...) \
58 geos_destroy((sizeof((void*[]){__VA_ARGS__})/sizeof(void*)), __VA_ARGS__); \
64 lwerror("%s: GEOS Error: %s", __func__, lwgeom_geos_errmsg); \
69 #define GEOS_FAIL_DEBUG() \
72 lwdebug(1, "%s: GEOS Error: %s", __func__, lwgeom_geos_errmsg); \
76 #define GEOS_FREE_AND_FAIL(...) \
78 GEOS_FREE(__VA_ARGS__); \
82 #define GEOS_FREE_AND_FAIL_DEBUG(...) \
85 GEOS_FREE(__VA_ARGS__); \
91 #define RESULT_SRID(...) \
92 (get_result_srid((sizeof((const void*[]){__VA_ARGS__})/sizeof(void*)), __func__, __VA_ARGS__))
101 GEOSGeometry* g = va_arg(ap, GEOSGeometry*);
124 POINT4D point = { 0.0, 0.0, 0.0, 0.0 };
126 LWDEBUG(2,
"ptarray_fromGEOSCoordSeq called");
128 if (!GEOSCoordSeq_getSize(cs, &size))
lwerror(
"Exception thrown");
130 LWDEBUGF(4,
" GEOSCoordSeq size: %d", size);
134 if (!GEOSCoordSeq_getDimensions(cs, &dims))
lwerror(
"Exception thrown");
136 LWDEBUGF(4,
" GEOSCoordSeq dimensions: %d", dims);
139 if (dims > 3) dims = 3;
142 LWDEBUGF(4,
" output dimensions: %d", dims);
146 for (i = 0; i < size; i++)
148 #if POSTGIS_GEOS_VERSION < 38
149 GEOSCoordSeq_getX(cs, i, &(point.
x));
150 GEOSCoordSeq_getY(cs, i, &(point.
y));
151 if (dims >= 3) GEOSCoordSeq_getZ(cs, i, &(point.
z));
154 GEOSCoordSeq_getXYZ(cs, i, &(point.
x), &(point.
y), &(point.
z));
156 GEOSCoordSeq_getXY(cs, i, &(point.
x), &(point.
y));
168 int type = GEOSGeomTypeId(geom);
169 int SRID = GEOSGetSRID(geom);
174 if (want3d && !GEOSHasZ(geom))
176 LWDEBUG(3,
"Geometry has no Z, won't provide one");
182 const GEOSCoordSequence* cs;
184 const GEOSGeometry* g;
189 LWDEBUG(4,
"lwgeom_from_geometry: it's a Point");
190 cs = GEOSGeom_getCoordSeq(geom);
195 case GEOS_LINESTRING:
196 case GEOS_LINEARRING:
197 LWDEBUG(4,
"lwgeom_from_geometry: it's a LineString or LinearRing");
200 cs = GEOSGeom_getCoordSeq(geom);
205 LWDEBUG(4,
"lwgeom_from_geometry: it's a Polygon");
207 ngeoms = GEOSGetNumInteriorRings(geom);
209 g = GEOSGetExteriorRing(geom);
210 cs = GEOSGeom_getCoordSeq(g);
212 for (i = 0; i < ngeoms; i++)
214 g = GEOSGetInteriorRingN(geom, i);
215 cs = GEOSGeom_getCoordSeq(g);
220 case GEOS_MULTIPOINT:
221 case GEOS_MULTILINESTRING:
222 case GEOS_MULTIPOLYGON:
223 case GEOS_GEOMETRYCOLLECTION:
224 LWDEBUG(4,
"lwgeom_from_geometry: it's a Collection or Multi");
226 ngeoms = GEOSGetNumGeometries(geom);
231 for (i = 0; i < ngeoms; i++)
233 g = GEOSGetGeometryN(geom, i);
240 lwerror(
"GEOS2LWGEOM: unknown geometry type: %d",
type);
252 int append_points = 0;
263 lwerror(
"ptarray_to_GEOSCoordSeq called with fix_ring and 0 vertices in ring, cannot fix");
273 if (!(sq = GEOSCoordSeq_create(pa->
npoints + append_points, dims)))
275 lwerror(
"Error creating GEOS Coordinate Sequence");
279 for (i = 0; i < pa->
npoints; i++)
285 LWDEBUGF(4,
"Point: %g,%g,%g", p3d->
x, p3d->
y, p3d->
z);
293 #if POSTGIS_GEOS_VERSION < 38
294 GEOSCoordSeq_setX(sq, i, p2d->
x);
295 GEOSCoordSeq_setY(sq, i, p2d->
y);
296 if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->
z);
299 GEOSCoordSeq_setXYZ(sq, i, p2d->
x, p2d->
y, p3d->
z);
301 GEOSCoordSeq_setXY(sq, i, p2d->
x, p2d->
y);
315 for (i = pa->
npoints; i < pa->npoints + append_points; i++)
317 #if POSTGIS_GEOS_VERSION < 38
318 GEOSCoordSeq_setX(sq, i, p2d->
x);
319 GEOSCoordSeq_setY(sq, i, p2d->
y);
321 GEOSCoordSeq_setXY(sq, i, p2d->
x, p2d->
y);
324 if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->
z);
331 static inline GEOSGeometry*
337 g = GEOSGeom_createLinearRing(sq);
344 GEOSGeometry* envelope;
346 GEOSCoordSequence* seq = GEOSCoordSeq_create(5, 2);
347 if (!seq)
return NULL;
349 #if POSTGIS_GEOS_VERSION < 38
350 GEOSCoordSeq_setX(seq, 0, box->
xmin);
351 GEOSCoordSeq_setY(seq, 0, box->
ymin);
353 GEOSCoordSeq_setX(seq, 1, box->
xmax);
354 GEOSCoordSeq_setY(seq, 1, box->
ymin);
356 GEOSCoordSeq_setX(seq, 2, box->
xmax);
357 GEOSCoordSeq_setY(seq, 2, box->
ymax);
359 GEOSCoordSeq_setX(seq, 3, box->
xmin);
360 GEOSCoordSeq_setY(seq, 3, box->
ymax);
362 GEOSCoordSeq_setX(seq, 4, box->
xmin);
363 GEOSCoordSeq_setY(seq, 4, box->
ymin);
365 GEOSCoordSeq_setXY(seq, 0, box->
xmin, box->
ymin);
366 GEOSCoordSeq_setXY(seq, 1, box->
xmax, box->
ymin);
367 GEOSCoordSeq_setXY(seq, 2, box->
xmax, box->
ymax);
368 GEOSCoordSeq_setXY(seq, 3, box->
xmin, box->
ymax);
369 GEOSCoordSeq_setXY(seq, 4, box->
xmin, box->
ymin);
372 ring = GEOSGeom_createLinearRing(seq);
375 GEOSCoordSeq_destroy(seq);
379 envelope = GEOSGeom_createPolygon(ring, NULL, 0);
382 GEOSGeom_destroy(ring);
394 GEOSGeom* geoms = NULL;
397 #if LWDEBUG_LEVEL >= 4
413 GEOSGeometry* g =
LWGEOM2GEOS(lwgeom_stroked, autofix);
423 switch (lwgeom->
type)
429 g = GEOSGeom_createEmptyPolygon();
432 #if POSTGIS_GEOS_VERSION < 38
434 g = GEOSGeom_createPoint(sq);
439 g = GEOSGeom_createPoint(sq);
444 g = GEOSGeom_createPointFromXY(p->
x, p->
y);
463 g = GEOSGeom_createLineString(sq);
470 g = GEOSGeom_createEmptyPolygon();
474 if (!shell)
return NULL;
475 ngeoms = lwpoly->
nrings - 1;
476 if (ngeoms > 0) geoms =
lwalloc(
sizeof(GEOSGeom) * ngeoms);
478 for (i = 1; i < lwpoly->
nrings; i++)
484 for (k = 0; k < i - 1; k++)
485 GEOSGeom_destroy(geoms[k]);
487 GEOSGeom_destroy(shell);
491 g = GEOSGeom_createPolygon(shell, geoms, ngeoms);
501 geostype = GEOS_MULTIPOINT;
503 geostype = GEOS_MULTILINESTRING;
505 geostype = GEOS_MULTIPOLYGON;
507 geostype = GEOS_GEOMETRYCOLLECTION;
512 if (ngeoms > 0) geoms =
lwalloc(
sizeof(GEOSGeom) * ngeoms);
515 for (i = 0; i < ngeoms; ++i)
525 for (k = 0; k < j; k++)
526 GEOSGeom_destroy(geoms[k]);
532 g = GEOSGeom_createCollection(geostype, geoms, j);
533 if (ngeoms > 0)
lwfree(geoms);
542 GEOSSetSRID(g, lwgeom->
srid);
544 #if LWDEBUG_LEVEL >= 4
545 wkt = GEOSGeomToWKT(g);
546 LWDEBUGF(4,
"LWGEOM2GEOS: GEOSGeom: %s", wkt);
556 GEOSCoordSequence* seq = GEOSCoordSeq_create(1, 2);
557 GEOSGeometry* geom = NULL;
559 if (!seq)
return NULL;
561 #if POSTGIS_GEOS_VERSION < 38
562 GEOSCoordSeq_setX(seq, 0,
x);
563 GEOSCoordSeq_setY(seq, 0,
y);
565 GEOSCoordSeq_setXY(seq, 0,
x,
y);
568 geom = GEOSGeom_createPoint(seq);
569 if (!geom) GEOSCoordSeq_destroy(seq);
576 GEOSCoordSequence* seq = GEOSCoordSeq_create(2, 2);
577 GEOSGeometry* geom = NULL;
579 if (!seq)
return NULL;
581 #if POSTGIS_GEOS_VERSION < 38
582 GEOSCoordSeq_setX(seq, 0, x1);
583 GEOSCoordSeq_setY(seq, 0, y1);
584 GEOSCoordSeq_setX(seq, 1, x2);
585 GEOSCoordSeq_setY(seq, 1, y2);
587 GEOSCoordSeq_setXY(seq, 0, x1, y1);
588 GEOSCoordSeq_setXY(seq, 1, x2, y2);
591 geom = GEOSGeom_createLineString(seq);
592 if (!geom) GEOSCoordSeq_destroy(seq);
599 const char* ver = GEOSversion();
609 va_start(ap, funcname);
612 for(i = 0; i <
count; i++)
617 lwerror(
"%s: Geometry is null", funcname);
628 lwerror(
"%s: Operation on mixed SRID geometries (%d != %d)", funcname, srid, g->
srid);
651 GEOSSetSRID(g, srid);
682 g3 = GEOSIntersection(g1, g2);
685 GEOSSetSRID(g3, srid);
711 g3 = GEOSLineMerge(g1);
714 GEOSSetSRID(g3, srid);
742 g3 = GEOSUnaryUnion(g1);
745 GEOSSetSRID(g3, srid);
761 GEOSGeometry *g1, *g2, *g3;
776 g3 = GEOSDifference(g1, g2);
779 GEOSSetSRID(g3, srid);
794 GEOSGeometry *g1, *g2, *g3;
809 g3 = GEOSSymDifference(g1, g2);
812 GEOSSetSRID(g3, srid);
827 GEOSGeometry *g1, *g3;
841 g3 = GEOSGetCentroid(g1);
844 GEOSSetSRID(g3, srid);
860 GEOSGeometry *g1, *g3;
874 g3 = GEOSPointOnSurface(g1);
877 GEOSSetSRID(g3, srid);
893 GEOSGeometry *g1, *g2, *g3;
908 g3 = GEOSUnion(g1, g2);
911 GEOSSetSRID(g3, srid);
924 GEOSGeometry *g1, *g3;
938 if (!(g3 = GEOSClipByRect(g1, x1, y1, x2, y2)))
954 #if POSTGIS_GEOS_VERSION < 38
955 typedef struct Face_t
957 const GEOSGeometry* geom;
960 struct Face_t* parent;
963 static Face* newFace(
const GEOSGeometry* g);
964 static void delFace(Face* f);
965 static unsigned int countParens(
const Face* f);
966 static void findFaceHoles(Face** faces,
int nfaces);
969 newFace(
const GEOSGeometry* g)
971 Face* f =
lwalloc(
sizeof(Face));
973 f->env = GEOSEnvelope(f->geom);
974 GEOSArea(f->env, &f->envarea);
980 countParens(
const Face* f)
982 unsigned int pcount = 0;
995 GEOSGeom_destroy(f->env);
1000 compare_by_envarea(
const void* g1,
const void* g2)
1002 Face* f1 = *(Face**)g1;
1003 Face* f2 = *(Face**)g2;
1004 double n1 = f1->envarea;
1005 double n2 = f2->envarea;
1007 if (n1 < n2)
return 1;
1008 if (n1 > n2)
return -1;
1014 findFaceHoles(Face** faces,
int nfaces)
1019 qsort(faces, nfaces,
sizeof(Face*), compare_by_envarea);
1020 for (i = 0; i < nfaces; ++i)
1023 int nholes = GEOSGetNumInteriorRings(f->geom);
1024 LWDEBUGF(2,
"Scanning face %d with env area %g and %d holes", i, f->envarea, nholes);
1025 for (h = 0; h < nholes; ++h)
1027 const GEOSGeometry* hole = GEOSGetInteriorRingN(f->geom, h);
1029 "Looking for hole %d/%d of face %d among %d other faces",
1034 for (j = i + 1; j < nfaces; ++j)
1036 const GEOSGeometry* f2er;
1037 Face* f2 = faces[j];
1038 if (f2->parent)
continue;
1039 f2er = GEOSGetExteriorRing(f2->geom);
1042 if (GEOSEquals(f2er, hole))
1044 LWDEBUGF(2,
"Hole %d/%d of face %d is face %d", h + 1, nholes, i, j);
1053 static GEOSGeometry*
1054 collectFacesWithEvenAncestors(Face** faces,
int nfaces)
1056 GEOSGeometry** geoms =
lwalloc(
sizeof(GEOSGeometry*) * nfaces);
1058 unsigned int ngeoms = 0;
1061 for (i = 0; i < nfaces; ++i)
1064 if (countParens(f) % 2)
continue;
1065 geoms[ngeoms++] = GEOSGeom_clone(f->geom);
1068 ret = GEOSGeom_createCollection(GEOS_MULTIPOLYGON, geoms, ngeoms);
1077 GEOSGeometry *geos_result, *shp;
1078 GEOSGeometry
const* vgeoms[1];
1080 int srid = GEOSGetSRID(geom_in);
1082 #if POSTGIS_DEBUG_LEVEL >= 3
1087 vgeoms[0] = geom_in;
1088 geos_result = GEOSPolygonize(vgeoms, 1);
1090 LWDEBUGF(3,
"GEOSpolygonize returned @ %p", geos_result);
1093 if (!geos_result)
return 0;
1096 #if PARANOIA_LEVEL > 0
1099 GEOSGeom_destroy(geos_result);
1100 lwerror(
"%s [%d] Unexpected return from GEOSpolygonize", __FILE__, __LINE__);
1105 ngeoms = GEOSGetNumGeometries(geos_result);
1107 #if POSTGIS_DEBUG_LEVEL >= 3
1108 LWDEBUGF(3,
"GEOSpolygonize: ngeoms in polygonize output: %d", ngeoms);
1111 LWDEBUGF(3,
"GEOSpolygonize: polygonized:%s", geom_ewkt);
1119 GEOSSetSRID(geos_result, srid);
1126 tmp = (GEOSGeometry*)GEOSGetGeometryN(geos_result, 0);
1129 GEOSGeom_destroy(geos_result);
1132 shp = GEOSGeom_clone(tmp);
1133 GEOSGeom_destroy(geos_result);
1134 GEOSSetSRID(shp, srid);
1138 LWDEBUGF(2,
"Polygonize returned %d geoms", ngeoms);
1168 geoms =
lwalloc(
sizeof(Face**) * ngeoms);
1169 for (i = 0; i < ngeoms; ++i)
1170 geoms[i] = newFace(GEOSGetGeometryN(geos_result, i));
1173 findFaceHoles(geoms, ngeoms);
1176 tmp = collectFacesWithEvenAncestors(geoms, ngeoms);
1179 for (i = 0; i < ngeoms; ++i)
1184 GEOSGeom_destroy(geos_result);
1187 shp = GEOSUnionCascaded(tmp);
1190 GEOSGeom_destroy(tmp);
1194 GEOSGeom_destroy(tmp);
1196 GEOSSetSRID(shp, srid);
1208 GEOSGeometry *g1, *g3;
1219 #if POSTGIS_GEOS_VERSION < 38
1222 g3 = GEOSBuildArea(g1);
1226 GEOSSetSRID(g3, srid);
1229 if (GEOSGetNumGeometries(g3) == 0)
1258 simple = GEOSisSimple(g);
1259 GEOSGeom_destroy(g);
1285 GEOSSetSRID(g, srid);
1301 GEOSGeometry *g1, *g2, *g3;
1310 g3 = GEOSSnap(g1, g2, tolerance);
1313 GEOSSetSRID(g3, srid);
1328 GEOSGeometry *g1, *g2, *g3;
1337 g3 = GEOSSharedPaths(g1, g2);
1340 GEOSSetSRID(g3, srid);
1356 GEOSGeometry *g1, *g3;
1364 g3 = GEOSOffsetCurve(g1, size, quadsegs, joinStyle, mitreLimit);
1372 GEOSSetSRID(g3, srid);
1394 for (i = 0; i < col->
ngeoms; i++)
1421 tmp = result->
geoms[0];
1469 lwerror(
"lwgeom_offsetcurve: cannot node input");
1477 lwerror(
"lwgeom_offsetcurve: noded geometry cannot be offset");
1488 double area, bbox_area, bbox_width, bbox_height;
1491 uint32_t sample_npoints, sample_sqrt, sample_width, sample_height;
1492 double sample_cell_size;
1498 const GEOSPreparedGeometry* gprep;
1500 GEOSCoordSequence* gseq;
1505 const size_t size = 2 *
sizeof(int);
1506 char tmp[2 *
sizeof(int)];
1507 const size_t stride = 2 *
sizeof(int);
1511 lwerror(
"%s: only polygons supported", __func__);
1520 bbox = *(lwpoly->
bbox);
1523 bbox_width = bbox.
xmax - bbox.
xmin;
1524 bbox_height = bbox.
ymax - bbox.
ymin;
1525 bbox_area = bbox_width * bbox_height;
1527 if (
area == 0.0 || bbox_area == 0.0)
1529 lwerror(
"%s: zero area input polygon, TBD", __func__);
1534 sample_npoints = npoints * bbox_area /
area;
1539 sample_sqrt = lround(sqrt(sample_npoints));
1540 if (sample_sqrt == 0) sample_sqrt = 1;
1543 if (bbox_width > bbox_height)
1545 sample_width = sample_sqrt;
1546 sample_height = ceil((
double)sample_npoints / (
double)sample_width);
1547 sample_cell_size = bbox_width / sample_width;
1551 sample_height = sample_sqrt;
1552 sample_width = ceil((
double)sample_npoints / (
double)sample_height);
1553 sample_cell_size = bbox_height / sample_height;
1564 gprep = GEOSPrepare(g);
1575 cells =
lwalloc(2 *
sizeof(
int) * sample_height * sample_width);
1576 for (i = 0; i < sample_width; i++)
1578 for (j = 0; j < sample_height; j++)
1580 cells[2 * (i * sample_height + j)] = i;
1581 cells[2 * (i * sample_height + j) + 1] = j;
1586 n = sample_height * sample_width;
1589 for (i = 0; i < n - 1; ++i)
1591 size_t rnd = (size_t)rand();
1592 size_t j = i + rnd / (RAND_MAX / (n - i) + 1);
1594 memcpy(tmp, (
char *)cells + j * stride, size);
1595 memcpy((
char *)cells + j * stride, (
char *)cells + i * stride, size);
1596 memcpy((
char *)cells + i * stride, tmp, size);
1601 while (npoints_generated < npoints)
1604 for (i = 0; i < sample_width * sample_height; i++)
1607 double y = bbox.
ymin + cells[2 * i] * sample_cell_size;
1608 double x = bbox.
xmin + cells[2 * i + 1] * sample_cell_size;
1609 x += rand() * sample_cell_size / RAND_MAX;
1610 y += rand() * sample_cell_size / RAND_MAX;
1611 if (
x >= bbox.
xmax ||
y >= bbox.
ymax)
continue;
1613 gseq = GEOSCoordSeq_create(1, 2);
1614 #if POSTGIS_GEOS_VERSION < 38
1615 GEOSCoordSeq_setX(gseq, 0,
x);
1616 GEOSCoordSeq_setY(gseq, 0,
y);
1618 GEOSCoordSeq_setXY(gseq, 0,
x,
y);
1620 gpt = GEOSGeom_createPoint(gseq);
1622 contains = GEOSPreparedIntersects(gprep, gpt);
1624 GEOSGeom_destroy(gpt);
1628 GEOSPreparedGeom_destroy(gprep);
1629 GEOSGeom_destroy(g);
1635 npoints_generated++;
1637 if (npoints_generated == npoints)
1646 if (npoints_tested % 10000 == 0)
1647 LW_ON_INTERRUPT(GEOSPreparedGeom_destroy(gprep); GEOSGeom_destroy(g);
return NULL);
1651 if (done || iterations > 100)
break;
1654 GEOSPreparedGeom_destroy(gprep);
1655 GEOSGeom_destroy(g);
1673 lwerror(
"%s: only multipolygons supported", __func__);
1680 for (i = 0; i < lwmpoly->
ngeoms; i++)
1683 int sub_npoints = lround(npoints * sub_area /
area);
1684 if (sub_npoints > 0)
1692 for (j = 0; j < sub_mpt->
ngeoms; j++)
1722 int type = GEOSGeomTypeId(geom);
1723 int SRID = GEOSGetSRID(geom);
1728 if (want3d && !GEOSHasZ(geom))
1730 LWDEBUG(3,
"Geometry has no Z, won't provide one");
1738 case GEOS_GEOMETRYCOLLECTION:
1739 LWDEBUG(4,
"lwgeom_from_geometry: it's a Collection or Multi");
1741 ngeoms = GEOSGetNumGeometries(geom);
1745 geoms =
lwalloc(ngeoms *
sizeof *geoms);
1748 lwerror(
"lwtin_from_geos: can't allocate geoms");
1751 for (i = 0; i < ngeoms; i++)
1753 const GEOSGeometry *poly, *ring;
1754 const GEOSCoordSequence* cs;
1757 poly = GEOSGetGeometryN(geom, i);
1758 ring = GEOSGetExteriorRing(poly);
1759 cs = GEOSGeom_getCoordSeq(ring);
1767 case GEOS_MULTIPOINT:
1768 case GEOS_MULTILINESTRING:
1769 case GEOS_MULTIPOLYGON:
1770 case GEOS_LINESTRING:
1771 case GEOS_LINEARRING:
1773 lwerror(
"lwtin_from_geos: invalid geometry type for tin: %d",
type);
1777 lwerror(
"GEOS2LWGEOM: unknown geometry type: %d",
type);
1793 GEOSGeometry *g1, *g3;
1795 if (output < 0 || output > 2)
1797 lwerror(
"%s: invalid output type specified %d", __func__, output);
1808 g3 = GEOSDelaunayTriangulation(g1, tolerance, output == 1);
1811 GEOSSetSRID(g3, srid);
1819 lwerror(
"%s: cannot convert output geometry", __func__);
1831 static GEOSCoordSequence*
1837 GEOSCoordSequence* coords;
1840 coords = GEOSCoordSeq_create(num_points, num_dims);
1841 if (!coords)
return NULL;
1846 if (i >= num_points)
1848 lwerror(
"Incorrect num_points provided to lwgeom_get_geos_coordseq_2d");
1849 GEOSCoordSeq_destroy(coords);
1854 #if POSTGIS_GEOS_VERSION < 38
1855 if (!GEOSCoordSeq_setX(coords, i, tmp.
x) || !GEOSCoordSeq_setY(coords, i, tmp.
y))
1857 if (!GEOSCoordSeq_setXY(coords, i, tmp.
x, tmp.
y))
1860 GEOSCoordSeq_destroy(coords);
1878 GEOSCoordSequence* coords;
1879 GEOSGeometry* geos_geom;
1880 GEOSGeometry* geos_env = NULL;
1881 GEOSGeometry* geos_result;
1896 if (!coords)
return NULL;
1898 geos_geom = GEOSGeom_createLineString(coords);
1901 GEOSCoordSeq_destroy(coords);
1907 geos_result = GEOSVoronoiDiagram(geos_geom, geos_env, tolerance, output_edges);
1909 GEOSGeom_destroy(geos_geom);
1910 if (env) GEOSGeom_destroy(geos_env);
1919 GEOSGeom_destroy(geos_result);
1923 return lwgeom_result;
#define LWGEOM_GEOS_ERRMSG_MAXSIZE
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
static LWGEOM * lwcollection_offsetcurve(const LWCOLLECTION *col, double size, int quadsegs, int joinStyle, double mitreLimit)
static GEOSGeometry * ptarray_to_GEOSLinearRing(const POINTARRAY *pa, uint8_t autofix)
LWGEOM * lwgeom_symdifference(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom)
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
GEOSGeometry * make_geos_point(double x, double y)
static LWGEOM * lwline_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit)
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t output)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
int lwgeom_is_simple(const LWGEOM *geom)
LWGEOM * lwgeom_pointonsurface(const LWGEOM *geom)
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
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.
LWMPOINT * lwmpoly_to_points(const LWMPOLY *lwmpoly, uint32_t npoints)
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints)
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
static int32_t get_result_srid(size_t count, const char *funcname,...)
#define GEOS_FREE_AND_FAIL_DEBUG(...)
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
#define GEOS_FAIL_DEBUG()
LWGEOM * lwgeom_linemerge(const LWGEOM *geom)
#define GEOS_FREE_AND_FAIL(...)
GEOSGeometry * make_geos_segment(double x1, double y1, double x2, double y2)
static void geos_destroy(size_t count,...)
LWMPOINT * lwpoly_to_points(const LWPOLY *lwpoly, uint32_t npoints)
GEOSGeometry * GBOX2GEOS(const GBOX *box)
const char * lwgeom_geos_version()
Return GEOS version string (not to be freed)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
GEOSCoordSeq ptarray_to_GEOSCoordSeq(const POINTARRAY *, uint8_t fix_ring)
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, uint8_t want3d)
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x1, double y1, double x2, double y2)
void lwgeom_geos_error(const char *fmt,...)
static GEOSCoordSequence * lwgeom_get_geos_coordseq_2d(const LWGEOM *g, uint32_t num_points)
LWTIN * lwtin_from_geos(const GEOSGeometry *geom, uint8_t want3d)
GEOSGeometry * LWGEOM_GEOS_buildArea(const GEOSGeometry *geom_in)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
LWPOINT * lwpoint_make2d(int srid, double x, double y)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
void lwgeom_free(LWGEOM *geom)
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.
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
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...
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
double lwgeom_area(const LWGEOM *geom)
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
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...
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
#define FLAGS_NDIMS(flags)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
void lwcollection_release(LWCOLLECTION *lwcollection)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
void lwcollection_free(LWCOLLECTION *col)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
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...
LWCOLLECTION * lwcollection_concat_in_place(LWCOLLECTION *col1, const LWCOLLECTION *col2)
Appends all geometries from col2 to col1 in place.
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
void * lwalloc(size_t size)
int ptarray_is_closed_2d(const POINTARRAY *pa)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
#define LW_TRUE
Return types for functions with status returns.
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
#define SRID_UNKNOWN
Unknown SRID value.
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
int lwgeom_has_arc(const LWGEOM *geom)
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
This library is the generic geometry handling section of PostGIS.
#define LW_ON_INTERRUPT(x)
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Datum area(PG_FUNCTION_ARGS)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Datum contains(PG_FUNCTION_ARGS)