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))
1484 srid = geoms[ngeoms - 1]->
srid;
1490 POSTGIS_DEBUGF(3,
"%s: element %d deserialized", __func__, ngeoms);
1492 array_free_iterator(iterator);
1498 elog(NOTICE,
"No points or linestrings in input array");
1502 POSTGIS_DEBUGF(3,
"LWGEOM_makeline_garray: elements: %d", ngeoms);
1506 result = geometry_serialize(outlwg);
1508 PG_RETURN_POINTER(
result);
1523 POSTGIS_DEBUG(2,
"LWGEOM_makeline called.");
1526 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1527 pglwg2 = PG_GETARG_GSERIALIZED_P(1);
1532 elog(ERROR,
"Input geometries must be points or lines");
1545 PG_FREE_IF_COPY(pglwg1, 0);
1546 PG_FREE_IF_COPY(pglwg2, 1);
1550 PG_RETURN_POINTER(
result);
1561 ArrayType *array = NULL;
1563 const LWLINE *shell = NULL;
1564 const LWLINE **holes = NULL;
1570 POSTGIS_DEBUG(2,
"LWGEOM_makepoly called.");
1573 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1576 lwpgerror(
"Shell is not a line");
1583 array = PG_GETARG_ARRAYTYPE_P(1);
1584 nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1586 for (i = 0; i < nholes; i++)
1588 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1589 #pragma GCC diagnostic push
1590 #pragma GCC diagnostic ignored "-Wsign-compare"
1593 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1594 #pragma GCC diagnostic pop
1597 offset += INTALIGN(VARSIZE(g));
1600 lwpgerror(
"Hole %d is not a line", i);
1612 PG_FREE_IF_COPY(pglwg1, 0);
1614 for (i = 0; i < nholes; i++)
1619 PG_RETURN_POINTER(
result);
1637 POSTGIS_DEBUG(2,
"LWGEOM_expand called.");
1643 PG_RETURN_POINTER(geom);
1650 PG_RETURN_POINTER(geom);
1653 if (PG_NARGS() == 2)
1656 double d = PG_GETARG_FLOAT8(1);
1661 double dx = PG_GETARG_FLOAT8(1);
1662 double dy = PG_GETARG_FLOAT8(2);
1663 double dz = PG_GETARG_FLOAT8(3);
1664 double dm = PG_GETARG_FLOAT8(4);
1686 PG_FREE_IF_COPY(geom, 0);
1688 PG_RETURN_POINTER(
result);
1695 GSERIALIZED *pg_lwgeom = PG_GETARG_GSERIALIZED_P(0);
1709 PG_FREE_IF_COPY(pg_lwgeom, 0);
1716 out->low.x = gbox.
xmin;
1717 out->low.y = gbox.
ymin;
1718 out->high.x = gbox.
xmax;
1719 out->high.y = gbox.
ymax;
1720 PG_RETURN_POINTER(out);
1733 int32_t srid = lwgeom->
srid;
1742 PG_RETURN_POINTER(geom);
1748 PG_RETURN_POINTER(geom);
1818 PG_FREE_IF_COPY(geom, 0);
1820 PG_RETURN_POINTER(
result);
1841 LWGEOM *inlwgeom, *outlwgeom;
1844 POSTGIS_DEBUG(2,
"LWGEOM_segmentize2d called");
1846 ingeom = PG_GETARG_GSERIALIZED_P(0);
1847 dist = PG_GETARG_FLOAT8(1);
1854 PG_RETURN_POINTER(ingeom);
1861 elog(ERROR,
"ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1872 PG_RETURN_POINTER(ingeom);
1879 PG_FREE_IF_COPY(ingeom, 0);
1887 outgeom = geometry_serialize(outlwgeom);
1892 PG_FREE_IF_COPY(ingeom, 0);
1894 PG_RETURN_POINTER(outgeom);
1904 POSTGIS_DEBUG(2,
"LWGEOM_reverse called");
1906 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
1911 geom = geometry_serialize(lwgeom);
1913 PG_RETURN_POINTER(geom);
1923 POSTGIS_DEBUG(2,
"LWGEOM_force_clockwise_poly called");
1925 ingeom = PG_GETARG_GSERIALIZED_P_COPY(0);
1930 outgeom = geometry_serialize(lwgeom);
1933 PG_FREE_IF_COPY(ingeom, 0);
1934 PG_RETURN_POINTER(outgeom);
1948 POSTGIS_DEBUG(2,
"ST_ForcePolygonCCW called");
1950 ingeom = PG_GETARG_GSERIALIZED_P_COPY(0);
1955 outgeom = geometry_serialize(lwgeom);
1958 PG_FREE_IF_COPY(ingeom, 0);
1959 PG_RETURN_POINTER(outgeom);
1969 PG_RETURN_POINTER(out);
1977 LWGEOM *lwgeom_in, *lwgeom_out;
1979 POSTGIS_DEBUG(2,
"ST_Normalize called");
1981 in = PG_GETARG_GSERIALIZED_P_COPY(0);
1984 POSTGIS_DEBUGF(3,
"Deserialized: %s",
lwgeom_summary(lwgeom_in, 0));
1987 POSTGIS_DEBUGF(3,
"Normalized: %s",
lwgeom_summary(lwgeom_out, 0));
1989 out = geometry_serialize(lwgeom_out);
1993 PG_FREE_IF_COPY(in, 0);
1995 PG_RETURN_POINTER(out);
2008 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2015 PG_FREE_IF_COPY(in, 0);
2016 PG_RETURN_INT16(ret);
2022 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2029 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2036 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2038 PG_FREE_IF_COPY(in, 0);
2039 PG_RETURN_BOOL(
res);
2046 GSERIALIZED *in = PG_GETARG_GSERIALIZED_HEADER(0);
2048 PG_FREE_IF_COPY(in, 0);
2049 PG_RETURN_INT16(ret);
2067 double x1, y1, x2, y2;
2070 POSTGIS_DEBUG(2,
"ST_MakeEnvelope called");
2072 x1 = PG_GETARG_FLOAT8(0);
2073 y1 = PG_GETARG_FLOAT8(1);
2074 x2 = PG_GETARG_FLOAT8(2);
2075 y2 = PG_GETARG_FLOAT8(3);
2078 srid = PG_GETARG_INT32(4);
2086 PG_RETURN_POINTER(
result);
2096 uint32_t worldTileSize;
2097 double tileGeoSizeX, tileGeoSizeY;
2098 double boundsWidth, boundsHeight;
2099 double x1, y1, x2, y2;
2110 POSTGIS_DEBUG(2,
"ST_TileEnvelope called");
2112 zoom = PG_GETARG_INT32(0);
2113 x = PG_GETARG_INT32(1);
2114 y = PG_GETARG_INT32(2);
2116 bounds = PG_GETARG_GSERIALIZED_P(3);
2125 elog(ERROR,
"%s: Unable to compute bbox", __func__);
2130 margin = PG_NARGS() < 4 ? 0 : PG_GETARG_FLOAT8(4);
2133 elog(ERROR,
"%s: Margin must not be less than -50%%, margin=%f", __func__, margin);
2135 boundsWidth = bbox.
xmax - bbox.
xmin;
2136 boundsHeight = bbox.
ymax - bbox.
ymin;
2137 if (boundsWidth <= 0 || boundsHeight <= 0)
2138 elog(ERROR,
"%s: Geometric bounds are too small", __func__);
2140 if (zoom < 0 || zoom >= 32)
2141 elog(ERROR,
"%s: Invalid tile zoom value, %d", __func__, zoom);
2143 zoomu = (uint32_t)zoom;
2144 worldTileSize = 0x01u << (zoomu > 31 ? 31 : zoomu);
2146 if (
x < 0 || (uint32_t)
x >= worldTileSize)
2147 elog(ERROR,
"%s: Invalid tile x value, %d", __func__,
x);
2148 if (
y < 0 || (uint32_t)
y >= worldTileSize)
2149 elog(ERROR,
"%s: Invalid tile y value, %d", __func__,
y);
2151 tileGeoSizeX = boundsWidth / worldTileSize;
2152 tileGeoSizeY = boundsHeight / worldTileSize;
2159 if ((1 + margin * 2) > worldTileSize)
2166 x1 = bbox.
xmin + tileGeoSizeX * (
x - margin);
2167 x2 = bbox.
xmin + tileGeoSizeX * (
x + 1 + margin);
2170 y1 = bbox.
ymax - tileGeoSizeY * (
y + 1 + margin);
2171 y2 = bbox.
ymax - tileGeoSizeY * (
y - margin);
2174 if (y1 < bbox.
ymin) y1 = bbox.
ymin;
2175 if (y2 > bbox.
ymax) y2 = bbox.
ymax;
2176 if (x1 < bbox.
xmin) x1 = bbox.
xmin;
2177 if (x2 > bbox.
xmax) x2 = bbox.
xmax;
2183 srid, x1, y1, x2, y2))));
2190 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_HEADER(0);
2202 POSTGIS_DEBUG(2,
"LWGEOM_makepoint called");
2204 x = PG_GETARG_FLOAT8(0);
2205 y = PG_GETARG_FLOAT8(1);
2207 if (PG_NARGS() == 2)
2209 else if (PG_NARGS() == 3)
2211 z = PG_GETARG_FLOAT8(2);
2214 else if (PG_NARGS() == 4)
2216 z = PG_GETARG_FLOAT8(2);
2217 m = PG_GETARG_FLOAT8(3);
2222 elog(ERROR,
"LWGEOM_makepoint: unsupported number of args: %d", PG_NARGS());
2228 PG_RETURN_POINTER(
result);
2234 double x = PG_GETARG_FLOAT8(0);
2235 double y = PG_GETARG_FLOAT8(1);
2236 int srid = PG_GETARG_INT32(2);
2239 PG_RETURN_POINTER(
result);
2245 double x = PG_GETARG_FLOAT8(0);
2246 double y = PG_GETARG_FLOAT8(1);
2247 double z = PG_GETARG_FLOAT8(2);
2248 int srid = PG_GETARG_INT32(3);
2251 PG_RETURN_POINTER(
result);
2257 double x = PG_GETARG_FLOAT8(0);
2258 double y = PG_GETARG_FLOAT8(1);
2259 double m = PG_GETARG_FLOAT8(2);
2260 int srid = PG_GETARG_INT32(3);
2263 PG_RETURN_POINTER(
result);
2269 double x = PG_GETARG_FLOAT8(0);
2270 double y = PG_GETARG_FLOAT8(1);
2271 double z = PG_GETARG_FLOAT8(2);
2272 double m = PG_GETARG_FLOAT8(3);
2273 int srid = PG_GETARG_INT32(4);
2276 PG_RETURN_POINTER(
result);
2287 POSTGIS_DEBUG(2,
"LWGEOM_makepoint3dm called.");
2289 x = PG_GETARG_FLOAT8(0);
2290 y = PG_GETARG_FLOAT8(1);
2291 m = PG_GETARG_FLOAT8(2);
2296 PG_RETURN_POINTER(
result);
2305 uint32_t uwhere = 0;
2307 POSTGIS_DEBUGF(2,
"%s called.", __func__);
2309 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2310 pglwg2 = PG_GETARG_GSERIALIZED_P(1);
2314 elog(ERROR,
"First argument must be a LINESTRING");
2320 elog(ERROR,
"Second argument must be a POINT");
2326 PG_RETURN_POINTER(pglwg1);
2331 if (PG_NARGS() <= 2)
2337 int32 where = PG_GETARG_INT32(2);
2344 elog(ERROR,
"%s: Invalid offset", __func__);
2359 elog(ERROR,
"Point insert failed");
2366 PG_FREE_IF_COPY(pglwg1, 0);
2367 PG_FREE_IF_COPY(pglwg2, 1);
2370 PG_RETURN_POINTER(
result);
2380 POSTGIS_DEBUG(2,
"LWGEOM_removepoint called.");
2382 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2383 which = PG_GETARG_INT32(1);
2387 elog(ERROR,
"First argument must be a LINESTRING");
2393 if (which < 0 || (uint32_t)which > line->
points->
npoints - 1)
2395 elog(ERROR,
"Point index out of range (%u..%u)", 0, line->
points->
npoints - 1);
2401 elog(ERROR,
"Can't remove points from a single segment line");
2412 PG_FREE_IF_COPY(pglwg1, 0);
2413 PG_RETURN_POINTER(
result);
2426 POSTGIS_DEBUG(2,
"LWGEOM_setpoint_linestring called.");
2429 pglwg1 = PG_GETARG_GSERIALIZED_P_COPY(0);
2431 which = PG_GETARG_INT32(1);
2432 pglwg2 = PG_GETARG_GSERIALIZED_P(2);
2439 elog(ERROR,
"Third argument must be a POINT");
2444 PG_FREE_IF_COPY(pglwg2, 2);
2451 elog(ERROR,
"First argument must be a LINESTRING");
2456 elog(ERROR,
"Line has no points");
2467 elog(ERROR,
"abs(Point index) out of range (-)(%u..%u)", 0, line->
points->
npoints - 1);
2481 PG_RETURN_POINTER(
result);
2514 geom = PG_GETARG_GSERIALIZED_P(0);
2518 PG_FREE_IF_COPY(geom, 0);
2519 lwpgerror(
"Argument must be POINT geometries");
2522 srid = lwpoint->
srid;
2525 PG_FREE_IF_COPY(geom, 0);
2526 lwpgerror(
"Error extracting point");
2530 PG_FREE_IF_COPY(geom, 0);
2533 geom = PG_GETARG_GSERIALIZED_P(1);
2537 PG_FREE_IF_COPY(geom, 1);
2538 lwpgerror(
"Argument must be POINT geometries");
2541 if (lwpoint->
srid != srid)
2543 PG_FREE_IF_COPY(geom, 1);
2544 lwpgerror(
"Operation on mixed SRID geometries");
2549 PG_FREE_IF_COPY(geom, 1);
2550 lwpgerror(
"Error extracting point");
2554 PG_FREE_IF_COPY(geom, 1);
2557 if ((p1.
x == p2.
x) && (p1.
y == p2.
y))
2568 PG_RETURN_FLOAT8(
result);
2584 LWGEOM *lwgeom1, *lwgeom2;
2587 geom1 = PG_GETARG_GSERIALIZED_P(0);
2589 azimuth = PG_GETARG_FLOAT8(2);
2594 lwpgerror(
"Argument must be POINT geometry");
2601 geom2 = geometry_serialize(lwgeom2);
2602 PG_RETURN_POINTER(geom2);
2617 LWPOINT *lwpoint1, *lwpoint2, *lwpoint3;
2618 LWGEOM *lwgeom1, *lwgeom2, *lwgeom3;
2621 geom1 = PG_GETARG_GSERIALIZED_P(0);
2622 geom2 = PG_GETARG_GSERIALIZED_P(1);
2630 if (!(lwpoint1 && lwpoint2))
2631 lwpgerror(
"Arguments must be POINT geometries");
2637 PG_RETURN_POINTER(geom2);
2641 geom3 = geometry_serialize(lwgeom3);
2643 PG_RETURN_POINTER(geom3);
2658 LWLINE *lwline1, *lwline2;
2659 LWGEOM *lwgeom1, *lwgeom2;
2660 double distance_forward, distance_backward;
2662 geom1 = PG_GETARG_GSERIALIZED_P(0);
2663 distance_forward = PG_GETARG_FLOAT8(1);
2664 distance_backward = PG_GETARG_FLOAT8(2);
2669 lwpgerror(
"Argument must be LINESTRING geometry");
2675 PG_RETURN_POINTER(geom1);
2677 lwline2 =
lwline_extend(lwline1, distance_forward, distance_backward);
2679 geom2 = geometry_serialize(lwgeom2);
2681 PG_RETURN_POINTER(geom2);
2706 int n_args = PG_NARGS();
2709 for (i = 0; i < n_args; i++)
2711 seri_geoms[i] = PG_GETARG_GSERIALIZED_P(i);
2734 if (srids[0] != srids[i])
2746 for (j = 0; j <= i; j++)
2747 PG_FREE_IF_COPY(seri_geoms[j], j);
2750 lwpgerror(
"Empty geometry");
2755 lwpgerror(
"Argument must be POINT geometries");
2760 lwpgerror(
"Operation on mixed SRID geometries");
2765 for (i = 0; i < n_args; i++)
2771 for (j = 0; j < n_args; j++)
2772 PG_FREE_IF_COPY(seri_geoms[j], j);
2773 lwpgerror(
"Error unserializing geometry");
2782 lwpgerror(
"Error extracting point");
2810 PG_RETURN_FLOAT8(
result);
2823 GSERIALIZED *pg_geom1 = PG_GETARG_GSERIALIZED_P(0);
2824 GSERIALIZED *pg_geom2 = PG_GETARG_GSERIALIZED_P(1);
2825 double dist = PG_GETARG_FLOAT8(2);
2834 elog(ERROR,
"optimistic_overlap: first arg isn't a polygon\n");
2840 elog(ERROR,
"optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
2847 g1_bvol.
xmin = g1_bvol.
xmin - dist;
2848 g1_bvol.
ymin = g1_bvol.
ymin - dist;
2849 g1_bvol.
xmax = g1_bvol.
xmax + dist;
2850 g1_bvol.
ymax = g1_bvol.
ymax + dist;
2855 PG_RETURN_BOOL(
false);
2863 DatumGetFloat8(DirectFunctionCall2(
ST_Distance, PointerGetDatum(pg_geom1), PointerGetDatum(pg_geom2)));
2865 PG_RETURN_BOOL(calc_dist < dist);
2872 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
2877 affine.
afac = PG_GETARG_FLOAT8(1);
2878 affine.
bfac = PG_GETARG_FLOAT8(2);
2879 affine.
cfac = PG_GETARG_FLOAT8(3);
2880 affine.
dfac = PG_GETARG_FLOAT8(4);
2881 affine.
efac = PG_GETARG_FLOAT8(5);
2882 affine.
ffac = PG_GETARG_FLOAT8(6);
2883 affine.
gfac = PG_GETARG_FLOAT8(7);
2884 affine.
hfac = PG_GETARG_FLOAT8(8);
2885 affine.
ifac = PG_GETARG_FLOAT8(9);
2886 affine.
xoff = PG_GETARG_FLOAT8(10);
2887 affine.
yoff = PG_GETARG_FLOAT8(11);
2888 affine.
zoff = PG_GETARG_FLOAT8(12);
2890 POSTGIS_DEBUG(2,
"LWGEOM_affine called.");
2899 ret = geometry_serialize(lwgeom);
2903 PG_FREE_IF_COPY(geom, 0);
2905 PG_RETURN_POINTER(ret);
2916 if (PG_ARGISNULL(0))
2921 geom = PG_GETARG_GSERIALIZED_P(0);
2923 if (!PG_ARGISNULL(1))
2930 PG_RETURN_TEXT_P(geohash);
2937 if (PG_ARGISNULL(0))
2951 extype = PG_GETARG_INT32(1);
2956 elog(ERROR,
"ST_CollectionExtract: only point, linestring and polygon may be extracted");
2960 gser_in = PG_GETARG_GSERIALIZED_P(0);
2967 if (lwg_in->
type == extype || !extype)
2970 PG_RETURN_POINTER(gser_in);
2976 PG_RETURN_POINTER(geometry_serialize(lwg_out));
2982 gser_out = geometry_serialize(lwg_out);
2985 PG_RETURN_POINTER(gser_out);
3001 PG_FREE_IF_COPY(input, 0);
3005 output = geometry_serialize(lwoutput);
3008 PG_FREE_IF_COPY(input, 0);
3009 PG_RETURN_POINTER(output);
3016 GSERIALIZED *g_in = PG_GETARG_GSERIALIZED_P_COPY(0);
3019 LWGEOM *lwgeom_in = NULL;
3020 double tolerance = 0.0;
3025 PG_RETURN_POINTER(g_in);
3027 if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
3028 tolerance = PG_GETARG_FLOAT8(1);
3035 PG_RETURN_POINTER(g_in);
3038 g_out = geometry_serialize(lwgeom_in);
3041 PG_RETURN_POINTER(g_out);
3048 GSERIALIZED *in = PG_GETARG_GSERIALIZED_P_COPY(0);
3053 out = geometry_serialize(lwgeom);
3056 PG_FREE_IF_COPY(in, 0);
3058 PG_RETURN_POINTER(out);
3064 if (n ==
'x' || n ==
'X')
3066 if (n ==
'y' || n ==
'Y')
3068 if (n ==
'z' || n ==
'Z')
3070 if (n ==
'm' || n ==
'M')
3072 lwpgerror(
"Invalid ordinate name '%c'. Expected x,y,z or m", n);
3086 ospec = PG_GETARG_CSTRING(1);
3087 if (strlen(ospec) != 2)
3090 "Invalid ordinate specification. "
3091 "Need two letters from the set (x,y,z,m). "
3099 in = PG_GETARG_GSERIALIZED_P_COPY(0);
3104 lwpgerror(
"Geometry does not have an M ordinate");
3109 lwpgerror(
"Geometry does not have a Z ordinate");
3115 PG_RETURN_POINTER(in);
3119 out = geometry_serialize(lwgeom);
3121 PG_FREE_IF_COPY(in, 0);
3122 PG_RETURN_POINTER(out);
3133 bool fits = PG_GETARG_BOOL(1);
3134 LWGEOM *lwgeom_out = NULL;
3146 GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
3151 srid = lwgeom_in->
srid;
3182 geom_out = geometry_serialize(lwgeom_out);
3185 PG_RETURN_POINTER(geom_out);
3193 GSERIALIZED *geom_scale = PG_GETARG_GSERIALIZED_P(1);
3195 LWGEOM *lwg, *lwg_scale, *lwg_origin;
3196 LWPOINT *lwpt_scale, *lwpt_origin;
3199 bool translate =
false;
3209 PG_FREE_IF_COPY(geom_scale, 1);
3210 lwpgerror(
"Scale factor geometry parameter must be a point");
3215 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
3223 PG_FREE_IF_COPY(geom_scale, 1);
3224 PG_RETURN_POINTER(geom);
3237 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
3239 geom_origin = PG_GETARG_GSERIALIZED_P(2);
3249 PG_FREE_IF_COPY(geom_origin, 2);
3256 memset(&aff, 0,
sizeof(
AFFINE));
3260 aff.
xoff = -1 * origin.
x;
3261 aff.
yoff = -1 * origin.
y;
3262 aff.
zoff = -1 * origin.
z;
3278 ret = geometry_serialize(lwg);
3280 PG_FREE_IF_COPY(geom, 0);
3281 PG_FREE_IF_COPY(geom_scale, 1);
3282 PG_RETURN_POINTER(ret);
3289 if (PG_ARGISNULL(0))
3304 PG_RETURN_POINTER(ret);
3319 if (PG_ARGISNULL(0))
3321 if (PG_ARGISNULL(1))
3323 lwpgerror(
"Must specify precision");
3328 prec_x = PG_GETARG_INT32(1);
3330 prec_y = PG_ARGISNULL(2) ? prec_x : PG_GETARG_INT32(2);
3331 prec_z = PG_ARGISNULL(3) ? prec_x : PG_GETARG_INT32(3);
3332 prec_m = PG_ARGISNULL(4) ? prec_x : PG_GETARG_INT32(4);
3334 input = PG_GETARG_GSERIALIZED_P_COPY(0);
3340 result = geometry_serialize(g);
3342 PG_FREE_IF_COPY(input, 0);
3343 PG_RETURN_POINTER(
result);
3360 if (PG_NARGS() > 0 && !PG_ARGISNULL(0))
3362 geom_in = PG_GETARG_GSERIALIZED_P(0);
3369 if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
3370 min = PG_GETARG_FLOAT8(1);
3375 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
3376 max = PG_GETARG_FLOAT8(2);
3381 if (PG_NARGS() > 3 && !PG_ARGISNULL(3) && PG_GETARG_BOOL(3))
3390 elog(ERROR,
"Min-value cannot be larger than Max value\n");
3400 elog(NOTICE,
"No M-value, No vertex removed\n");
3401 PG_RETURN_POINTER(geom_in);
3406 geom_out = geometry_serialize(lwgeom_out);
3408 PG_RETURN_POINTER(geom_out);
3416 LWGEOM *lwgeom, *lwresult;
3418 geom1 = PG_GETARG_GSERIALIZED_P(0);
3430 result = geometry_serialize(lwresult);
3435 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)
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)
void lwgeom_force_counterclockwise(LWGEOM *lwgeom)
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_ForcePolygonCCW(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