28 #include "utils/array.h"
29 #include "utils/builtins.h"
30 #include "utils/elog.h"
31 #include "utils/geo_decls.h"
33 #include "../postgis_config.h"
36 #include "lwgeom_pg.h"
43 #define xstr(s) str(s)
50 Datum
ST_Area(PG_FUNCTION_ARGS);
136 size_t size = VARSIZE(geom);
137 PG_FREE_IF_COPY(geom, 0);
138 PG_RETURN_INT32(size);
150 size_t result_sz = strlen(lwresult) + 8;
155 snprintf(
result, result_sz,
"0:%s", lwresult);
160 snprintf(
result, result_sz,
"%s", lwresult);
166 summary = cstring_to_text(
result);
169 PG_FREE_IF_COPY(g, 0);
170 PG_RETURN_TEXT_P(summary);
176 char *ver = POSTGIS_VERSION;
177 text *
result = cstring_to_text(ver);
185 text *
result = cstring_to_text(ver);
193 text *
result = cstring_to_text(ver);
200 static char *rev =
xstr(POSTGIS_REVISION);
202 if (rev && rev[0] !=
'\0')
204 snprintf(ver, 32,
"%s", rev);
206 PG_RETURN_TEXT_P(cstring_to_text(ver));
208 else PG_RETURN_NULL();
214 char *ver = POSTGIS_BUILD_DATE;
215 text *
result = cstring_to_text(ver);
228 result = cstring_to_text(ver);
236 text *
result = cstring_to_text(ver);
251 PG_FREE_IF_COPY(geom, 0);
252 PG_RETURN_INT32(npoints);
266 PG_FREE_IF_COPY(geom, 0);
267 PG_RETURN_INT32(nrings);
286 PG_FREE_IF_COPY(geom, 0);
288 PG_RETURN_FLOAT8(area);
305 PG_FREE_IF_COPY(geom, 0);
306 PG_RETURN_FLOAT8(dist);
323 PG_FREE_IF_COPY(geom, 0);
324 PG_RETURN_FLOAT8(dist);
339 double perimeter = 0.0;
342 PG_FREE_IF_COPY(geom, 0);
343 PG_RETURN_FLOAT8(perimeter);
358 double perimeter = 0.0;
361 PG_FREE_IF_COPY(geom, 0);
362 PG_RETURN_FLOAT8(perimeter);
369 GSERIALIZED *pg_geom_in = PG_GETARG_GSERIALIZED_P(0);
375 PG_RETURN_POINTER(pg_geom_in);
379 pg_geom_out = geometry_serialize(lwg_out);
383 PG_FREE_IF_COPY(pg_geom_in, 0);
384 PG_RETURN_POINTER(pg_geom_out);
391 GSERIALIZED *pg_geom_in = PG_GETARG_GSERIALIZED_P(0);
394 double z = PG_NARGS() < 2 ? 0 : PG_GETARG_FLOAT8(1);
398 PG_RETURN_POINTER(pg_geom_in);
402 pg_geom_out = geometry_serialize(lwg_out);
406 PG_FREE_IF_COPY(pg_geom_in, 0);
407 PG_RETURN_POINTER(pg_geom_out);
414 GSERIALIZED *pg_geom_in = PG_GETARG_GSERIALIZED_P(0);
417 double m = PG_NARGS() < 2 ? 0 : PG_GETARG_FLOAT8(1);
421 PG_RETURN_POINTER(pg_geom_in);
425 pg_geom_out = geometry_serialize(lwg_out);
429 PG_FREE_IF_COPY(pg_geom_in, 0);
430 PG_RETURN_POINTER(pg_geom_out);
437 GSERIALIZED *pg_geom_in = PG_GETARG_GSERIALIZED_P(0);
440 double z = PG_NARGS() < 3 ? 0 : PG_GETARG_FLOAT8(1);
441 double m = PG_NARGS() < 3 ? 0 : PG_GETARG_FLOAT8(2);
445 PG_RETURN_POINTER(pg_geom_in);
449 pg_geom_out = geometry_serialize(lwg_out);
453 PG_FREE_IF_COPY(pg_geom_in, 0);
454 PG_RETURN_POINTER(pg_geom_out);
468 POSTGIS_DEBUG(2,
"LWGEOM_force_collection called");
477 PG_RETURN_POINTER(geom);
497 lwgeoms = palloc(
sizeof(
LWGEOM *));
502 result = geometry_serialize(lwgeom);
505 PG_FREE_IF_COPY(geom, 0);
506 PG_RETURN_POINTER(
result);
518 POSTGIS_DEBUG(2,
"LWGEOM_force_multi called");
536 PG_RETURN_POINTER(geom);
546 result = geometry_serialize(ogeom);
548 PG_FREE_IF_COPY(geom, 0);
550 PG_RETURN_POINTER(
result);
562 POSTGIS_DEBUG(2,
"LWGEOM_force_curve called");
569 result = geometry_serialize(ogeom);
571 PG_FREE_IF_COPY(geom, 0);
573 PG_RETURN_POINTER(
result);
587 POSTGIS_DEBUG(2,
"LWGEOM_force_sfs called");
590 if ((PG_NARGS() > 1) && (!PG_ARGISNULL(1)))
592 ver = PG_GETARG_TEXT_P(1);
594 if (!strncmp(VARDATA(ver),
"1.2", 3))
603 result = geometry_serialize(ogeom);
605 PG_FREE_IF_COPY(geom, 0);
607 PG_RETURN_POINTER(
result);
630 result = geometry_serialize(point);
635 PG_FREE_IF_COPY(geom1, 0);
636 PG_FREE_IF_COPY(geom2, 1);
637 PG_RETURN_POINTER(
result);
659 result = geometry_serialize(theline);
664 PG_FREE_IF_COPY(geom1, 0);
665 PG_FREE_IF_COPY(geom2, 1);
666 PG_RETURN_POINTER(
result);
688 result = geometry_serialize(theline);
693 PG_FREE_IF_COPY(geom1, 0);
694 PG_FREE_IF_COPY(geom2, 1);
695 PG_RETURN_POINTER(
result);
715 PG_FREE_IF_COPY(geom1, 0);
716 PG_FREE_IF_COPY(geom2, 1);
719 if (mindist < FLT_MAX)
720 PG_RETURN_FLOAT8(mindist);
736 double tolerance = PG_GETARG_FLOAT8(2);
742 elog(ERROR,
"Tolerance cannot be less than zero\n");
750 PG_RETURN_BOOL(
false);
755 PG_FREE_IF_COPY(geom1, 0);
756 PG_FREE_IF_COPY(geom2, 1);
759 PG_RETURN_BOOL(tolerance >= mindist);
777 PG_FREE_IF_COPY(geom1, 0);
778 PG_FREE_IF_COPY(geom2, 1);
782 PG_RETURN_FLOAT8(maxdist);
808 result = geometry_serialize(point);
814 PG_FREE_IF_COPY(geom1, 0);
815 PG_FREE_IF_COPY(geom2, 1);
816 PG_RETURN_POINTER(
result);
839 result = geometry_serialize(theline);
845 PG_FREE_IF_COPY(geom1, 0);
846 PG_FREE_IF_COPY(geom2, 1);
847 PG_RETURN_POINTER(
result);
870 result = geometry_serialize(theline);
876 PG_FREE_IF_COPY(geom1, 0);
877 PG_FREE_IF_COPY(geom2, 1);
878 PG_RETURN_POINTER(
result);
895 PG_FREE_IF_COPY(geom1, 0);
896 PG_FREE_IF_COPY(geom2, 1);
899 if (mindist < FLT_MAX)
900 PG_RETURN_FLOAT8(mindist);
918 PG_FREE_IF_COPY(geom1, 0);
919 PG_FREE_IF_COPY(geom2, 1);
922 PG_RETURN_BOOL(0.0 == mindist);
937 double tolerance = PG_GETARG_FLOAT8(2);
943 elog(ERROR,
"Tolerance cannot be less than zero\n");
951 PG_FREE_IF_COPY(geom1, 0);
952 PG_FREE_IF_COPY(geom2, 1);
956 PG_RETURN_BOOL(tolerance >= mindist);
970 double tolerance = PG_GETARG_FLOAT8(2);
976 elog(ERROR,
"Tolerance cannot be less than zero\n");
983 PG_FREE_IF_COPY(geom1, 0);
984 PG_FREE_IF_COPY(geom2, 1);
988 PG_RETURN_BOOL(tolerance >= maxdist);
1009 PG_FREE_IF_COPY(geom1, 0);
1010 PG_FREE_IF_COPY(geom2, 1);
1014 PG_RETURN_FLOAT8(maxdist);
1026 POSTGIS_DEBUG(2,
"LWGEOM_longitude_shift called.");
1028 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
1038 ret = geometry_serialize(lwgeom);
1046 PG_RETURN_POINTER(ret);
1054 LWGEOM *lwgeom_in, *lwgeom_out;
1059 POSTGIS_DEBUG(2,
"ST_WrapX called.");
1061 gdatum = PG_GETARG_DATUM(0);
1062 cutx = PG_GETARG_FLOAT8(1);
1063 amount = PG_GETARG_FLOAT8(2);
1067 geom_in = ((
GSERIALIZED *)PG_DETOAST_DATUM(gdatum));
1071 geom_out = geometry_serialize(lwgeom_out);
1075 PG_FREE_IF_COPY(geom_in, 0);
1077 PG_RETURN_POINTER(geom_out);
1083 Datum datum_line, datum_point;
1085 LWGEOM *lwgeom_line, *lwgeom_point;
1092 POSTGIS_DEBUG(2,
"ST_Scroll called.");
1094 datum_line = PG_GETARG_DATUM(0);
1095 datum_point = PG_GETARG_DATUM(1);
1097 ser_line = ((
GSERIALIZED *)PG_DETOAST_DATUM(datum_line));
1101 lwpgerror(
"First argument must be a line");
1105 ser_point = ((
GSERIALIZED *)PG_DETOAST_DATUM(datum_point));
1109 lwpgerror(
"Second argument must be a point");
1113 lwpgerror(
"Second argument must be a non-empty point");
1122 ser_out = geometry_serialize(lwgeom_line);
1125 PG_FREE_IF_COPY(ser_line, 0);
1126 PG_FREE_IF_COPY(ser_point, 0);
1128 PG_RETURN_POINTER(ser_out);
1135 double cx = PG_GETARG_FLOAT8(1);
1136 double cy = PG_GETARG_FLOAT8(2);
1137 double rr = PG_GETARG_FLOAT8(3);
1142 geom = PG_GETARG_GSERIALIZED_P(0);
1147 PG_FREE_IF_COPY(geom, 0);
1154 PG_FREE_IF_COPY(geom, 0);
1155 PG_RETURN_BOOL(inside);
1169 LWGEOM *lwgeoms[2], *outlwg;
1170 uint32 type1, type2;
1174 POSTGIS_DEBUG(2,
"LWGEOM_collect called.");
1177 if (PG_ARGISNULL(0) && PG_ARGISNULL(1))
1181 if (PG_ARGISNULL(0))
1182 PG_RETURN_DATUM(PG_GETARG_DATUM(1));
1185 if (PG_ARGISNULL(1))
1186 PG_RETURN_DATUM(PG_GETARG_DATUM(0));
1188 gser1 = PG_GETARG_GSERIALIZED_P(0);
1189 gser2 = PG_GETARG_GSERIALIZED_P(1);
1193 "LWGEOM_collect(%s, %s): call",
1200 elog(ERROR,
"Cannot ST_Collect geometries with differing dimensionality.");
1209 type1 = lwgeoms[0]->
type;
1210 type2 = lwgeoms[1]->
type;
1217 POSTGIS_DEBUGF(3,
" outtype = %d", outtype);
1226 result = geometry_serialize(outlwg);
1231 PG_FREE_IF_COPY(gser1, 0);
1232 PG_FREE_IF_COPY(gser2, 1);
1234 PG_RETURN_POINTER(
result);
1253 LWGEOM **lwgeoms, *outlwg;
1259 ArrayIterator iterator;
1263 POSTGIS_DEBUG(2,
"LWGEOM_collect_garray called.");
1265 if (PG_ARGISNULL(0))
1269 array = PG_GETARG_ARRAYTYPE_P(0);
1270 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1273 " array is %d-bytes in size, %ld w/out header",
1275 ARR_SIZE(array) - ARR_OVERHEAD_NONULLS(ARR_NDIM(array)));
1277 POSTGIS_DEBUGF(3,
"LWGEOM_collect_garray: array has %d elements", nelems);
1287 lwgeoms = palloc(
sizeof(
LWGEOM *) * nelems);
1291 iterator = array_create_iterator(array, 0, NULL);
1293 while (array_iterate(iterator, &
value, &isnull))
1307 POSTGIS_DEBUGF(3,
"%s: geom %d deserialized", __func__,
count);
1315 if (lwgeoms[
count]->bbox)
1326 if (lwgeoms[
count]->bbox)
1353 array_free_iterator(iterator);
1355 POSTGIS_DEBUGF(3,
"LWGEOM_collect_garray: outtype = %d", outtype);
1366 result = geometry_serialize(outlwg);
1368 PG_RETURN_POINTER(
result);
1383 POSTGIS_DEBUG(2,
"LWGEOM_line_from_mpoint called");
1386 ingeom = PG_GETARG_GSERIALIZED_P(0);
1390 elog(ERROR,
"makeline: input must be a multipoint");
1398 PG_FREE_IF_COPY(ingeom, 0);
1399 elog(ERROR,
"makeline: lwline_from_lwmpoint returned NULL");
1405 PG_FREE_IF_COPY(ingeom, 0);
1408 PG_RETURN_POINTER(
result);
1427 ArrayIterator iterator;
1431 POSTGIS_DEBUGF(2,
"%s called", __func__);
1434 if (PG_ARGISNULL(0))
1438 array = PG_GETARG_ARRAYTYPE_P(0);
1441 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1443 POSTGIS_DEBUGF(3,
"%s: array has %d elements", __func__, nelems);
1456 geoms = palloc(
sizeof(
LWGEOM *) * nelems);
1459 iterator = array_create_iterator(array, 0, NULL);
1461 while (array_iterate(iterator, &
value, &isnull))
1482 srid = geoms[ngeoms - 1]->
srid;
1488 POSTGIS_DEBUGF(3,
"%s: element %d deserialized", __func__, ngeoms);
1490 array_free_iterator(iterator);
1496 elog(NOTICE,
"No points or linestrings in input array");
1500 POSTGIS_DEBUGF(3,
"LWGEOM_makeline_garray: elements: %d", ngeoms);
1504 result = geometry_serialize(outlwg);
1506 PG_RETURN_POINTER(
result);
1521 POSTGIS_DEBUG(2,
"LWGEOM_makeline called.");
1524 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1525 pglwg2 = PG_GETARG_GSERIALIZED_P(1);
1530 elog(ERROR,
"Input geometries must be points or lines");
1543 PG_FREE_IF_COPY(pglwg1, 0);
1544 PG_FREE_IF_COPY(pglwg2, 1);
1548 PG_RETURN_POINTER(
result);
1559 ArrayType *array = NULL;
1561 const LWLINE *shell = NULL;
1562 const LWLINE **holes = NULL;
1568 POSTGIS_DEBUG(2,
"LWGEOM_makepoly called.");
1571 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1574 lwpgerror(
"Shell is not a line");
1581 array = PG_GETARG_ARRAYTYPE_P(1);
1582 nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1584 for (i = 0; i < nholes; i++)
1586 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1587 #pragma GCC diagnostic push
1588 #pragma GCC diagnostic ignored "-Wsign-compare"
1591 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1592 #pragma GCC diagnostic pop
1595 offset += INTALIGN(VARSIZE(g));
1598 lwpgerror(
"Hole %d is not a line", i);
1610 PG_FREE_IF_COPY(pglwg1, 0);
1612 for (i = 0; i < nholes; i++)
1617 PG_RETURN_POINTER(
result);
1635 POSTGIS_DEBUG(2,
"LWGEOM_expand called.");
1641 PG_RETURN_POINTER(geom);
1648 PG_RETURN_POINTER(geom);
1651 if (PG_NARGS() == 2)
1654 double d = PG_GETARG_FLOAT8(1);
1659 double dx = PG_GETARG_FLOAT8(1);
1660 double dy = PG_GETARG_FLOAT8(2);
1661 double dz = PG_GETARG_FLOAT8(3);
1662 double dm = PG_GETARG_FLOAT8(4);
1684 PG_FREE_IF_COPY(geom, 0);
1686 PG_RETURN_POINTER(
result);
1693 GSERIALIZED *pg_lwgeom = PG_GETARG_GSERIALIZED_P(0);
1707 PG_FREE_IF_COPY(pg_lwgeom, 0);
1714 out->low.x = gbox.
xmin;
1715 out->low.y = gbox.
ymin;
1716 out->high.x = gbox.
xmax;
1717 out->high.y = gbox.
ymax;
1718 PG_RETURN_POINTER(out);
1731 int32_t srid = lwgeom->
srid;
1740 PG_RETURN_POINTER(geom);
1746 PG_RETURN_POINTER(geom);
1816 PG_FREE_IF_COPY(geom, 0);
1818 PG_RETURN_POINTER(
result);
1839 LWGEOM *inlwgeom, *outlwgeom;
1842 POSTGIS_DEBUG(2,
"LWGEOM_segmentize2d called");
1844 ingeom = PG_GETARG_GSERIALIZED_P(0);
1845 dist = PG_GETARG_FLOAT8(1);
1852 PG_RETURN_POINTER(ingeom);
1859 elog(ERROR,
"ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1870 PG_RETURN_POINTER(ingeom);
1877 PG_FREE_IF_COPY(ingeom, 0);
1885 outgeom = geometry_serialize(outlwgeom);
1890 PG_FREE_IF_COPY(ingeom, 0);
1892 PG_RETURN_POINTER(outgeom);
1902 POSTGIS_DEBUG(2,
"LWGEOM_reverse called");
1904 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
1909 geom = geometry_serialize(lwgeom);
1911 PG_RETURN_POINTER(geom);
1921 POSTGIS_DEBUG(2,
"LWGEOM_force_clockwise_poly called");
1923 ingeom = PG_GETARG_GSERIALIZED_P_COPY(0);
1928 outgeom = geometry_serialize(lwgeom);
1931 PG_FREE_IF_COPY(ingeom, 0);
1932 PG_RETURN_POINTER(outgeom);
1942 PG_RETURN_POINTER(out);
1950 LWGEOM *lwgeom_in, *lwgeom_out;
1952 POSTGIS_DEBUG(2,
"ST_Normalize called");
1954 in = PG_GETARG_GSERIALIZED_P_COPY(0);
1957 POSTGIS_DEBUGF(3,
"Deserialized: %s",
lwgeom_summary(lwgeom_in, 0));
1960 POSTGIS_DEBUGF(3,
"Normalized: %s",
lwgeom_summary(lwgeom_out, 0));
1962 out = geometry_serialize(lwgeom_out);
1966 PG_FREE_IF_COPY(in, 0);
1968 PG_RETURN_POINTER(out);
1981 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
1988 PG_FREE_IF_COPY(in, 0);
1989 PG_RETURN_INT16(ret);
1995 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2002 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2009 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2011 PG_FREE_IF_COPY(in, 0);
2012 PG_RETURN_BOOL(
res);
2019 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2021 PG_FREE_IF_COPY(in, 0);
2022 PG_RETURN_INT16(ret);
2040 double x1, y1, x2, y2;
2043 POSTGIS_DEBUG(2,
"ST_MakeEnvelope called");
2045 x1 = PG_GETARG_FLOAT8(0);
2046 y1 = PG_GETARG_FLOAT8(1);
2047 x2 = PG_GETARG_FLOAT8(2);
2048 y2 = PG_GETARG_FLOAT8(3);
2051 srid = PG_GETARG_INT32(4);
2059 PG_RETURN_POINTER(
result);
2069 uint32_t worldTileSize;
2070 double tileGeoSizeX, tileGeoSizeY;
2071 double boundsWidth, boundsHeight;
2072 double x1, y1, x2, y2;
2083 POSTGIS_DEBUG(2,
"ST_TileEnvelope called");
2085 zoom = PG_GETARG_INT32(0);
2086 x = PG_GETARG_INT32(1);
2087 y = PG_GETARG_INT32(2);
2089 bounds = PG_GETARG_GSERIALIZED_P(3);
2098 elog(ERROR,
"%s: Unable to compute bbox", __func__);
2103 margin = PG_NARGS() < 4 ? 0 : PG_GETARG_FLOAT8(4);
2106 elog(ERROR,
"%s: Margin must not be less than -50%%, margin=%f", __func__, margin);
2108 boundsWidth = bbox.
xmax - bbox.
xmin;
2109 boundsHeight = bbox.
ymax - bbox.
ymin;
2110 if (boundsWidth <= 0 || boundsHeight <= 0)
2111 elog(ERROR,
"%s: Geometric bounds are too small", __func__);
2113 if (zoom < 0 || zoom >= 32)
2114 elog(ERROR,
"%s: Invalid tile zoom value, %d", __func__, zoom);
2116 zoomu = (uint32_t)zoom;
2117 worldTileSize = 0x01u << (zoomu > 31 ? 31 : zoomu);
2119 if (
x < 0 || (uint32_t)
x >= worldTileSize)
2120 elog(ERROR,
"%s: Invalid tile x value, %d", __func__,
x);
2121 if (
y < 0 || (uint32_t)
y >= worldTileSize)
2122 elog(ERROR,
"%s: Invalid tile y value, %d", __func__,
y);
2124 tileGeoSizeX = boundsWidth / worldTileSize;
2125 tileGeoSizeY = boundsHeight / worldTileSize;
2132 if ((1 + margin * 2) > worldTileSize)
2139 x1 = bbox.
xmin + tileGeoSizeX * (
x - margin);
2140 x2 = bbox.
xmin + tileGeoSizeX * (
x + 1 + margin);
2143 y1 = bbox.
ymax - tileGeoSizeY * (
y + 1 + margin);
2144 y2 = bbox.
ymax - tileGeoSizeY * (
y - margin);
2147 if (y1 < bbox.
ymin) y1 = bbox.
ymin;
2148 if (y2 > bbox.
ymax) y2 = bbox.
ymax;
2149 if (x1 < bbox.
xmin) x1 = bbox.
xmin;
2150 if (x2 > bbox.
xmax) x2 = bbox.
xmax;
2156 srid, x1, y1, x2, y2))));
2163 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_HEADER(0);
2175 POSTGIS_DEBUG(2,
"LWGEOM_makepoint called");
2177 x = PG_GETARG_FLOAT8(0);
2178 y = PG_GETARG_FLOAT8(1);
2180 if (PG_NARGS() == 2)
2182 else if (PG_NARGS() == 3)
2184 z = PG_GETARG_FLOAT8(2);
2187 else if (PG_NARGS() == 4)
2189 z = PG_GETARG_FLOAT8(2);
2190 m = PG_GETARG_FLOAT8(3);
2195 elog(ERROR,
"LWGEOM_makepoint: unsupported number of args: %d", PG_NARGS());
2201 PG_RETURN_POINTER(
result);
2207 double x = PG_GETARG_FLOAT8(0);
2208 double y = PG_GETARG_FLOAT8(1);
2209 int srid = PG_GETARG_INT32(2);
2212 PG_RETURN_POINTER(
result);
2218 double x = PG_GETARG_FLOAT8(0);
2219 double y = PG_GETARG_FLOAT8(1);
2220 double z = PG_GETARG_FLOAT8(2);
2221 int srid = PG_GETARG_INT32(3);
2224 PG_RETURN_POINTER(
result);
2230 double x = PG_GETARG_FLOAT8(0);
2231 double y = PG_GETARG_FLOAT8(1);
2232 double m = PG_GETARG_FLOAT8(2);
2233 int srid = PG_GETARG_INT32(3);
2236 PG_RETURN_POINTER(
result);
2242 double x = PG_GETARG_FLOAT8(0);
2243 double y = PG_GETARG_FLOAT8(1);
2244 double z = PG_GETARG_FLOAT8(2);
2245 double m = PG_GETARG_FLOAT8(3);
2246 int srid = PG_GETARG_INT32(4);
2249 PG_RETURN_POINTER(
result);
2260 POSTGIS_DEBUG(2,
"LWGEOM_makepoint3dm called.");
2262 x = PG_GETARG_FLOAT8(0);
2263 y = PG_GETARG_FLOAT8(1);
2264 m = PG_GETARG_FLOAT8(2);
2269 PG_RETURN_POINTER(
result);
2278 uint32_t uwhere = 0;
2280 POSTGIS_DEBUGF(2,
"%s called.", __func__);
2282 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2283 pglwg2 = PG_GETARG_GSERIALIZED_P(1);
2287 elog(ERROR,
"First argument must be a LINESTRING");
2293 elog(ERROR,
"Second argument must be a POINT");
2299 PG_RETURN_POINTER(pglwg1);
2304 if (PG_NARGS() <= 2)
2310 int32 where = PG_GETARG_INT32(2);
2317 elog(ERROR,
"%s: Invalid offset", __func__);
2332 elog(ERROR,
"Point insert failed");
2339 PG_FREE_IF_COPY(pglwg1, 0);
2340 PG_FREE_IF_COPY(pglwg2, 1);
2343 PG_RETURN_POINTER(
result);
2353 POSTGIS_DEBUG(2,
"LWGEOM_removepoint called.");
2355 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2356 which = PG_GETARG_INT32(1);
2360 elog(ERROR,
"First argument must be a LINESTRING");
2366 if (which < 0 || (uint32_t)which > line->
points->
npoints - 1)
2368 elog(ERROR,
"Point index out of range (%u..%u)", 0, line->
points->
npoints - 1);
2374 elog(ERROR,
"Can't remove points from a single segment line");
2385 PG_FREE_IF_COPY(pglwg1, 0);
2386 PG_RETURN_POINTER(
result);
2399 POSTGIS_DEBUG(2,
"LWGEOM_setpoint_linestring called.");
2402 pglwg1 = PG_GETARG_GSERIALIZED_P_COPY(0);
2404 which = PG_GETARG_INT32(1);
2405 pglwg2 = PG_GETARG_GSERIALIZED_P(2);
2412 elog(ERROR,
"Third argument must be a POINT");
2417 PG_FREE_IF_COPY(pglwg2, 2);
2424 elog(ERROR,
"First argument must be a LINESTRING");
2429 elog(ERROR,
"Line has no points");
2440 elog(ERROR,
"abs(Point index) out of range (-)(%u..%u)", 0, line->
points->
npoints - 1);
2454 PG_RETURN_POINTER(
result);
2487 geom = PG_GETARG_GSERIALIZED_P(0);
2491 PG_FREE_IF_COPY(geom, 0);
2492 lwpgerror(
"Argument must be POINT geometries");
2495 srid = lwpoint->
srid;
2498 PG_FREE_IF_COPY(geom, 0);
2499 lwpgerror(
"Error extracting point");
2503 PG_FREE_IF_COPY(geom, 0);
2506 geom = PG_GETARG_GSERIALIZED_P(1);
2510 PG_FREE_IF_COPY(geom, 1);
2511 lwpgerror(
"Argument must be POINT geometries");
2514 if (lwpoint->
srid != srid)
2516 PG_FREE_IF_COPY(geom, 1);
2517 lwpgerror(
"Operation on mixed SRID geometries");
2522 PG_FREE_IF_COPY(geom, 1);
2523 lwpgerror(
"Error extracting point");
2527 PG_FREE_IF_COPY(geom, 1);
2530 if ((p1.
x == p2.
x) && (p1.
y == p2.
y))
2541 PG_RETURN_FLOAT8(
result);
2557 LWGEOM *lwgeom1, *lwgeom2;
2560 geom1 = PG_GETARG_GSERIALIZED_P(0);
2562 azimuth = PG_GETARG_FLOAT8(2);
2567 lwpgerror(
"Argument must be POINT geometry");
2574 geom2 = geometry_serialize(lwgeom2);
2575 PG_RETURN_POINTER(geom2);
2590 LWPOINT *lwpoint1, *lwpoint2, *lwpoint3;
2591 LWGEOM *lwgeom1, *lwgeom2, *lwgeom3;
2594 geom1 = PG_GETARG_GSERIALIZED_P(0);
2595 geom2 = PG_GETARG_GSERIALIZED_P(1);
2603 if (!(lwpoint1 && lwpoint2))
2604 lwpgerror(
"Arguments must be POINT geometries");
2610 PG_RETURN_POINTER(geom2);
2614 geom3 = geometry_serialize(lwgeom3);
2616 PG_RETURN_POINTER(geom3);
2631 LWLINE *lwline1, *lwline2;
2632 LWGEOM *lwgeom1, *lwgeom2;
2633 double distance_forward, distance_backward;
2635 geom1 = PG_GETARG_GSERIALIZED_P(0);
2636 distance_forward = PG_GETARG_FLOAT8(1);
2637 distance_backward = PG_GETARG_FLOAT8(2);
2642 lwpgerror(
"Argument must be LINESTRING geometry");
2648 PG_RETURN_POINTER(geom1);
2650 lwline2 =
lwline_extend(lwline1, distance_forward, distance_backward);
2652 geom2 = geometry_serialize(lwgeom2);
2654 PG_RETURN_POINTER(geom2);
2679 int n_args = PG_NARGS();
2682 for (i = 0; i < n_args; i++)
2684 seri_geoms[i] = PG_GETARG_GSERIALIZED_P(i);
2707 if (srids[0] != srids[i])
2719 for (j = 0; j <= i; j++)
2720 PG_FREE_IF_COPY(seri_geoms[j], j);
2723 lwpgerror(
"Empty geometry");
2728 lwpgerror(
"Argument must be POINT geometries");
2733 lwpgerror(
"Operation on mixed SRID geometries");
2738 for (i = 0; i < n_args; i++)
2744 for (j = 0; j < n_args; j++)
2745 PG_FREE_IF_COPY(seri_geoms[j], j);
2746 lwpgerror(
"Error unserializing geometry");
2755 lwpgerror(
"Error extracting point");
2783 PG_RETURN_FLOAT8(
result);
2796 GSERIALIZED *pg_geom1 = PG_GETARG_GSERIALIZED_P(0);
2797 GSERIALIZED *pg_geom2 = PG_GETARG_GSERIALIZED_P(1);
2798 double dist = PG_GETARG_FLOAT8(2);
2807 elog(ERROR,
"optimistic_overlap: first arg isn't a polygon\n");
2813 elog(ERROR,
"optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
2820 g1_bvol.
xmin = g1_bvol.
xmin - dist;
2821 g1_bvol.
ymin = g1_bvol.
ymin - dist;
2822 g1_bvol.
xmax = g1_bvol.
xmax + dist;
2823 g1_bvol.
ymax = g1_bvol.
ymax + dist;
2828 PG_RETURN_BOOL(
false);
2836 DatumGetFloat8(DirectFunctionCall2(
ST_Distance, PointerGetDatum(pg_geom1), PointerGetDatum(pg_geom2)));
2838 PG_RETURN_BOOL(calc_dist < dist);
2845 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
2850 affine.
afac = PG_GETARG_FLOAT8(1);
2851 affine.
bfac = PG_GETARG_FLOAT8(2);
2852 affine.
cfac = PG_GETARG_FLOAT8(3);
2853 affine.
dfac = PG_GETARG_FLOAT8(4);
2854 affine.
efac = PG_GETARG_FLOAT8(5);
2855 affine.
ffac = PG_GETARG_FLOAT8(6);
2856 affine.
gfac = PG_GETARG_FLOAT8(7);
2857 affine.
hfac = PG_GETARG_FLOAT8(8);
2858 affine.
ifac = PG_GETARG_FLOAT8(9);
2859 affine.
xoff = PG_GETARG_FLOAT8(10);
2860 affine.
yoff = PG_GETARG_FLOAT8(11);
2861 affine.
zoff = PG_GETARG_FLOAT8(12);
2863 POSTGIS_DEBUG(2,
"LWGEOM_affine called.");
2872 ret = geometry_serialize(lwgeom);
2876 PG_FREE_IF_COPY(geom, 0);
2878 PG_RETURN_POINTER(ret);
2889 if (PG_ARGISNULL(0))
2894 geom = PG_GETARG_GSERIALIZED_P(0);
2896 if (!PG_ARGISNULL(1))
2903 PG_RETURN_TEXT_P(geohash);
2910 if (PG_ARGISNULL(0))
2924 extype = PG_GETARG_INT32(1);
2929 elog(ERROR,
"ST_CollectionExtract: only point, linestring and polygon may be extracted");
2933 gser_in = PG_GETARG_GSERIALIZED_P(0);
2940 if (lwg_in->
type == extype || !extype)
2943 PG_RETURN_POINTER(gser_in);
2949 PG_RETURN_POINTER(geometry_serialize(lwg_out));
2955 gser_out = geometry_serialize(lwg_out);
2958 PG_RETURN_POINTER(gser_out);
2974 PG_FREE_IF_COPY(input, 0);
2978 output = geometry_serialize(lwoutput);
2981 PG_FREE_IF_COPY(input, 0);
2982 PG_RETURN_POINTER(output);
2989 GSERIALIZED *g_in = PG_GETARG_GSERIALIZED_P_COPY(0);
2992 LWGEOM *lwgeom_in = NULL;
2993 double tolerance = 0.0;
2998 PG_RETURN_POINTER(g_in);
3000 if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
3001 tolerance = PG_GETARG_FLOAT8(1);
3008 PG_RETURN_POINTER(g_in);
3011 g_out = geometry_serialize(lwgeom_in);
3014 PG_RETURN_POINTER(g_out);
3021 GSERIALIZED *in = PG_GETARG_GSERIALIZED_P_COPY(0);
3026 out = geometry_serialize(lwgeom);
3029 PG_FREE_IF_COPY(in, 0);
3031 PG_RETURN_POINTER(out);
3037 if (n ==
'x' || n ==
'X')
3039 if (n ==
'y' || n ==
'Y')
3041 if (n ==
'z' || n ==
'Z')
3043 if (n ==
'm' || n ==
'M')
3045 lwpgerror(
"Invalid ordinate name '%c'. Expected x,y,z or m", n);
3059 ospec = PG_GETARG_CSTRING(1);
3060 if (strlen(ospec) != 2)
3063 "Invalid ordinate specification. "
3064 "Need two letters from the set (x,y,z,m). "
3072 in = PG_GETARG_GSERIALIZED_P_COPY(0);
3077 lwpgerror(
"Geometry does not have an M ordinate");
3082 lwpgerror(
"Geometry does not have a Z ordinate");
3088 PG_RETURN_POINTER(in);
3092 out = geometry_serialize(lwgeom);
3094 PG_FREE_IF_COPY(in, 0);
3095 PG_RETURN_POINTER(out);
3106 bool fits = PG_GETARG_BOOL(1);
3107 LWGEOM *lwgeom_out = NULL;
3119 GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
3124 srid = lwgeom_in->
srid;
3155 geom_out = geometry_serialize(lwgeom_out);
3158 PG_RETURN_POINTER(geom_out);
3166 GSERIALIZED *geom_scale = PG_GETARG_GSERIALIZED_P(1);
3168 LWGEOM *lwg, *lwg_scale, *lwg_origin;
3169 LWPOINT *lwpt_scale, *lwpt_origin;
3172 bool translate =
false;
3182 PG_FREE_IF_COPY(geom_scale, 1);
3183 lwpgerror(
"Scale factor geometry parameter must be a point");
3188 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
3196 PG_FREE_IF_COPY(geom_scale, 1);
3197 PG_RETURN_POINTER(geom);
3210 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
3212 geom_origin = PG_GETARG_GSERIALIZED_P(2);
3222 PG_FREE_IF_COPY(geom_origin, 2);
3229 memset(&aff, 0,
sizeof(
AFFINE));
3233 aff.
xoff = -1 * origin.
x;
3234 aff.
yoff = -1 * origin.
y;
3235 aff.
zoff = -1 * origin.
z;
3251 ret = geometry_serialize(lwg);
3253 PG_FREE_IF_COPY(geom, 0);
3254 PG_FREE_IF_COPY(geom_scale, 1);
3255 PG_RETURN_POINTER(ret);
3262 if (PG_ARGISNULL(0))
3277 PG_RETURN_POINTER(ret);
3292 if (PG_ARGISNULL(0))
3294 if (PG_ARGISNULL(1))
3296 lwpgerror(
"Must specify precision");
3301 prec_x = PG_GETARG_INT32(1);
3303 prec_y = PG_ARGISNULL(2) ? prec_x : PG_GETARG_INT32(2);
3304 prec_z = PG_ARGISNULL(3) ? prec_x : PG_GETARG_INT32(3);
3305 prec_m = PG_ARGISNULL(4) ? prec_x : PG_GETARG_INT32(4);
3307 input = PG_GETARG_GSERIALIZED_P_COPY(0);
3313 result = geometry_serialize(g);
3315 PG_FREE_IF_COPY(input, 0);
3316 PG_RETURN_POINTER(
result);
3333 if (PG_NARGS() > 0 && !PG_ARGISNULL(0))
3335 geom_in = PG_GETARG_GSERIALIZED_P(0);
3342 if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
3343 min = PG_GETARG_FLOAT8(1);
3348 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
3349 max = PG_GETARG_FLOAT8(2);
3354 if (PG_NARGS() > 3 && !PG_ARGISNULL(3) && PG_GETARG_BOOL(3))
3363 elog(ERROR,
"Min-value cannot be larger than Max value\n");
3373 elog(NOTICE,
"No M-value, No vertex removed\n");
3374 PG_RETURN_POINTER(geom_in);
3379 geom_out = geometry_serialize(lwgeom_out);
3381 PG_RETURN_POINTER(geom_out);
3389 LWGEOM *lwgeom, *lwresult;
3391 geom1 = PG_GETARG_GSERIALIZED_P(0);
3403 result = geometry_serialize(lwresult);
3408 PG_RETURN_POINTER(
result);
char result[OUT_DOUBLE_BUFFER_SIZE]
int gbox_merge(const GBOX *new_box, GBOX *merge_box)
Update the merged GBOX to be large enough to include itself and the new box.
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
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.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
int gserialized_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
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)...
int gserialized_ndims(const GSERIALIZED *g)
Return the number of dimensions (2, 3, 4) in a geometry.
uint32_t gserialized_get_version(const GSERIALIZED *g)
Return the serialization version.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
int gserialized_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
uint64_t gserialized_get_sortable_hash(const GSERIALIZED *g)
Return a sortable key based on gserialized.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
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".
int gserialized_datum_get_internals_p(Datum gsdatum, GBOX *gbox, lwflags_t *flags, uint8_t *type, int32_t *srid)
Peak into a GSERIALIZED datum to find its bounding box and some other metadata.
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
LWPOINT * lwpoint_make4d(int32_t srid, double x, double y, double z, double m)
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
double lwgeom_maxdistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing max distance calculation.
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
void lwmpoint_free(LWMPOINT *mpt)
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
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...
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.
void lwpoint_free(LWPOINT *pt)
void lwgeom_longitude_shift(LWGEOM *lwgeom)
void lwgeom_free(LWGEOM *geom)
double lwgeom_maxdistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d max distance calculations and dfullywithin calculations.
LWGEOM * lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm)
LWPOINT * lwpoint_make3dm(int32_t srid, double x, double y, double m)
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
double lwgeom_perimeter_2d(const LWGEOM *geom)
lwvarlena_t * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
LWGEOM * lwgeom_furthest_line_3d(LWGEOM *lw1, LWGEOM *lw2)
LWGEOM * lwgeom_closest_point_3d(const LWGEOM *lw1, const LWGEOM *lw2)
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom, double mval)
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
LWGEOM * lwgeom_force_4d(const LWGEOM *geom, double zval, double mval)
double lwgeom_length(const LWGEOM *geom)
const char * lwgeom_version(void)
Return lwgeom version string (not to be freed)
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom, double zval)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
#define FLAGS_GET_Z(flags)
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
double lwgeom_area(const LWGEOM *geom)
LWPOLY * lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2)
LWPOINT * lwpoint_project(const LWPOINT *lwpoint1, double distance, double azimuth)
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
LWCOLLECTION * lwcollection_extract(const LWCOLLECTION *col, uint32_t type)
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
LWPOINT * lwpoint_make3dz(int32_t srid, double x, double y, double z)
double lwgeom_mindistance3d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling 3d min distance calculations and dwithin calculations.
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
LWGEOM * lwgeom_boundary(LWGEOM *lwgeom)
#define POLYHEDRALSURFACETYPE
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
LWPOINT * lwpoint_project_lwpoint(const LWPOINT *lwpoint1, const LWPOINT *lwpoint2, double distance)
double lwgeom_length_2d(const LWGEOM *geom)
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
int lwtype_is_unitary(uint32_t lwtype)
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
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...
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
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,...
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
LWGEOM * lwgeom_furthest_line(const LWGEOM *lw1, const LWGEOM *lw2)
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
void lwpoly_free(LWPOLY *poly)
#define LW_TRUE
Return types for functions with status returns.
double lwgeom_maxdistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d max distance calculation.
#define SRID_UNKNOWN
Unknown SRID value.
double lwgeom_perimeter(const LWGEOM *geom)
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
LWLINE * lwline_extend(const LWLINE *line, double distance_forward, double distance_backward)
Extend the ends of a line.
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
void lwline_free(LWLINE *line)
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
LWGEOM * lwgeom_closest_line_3d(const LWGEOM *lw1, const LWGEOM *lw2)
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, uint32_t where)
Add a LWPOINT to an LWLINE.
void lwgeom_drop_srid(LWGEOM *lwgeom)
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
double lwgeom_mindistance3d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing 3d min distance calculation.
lwvarlena_t * lwgeom_to_wkt_varlena(const LWGEOM *geom, uint8_t variant, int precision)
enum LWORD_T LWORD
Ordinate names.
This library is the generic geometry handling section of PostGIS.
double lwline_length_2d(const LWLINE *line)
#define OUT_DEFAULT_DECIMAL_DIGITS
int lwline_is_empty(const LWLINE *line)
int ptarray_scroll_in_place(POINTARRAY *pa, const POINT4D *newbase)
char lwpoint_same2d(const LWPOINT *p1, const LWPOINT *p2)
Datum LWGEOM_FilterByM(PG_FUNCTION_ARGS)
Datum LWGEOM_isempty(PG_FUNCTION_ARGS)
Datum LWGEOM_perimeter2d_poly(PG_FUNCTION_ARGS)
Datum LWGEOM_force_3dm(PG_FUNCTION_ARGS)
Datum LWGEOM_force_2d(PG_FUNCTION_ARGS)
Datum ST_PointZM(PG_FUNCTION_ARGS)
Datum LWGEOM_makepoly(PG_FUNCTION_ARGS)
Datum LWGEOM_makepoint(PG_FUNCTION_ARGS)
Datum ST_3DIntersects(PG_FUNCTION_ARGS)
Datum LWGEOM_force_3dz(PG_FUNCTION_ARGS)
Datum LWGEOM_force_multi(PG_FUNCTION_ARGS)
Datum ST_Scroll(PG_FUNCTION_ARGS)
Datum LWGEOM_segmentize2d(PG_FUNCTION_ARGS)
Datum ST_PointM(PG_FUNCTION_ARGS)
Datum LWGEOM_dfullywithin3d(PG_FUNCTION_ARGS)
Datum ST_Area(PG_FUNCTION_ARGS)
Datum ST_CollectionHomogenize(PG_FUNCTION_ARGS)
Datum LWGEOM_shortestline3d(PG_FUNCTION_ARGS)
Datum postgis_lib_revision(PG_FUNCTION_ARGS)
Datum LWGEOM_maxdistance2d_linestring(PG_FUNCTION_ARGS)
Datum LWGEOM_removepoint(PG_FUNCTION_ARGS)
Datum LWGEOM_noop(PG_FUNCTION_ARGS)
Datum postgis_scripts_released(PG_FUNCTION_ARGS)
Datum geometry_project_direction(PG_FUNCTION_ARGS)
Datum LWGEOM_affine(PG_FUNCTION_ARGS)
Datum ST_RemoveRepeatedPoints(PG_FUNCTION_ARGS)
Datum ST_BoundingDiagonal(PG_FUNCTION_ARGS)
Datum LWGEOM_longitude_shift(PG_FUNCTION_ARGS)
Datum ST_PointZ(PG_FUNCTION_ARGS)
Datum ST_QuantizeCoordinates(PG_FUNCTION_ARGS)
Datum postgis_version(PG_FUNCTION_ARGS)
Datum postgis_liblwgeom_version(PG_FUNCTION_ARGS)
Datum LWGEOM_force_4d(PG_FUNCTION_ARGS)
Datum LWGEOM_nrings(PG_FUNCTION_ARGS)
Datum ST_Points(PG_FUNCTION_ARGS)
Datum LWGEOM_zmflag(PG_FUNCTION_ARGS)
Datum ST_GeoHash(PG_FUNCTION_ARGS)
Datum ST_TileEnvelope(PG_FUNCTION_ARGS)
Datum ST_IsCollection(PG_FUNCTION_ARGS)
Datum ST_3DDistance(PG_FUNCTION_ARGS)
Datum LWGEOM_mem_size(PG_FUNCTION_ARGS)
Datum postgis_svn_version(PG_FUNCTION_ARGS)
Datum LWGEOM_makeline(PG_FUNCTION_ARGS)
Datum LWGEOM_ndims(PG_FUNCTION_ARGS)
Datum ST_Scale(PG_FUNCTION_ARGS)
Datum LWGEOM_force_curve(PG_FUNCTION_ARGS)
Datum LWGEOM_setpoint_linestring(PG_FUNCTION_ARGS)
Datum LWGEOM_dwithin3d(PG_FUNCTION_ARGS)
Datum _ST_SortableHash(PG_FUNCTION_ARGS)
Datum LWGEOM_shortestline2d(PG_FUNCTION_ARGS)
Datum LWGEOM_perimeter_poly(PG_FUNCTION_ARGS)
Datum LWGEOM_envelope(PG_FUNCTION_ARGS)
Datum LWGEOM_force_collection(PG_FUNCTION_ARGS)
Datum ST_MakeEnvelope(PG_FUNCTION_ARGS)
Datum LWGEOM_force_clockwise_poly(PG_FUNCTION_ARGS)
Datum LWGEOM_hasm(PG_FUNCTION_ARGS)
Datum LWGEOM_to_BOX(PG_FUNCTION_ARGS)
Datum LWGEOM_azimuth(PG_FUNCTION_ARGS)
Datum ST_Normalize(PG_FUNCTION_ARGS)
Datum optimistic_overlap(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(LWGEOM_mem_size)
find the size of geometry
Datum ST_CollectionExtract(PG_FUNCTION_ARGS)
Datum LWGEOM_asEWKT(PG_FUNCTION_ARGS)
Datum LWGEOM_angle(PG_FUNCTION_ARGS)
Datum LWGEOM_inside_circle_point(PG_FUNCTION_ARGS)
Datum postgis_lib_build_date(PG_FUNCTION_ARGS)
Datum ST_Point(PG_FUNCTION_ARGS)
Datum geometry_project_geometry(PG_FUNCTION_ARGS)
Datum boundary(PG_FUNCTION_ARGS)
Datum LWGEOM_line_from_mpoint(PG_FUNCTION_ARGS)
Datum LWGEOM_collect(PG_FUNCTION_ARGS)
Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
Datum LWGEOM_hasBBOX(PG_FUNCTION_ARGS)
Datum LWGEOM_same(PG_FUNCTION_ARGS)
Datum ST_SwapOrdinates(PG_FUNCTION_ARGS)
Datum LWGEOM_reverse(PG_FUNCTION_ARGS)
Datum LWGEOM_hasz(PG_FUNCTION_ARGS)
Datum postgis_lib_version(PG_FUNCTION_ARGS)
Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
Datum LWGEOM_longestline2d(PG_FUNCTION_ARGS)
Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
Datum LWGEOM_force_sfs(PG_FUNCTION_ARGS)
Datum LWGEOM_length2d_linestring(PG_FUNCTION_ARGS)
Datum ST_FlipCoordinates(PG_FUNCTION_ARGS)
Datum LWGEOM_closestpoint(PG_FUNCTION_ARGS)
Datum LWGEOM_expand(PG_FUNCTION_ARGS)
Datum ST_Distance(PG_FUNCTION_ARGS)
Datum LWGEOM_longestline3d(PG_FUNCTION_ARGS)
Datum LWGEOM_length_linestring(PG_FUNCTION_ARGS)
Datum geometry_line_extend(PG_FUNCTION_ARGS)
static LWORD ordname2ordval(char n)
Datum LWGEOM_npoints(PG_FUNCTION_ARGS)
Datum ST_WrapX(PG_FUNCTION_ARGS)
Datum LWGEOM_makepoint3dm(PG_FUNCTION_ARGS)
Datum LWGEOM_dwithin(PG_FUNCTION_ARGS)
Datum LWGEOM_mindistance3d(PG_FUNCTION_ARGS)
Datum postgis_libxml_version(PG_FUNCTION_ARGS)
Datum LWGEOM_maxdistance3d(PG_FUNCTION_ARGS)
Datum LWGEOM_closestpoint3d(PG_FUNCTION_ARGS)
Datum LWGEOM_summary(PG_FUNCTION_ARGS)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
static double distance(double x1, double y1, double x2, double y2)
#define POSTGIS_LIB_VERSION
#define POSTGIS_LIBXML2_VERSION