28 #include "../postgis_config.h"
33 #include "utils/array.h"
34 #include "utils/builtins.h"
35 #include "utils/lsyscache.h"
36 #include "utils/numeric.h"
37 #include "access/htup_details.h"
54 #define HANDLE_GEOS_ERROR(label) \
56 if (strstr(lwgeom_geos_errmsg, "InterruptedException")) \
58 (errcode(ERRCODE_QUERY_CANCELED), errmsg("canceling statement due to user request"))); \
60 lwpgerror("%s: %s", (label), lwgeom_geos_errmsg); \
70 Datum
touches(PG_FUNCTION_ARGS);
72 Datum
crosses(PG_FUNCTION_ARGS);
74 Datum
within(PG_FUNCTION_ARGS);
76 Datum
covers(PG_FUNCTION_ARGS);
78 Datum
isvalid(PG_FUNCTION_ARGS);
81 Datum
buffer(PG_FUNCTION_ARGS);
90 Datum
isring(PG_FUNCTION_ARGS);
121 text *
result = cstring_to_text(ver);
122 PG_RETURN_POINTER(
result);
184 geom1 = PG_GETARG_GSERIALIZED_P(0);
185 geom2 = PG_GETARG_GSERIALIZED_P(1);
199 GEOSGeom_destroy(g1);
203 retcode = GEOSHausdorffDistance(g1, g2, &
result);
204 GEOSGeom_destroy(g1);
205 GEOSGeom_destroy(g2);
209 PG_FREE_IF_COPY(geom1, 0);
210 PG_FREE_IF_COPY(geom2, 1);
234 geom1 = PG_GETARG_GSERIALIZED_P(0);
235 geom2 = PG_GETARG_GSERIALIZED_P(1);
236 densifyFrac = PG_GETARG_FLOAT8(2);
250 GEOSGeom_destroy(g1);
254 retcode = GEOSHausdorffDistanceDensify(g1, g2, densifyFrac, &
result);
255 GEOSGeom_destroy(g1);
256 GEOSGeom_destroy(g2);
260 PG_FREE_IF_COPY(geom1, 0);
261 PG_FREE_IF_COPY(geom2, 1);
276 #if POSTGIS_GEOS_VERSION < 30700
278 lwpgerror(
"The GEOS version this PostGIS binary "
279 "was compiled against (%d) doesn't support "
280 "'GEOSFechetDistance' function (3.7.0+ required)",
293 geom1 = PG_GETARG_GSERIALIZED_P(0);
294 geom2 = PG_GETARG_GSERIALIZED_P(1);
295 densifyFrac = PG_GETARG_FLOAT8(2);
309 GEOSGeom_destroy(g1);
313 if (densifyFrac <= 0.0)
315 retcode = GEOSFrechetDistance(g1, g2, &
result);
319 retcode = GEOSFrechetDistanceDensify(g1, g2, densifyFrac, &
result);
322 GEOSGeom_destroy(g1);
323 GEOSGeom_destroy(g2);
327 PG_FREE_IF_COPY(geom1, 0);
328 PG_FREE_IF_COPY(geom2, 1);
346 #if POSTGIS_GEOS_VERSION < 30900
348 lwpgerror(
"The GEOS version this PostGIS binary "
349 "was compiled against (%d) doesn't support "
350 "'GEOSMaximumInscribedCircle' function (3.9.0+ required)",
358 TupleDesc resultTupleDesc;
359 HeapTuple resultTuple;
361 Datum result_values[3];
362 bool result_is_null[3];
370 geom = PG_GETARG_GSERIALIZED_P(0);
379 center = geometry_serialize(lwcenter);
380 nearest = geometry_serialize(lwnearest);
385 GEOSGeometry *ginput, *gcircle, *gcenter, *gnearest;
386 double width, height, size, tolerance;
393 lwpgerror(
"Geometry contains invalid coordinates");
403 size = width > height ? width : height;
404 tolerance = size / 1000.0;
415 gcircle = GEOSMaximumInscribedCircle(ginput, tolerance);
418 lwpgerror(
"Error calculating GEOSMaximumInscribedCircle.");
419 GEOSGeom_destroy(ginput);
425 gcircle = GEOSLargestEmptyCircle(ginput, NULL, tolerance);
428 lwpgerror(
"Error calculating GEOSLargestEmptyCircle.");
429 GEOSGeom_destroy(ginput);
434 gcenter = GEOSGeomGetStartPoint(gcircle);
435 gnearest = GEOSGeomGetEndPoint(gcircle);
436 GEOSDistance(gcenter, gnearest, &radius);
437 GEOSSetSRID(gcenter, srid);
438 GEOSSetSRID(gnearest, srid);
442 GEOSGeom_destroy(gcenter);
443 GEOSGeom_destroy(gnearest);
444 GEOSGeom_destroy(gcircle);
445 GEOSGeom_destroy(ginput);
448 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
449 BlessTupleDesc(resultTupleDesc);
451 result_values[0] = PointerGetDatum(center);
452 result_is_null[0] =
false;
453 result_values[1] = PointerGetDatum(nearest);
454 result_is_null[1] =
false;
455 result_values[2] = Float8GetDatum(radius);
456 result_is_null[2] =
false;
457 resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
459 result = HeapTupleGetDatum(resultTuple);
479 ArrayIterator iterator;
484 int nelems = 0, geoms_size = 0, curgeom = 0,
count = 0;
488 GEOSGeometry *g = NULL;
489 GEOSGeometry *g_union = NULL;
490 GEOSGeometry **geoms = NULL;
497 if ( PG_ARGISNULL(0) )
500 array = PG_GETARG_ARRAYTYPE_P(0);
501 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
504 if ( nelems == 0 ) PG_RETURN_NULL();
507 iterator = array_create_iterator(array, 0, NULL);
508 while (array_iterate(iterator, &
value, &isnull))
511 if (isnull)
continue;
514 array_free_iterator(iterator);
525 if (
count == 1 && nelems == 1 )
527 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
528 #pragma GCC diagnostic push
529 #pragma GCC diagnostic ignored "-Wsign-compare"
532 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
533 #pragma GCC diagnostic pop
535 g_union = GEOSUnaryUnion(g);
538 GEOSSetSRID(g_union, srid);
540 GEOSGeom_destroy(g_union);
541 PG_RETURN_POINTER(gser_out);
548 geoms = palloc(
sizeof(GEOSGeometry*) * geoms_size);
554 iterator = array_create_iterator(array, 0, NULL);
555 while (array_iterate(iterator, &
value, &isnull))
560 if (isnull)
continue;
578 if (gser_type > empty_type)
580 empty_type = gser_type;
581 POSTGIS_DEBUGF(4,
"empty_type = %d gser_type = %d", empty_type, gser_type);
592 "One of the geometries in the set "
593 "could not be converted to GEOS");
597 if ( curgeom == geoms_size )
600 geoms = repalloc( geoms,
sizeof(GEOSGeometry*) * geoms_size );
608 array_free_iterator(iterator);
616 g = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, curgeom);
617 if (!g)
HANDLE_GEOS_ERROR(
"Could not create GEOS COLLECTION from geometry array");
619 g_union = GEOSUnaryUnion(g);
623 GEOSSetSRID(g_union, srid);
625 GEOSGeom_destroy(g_union);
631 if ( empty_type > 0 )
648 PG_RETURN_POINTER(gser_out);
669 geoms = palloc(list_length(state->
geoms) *
sizeof(
LWGEOM*));
672 foreach (l, state->
geoms)
679 geoms[ngeoms++] = geom;
690 empty_type =
type > empty_type ?
type : empty_type;
708 gser_out = geometry_serialize(out);
729 PG_RETURN_POINTER(gser_out);
745 LWGEOM *lwgeom1, *lwresult ;
748 geom1 = PG_GETARG_GSERIALIZED_P(0);
749 if (PG_NARGS() > 1 && ! PG_ARGISNULL(1))
750 prec = PG_GETARG_FLOAT8(1);
755 result = geometry_serialize(lwresult) ;
760 PG_FREE_IF_COPY(geom1, 0);
762 PG_RETURN_POINTER(
result);
771 LWGEOM *lwgeom1, *lwgeom2, *lwresult;
772 double gridSize = -1;
774 geom1 = PG_GETARG_GSERIALIZED_P(0);
775 geom2 = PG_GETARG_GSERIALIZED_P(1);
776 if (PG_NARGS() > 2 && ! PG_ARGISNULL(2))
777 gridSize = PG_GETARG_FLOAT8(2);
783 result = geometry_serialize(lwresult);
789 PG_FREE_IF_COPY(geom1, 0);
790 PG_FREE_IF_COPY(geom2, 1);
792 PG_RETURN_POINTER(
result);
800 PG_RETURN_DATUM(DirectFunctionCall2(
802 PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)
817 LWGEOM *lwgeom1, *lwgeom2, *lwresult ;
820 geom1 = PG_GETARG_GSERIALIZED_P(0);
821 geom2 = PG_GETARG_GSERIALIZED_P(1);
822 if (PG_NARGS() > 2 && ! PG_ARGISNULL(2))
823 prec = PG_GETARG_FLOAT8(2);
829 result = geometry_serialize(lwresult) ;
835 PG_FREE_IF_COPY(geom1, 0);
836 PG_FREE_IF_COPY(geom2, 1);
838 PG_RETURN_POINTER(
result);
845 GEOSGeometry *g1, *g3;
851 geom1 = PG_GETARG_GSERIALIZED_P(0);
855 PG_RETURN_POINTER(geom1);
866 g3 = GEOSConvexHull(g1);
867 GEOSGeom_destroy(g1);
871 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
873 GEOSSetSRID(g3, srid);
876 GEOSGeom_destroy(g3);
881 "convexhull() failed to convert GEOS geometry to LWGEOM");
893 result = geometry_serialize(lwout);
898 elog(ERROR,
"GEOS convexhull() threw an error (result postgis geometry formation)!");
902 PG_FREE_IF_COPY(geom1, 0);
903 PG_RETURN_POINTER(
result);
912 GEOSGeometry *g1, *g3;
916 gs1 = PG_GETARG_GSERIALIZED_P(0);
917 tolerance = PG_GETARG_FLOAT8(1);
923 PG_RETURN_POINTER(gs1);
927 lwpgerror(
"Geometry contains invalid coordinates");
938 g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
939 GEOSGeom_destroy(g1);
943 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
948 GEOSGeom_destroy(g3);
952 elog(ERROR,
"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
956 PG_FREE_IF_COPY(gs1, 0);
957 PG_RETURN_POINTER(
result);
963 GEOSBufferParams *bufferparams;
964 GEOSGeometry *g1, *g3 = NULL;
981 const double DEFAULT_MITRE_LIMIT = 5.0;
982 const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
983 const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
984 double mitreLimit = DEFAULT_MITRE_LIMIT;
985 int endCapStyle = DEFAULT_ENDCAP_STYLE;
986 int joinStyle = DEFAULT_JOIN_STYLE;
989 double size = PG_GETARG_FLOAT8(1);
994 params_text = PG_GETARG_TEXT_P(2);
998 params_text = cstring_to_text(
"");
1007 PG_RETURN_POINTER(geometry_serialize(lwg));
1014 lwpgerror(
"Geometry contains invalid coordinates");
1026 if (VARSIZE_ANY_EXHDR(params_text) > 0)
1029 char *params = text_to_cstring(params_text);
1031 for (param=params; ; param=NULL)
1034 param = strtok(param,
" ");
1036 POSTGIS_DEBUGF(3,
"Param: %s", param);
1039 val = strchr(key,
'=');
1040 if (!val || *(val + 1) ==
'\0')
1042 lwpgerror(
"Missing value for buffer parameter %s", key);
1048 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
1050 if ( !strcmp(key,
"endcap") )
1055 if ( !strcmp(val,
"round") )
1057 endCapStyle = ENDCAP_ROUND;
1059 else if ( !strcmp(val,
"flat") ||
1060 !strcmp(val,
"butt") )
1062 endCapStyle = ENDCAP_FLAT;
1064 else if ( !strcmp(val,
"square") )
1066 endCapStyle = ENDCAP_SQUARE;
1070 lwpgerror(
"Invalid buffer end cap "
1071 "style: %s (accept: "
1072 "'round', 'flat', 'butt' "
1079 else if ( !strcmp(key,
"join") )
1081 if ( !strcmp(val,
"round") )
1083 joinStyle = JOIN_ROUND;
1085 else if ( !strcmp(val,
"mitre") ||
1086 !strcmp(val,
"miter") )
1088 joinStyle = JOIN_MITRE;
1090 else if ( !strcmp(val,
"bevel") )
1092 joinStyle = JOIN_BEVEL;
1096 lwpgerror(
"Invalid buffer end cap "
1097 "style: %s (accept: "
1098 "'round', 'mitre', 'miter' "
1104 else if ( !strcmp(key,
"mitre_limit") ||
1105 !strcmp(key,
"miter_limit") )
1108 mitreLimit = atof(val);
1110 else if ( !strcmp(key,
"quad_segs") )
1113 quadsegs = atoi(val);
1115 else if ( !strcmp(key,
"side") )
1117 if ( !strcmp(val,
"both") )
1121 else if ( !strcmp(val,
"left") )
1125 else if ( !strcmp(val,
"right") )
1132 lwpgerror(
"Invalid side parameter: %s (accept: 'right', 'left', 'both')", val);
1139 "Invalid buffer parameter: %s (accept: 'endcap', 'join', 'mitre_limit', 'miter_limit', 'quad_segs' and 'side')",
1148 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
1149 endCapStyle, joinStyle, mitreLimit);
1151 bufferparams = GEOSBufferParams_create();
1154 if (GEOSBufferParams_setEndCapStyle(bufferparams, endCapStyle) &&
1155 GEOSBufferParams_setJoinStyle(bufferparams, joinStyle) &&
1156 GEOSBufferParams_setMitreLimit(bufferparams, mitreLimit) &&
1157 GEOSBufferParams_setQuadrantSegments(bufferparams, quadsegs) &&
1158 GEOSBufferParams_setSingleSided(bufferparams, singleside))
1160 g3 = GEOSBufferWithParams(g1, bufferparams, size);
1164 lwpgerror(
"Error setting buffer parameters.");
1166 GEOSBufferParams_destroy(bufferparams);
1170 lwpgerror(
"Error setting buffer parameters.");
1173 GEOSGeom_destroy(g1);
1177 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1182 GEOSGeom_destroy(g3);
1186 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1190 PG_FREE_IF_COPY(geom1, 0);
1191 PG_RETURN_POINTER(
result);
1210 gser_input = PG_GETARG_GSERIALIZED_P(0);
1211 npoints = PG_GETARG_INT32(1);
1216 if (PG_NARGS() > 2 && ! PG_ARGISNULL(2))
1218 seed = PG_GETARG_INT32(2);
1221 lwpgerror(
"ST_GeneratePoints: seed must be greater than zero");
1230 PG_FREE_IF_COPY(gser_input, 0);
1237 gser_result = geometry_serialize(lwgeom_result);
1239 PG_RETURN_POINTER(gser_result);
1265 static const double DEFAULT_MITRE_LIMIT = 5.0;
1266 static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1267 double mitreLimit = DEFAULT_MITRE_LIMIT;
1268 int joinStyle = DEFAULT_JOIN_STYLE;
1270 char *paramstr = NULL;
1274 gser_input = PG_GETARG_GSERIALIZED_P(0);
1275 size = PG_GETARG_FLOAT8(1);
1278 if (size == 0) PG_RETURN_POINTER(gser_input);
1282 if ( ! lwgeom_input )
1283 lwpgerror(
"ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1287 PG_RETURN_POINTER(gser_input);
1292 text *wkttext = PG_GETARG_TEXT_P(2);
1293 paramstr = text_to_cstring(wkttext);
1295 POSTGIS_DEBUGF(3,
"paramstr: %s", paramstr);
1297 for ( param=paramstr; ; param=NULL )
1300 param = strtok(param,
" ");
1302 POSTGIS_DEBUGF(3,
"Param: %s", param);
1305 val = strchr(key,
'=');
1306 if (!val || *(val + 1) ==
'\0')
1308 lwpgerror(
"ST_OffsetCurve: Missing value for buffer parameter %s", key);
1314 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
1316 if ( !strcmp(key,
"join") )
1318 if ( !strcmp(val,
"round") )
1320 joinStyle = JOIN_ROUND;
1322 else if ( !(strcmp(val,
"mitre") && strcmp(val,
"miter")) )
1324 joinStyle = JOIN_MITRE;
1326 else if ( ! strcmp(val,
"bevel") )
1328 joinStyle = JOIN_BEVEL;
1333 "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1338 else if ( !strcmp(key,
"mitre_limit") ||
1339 !strcmp(key,
"miter_limit") )
1342 mitreLimit = atof(val);
1344 else if ( !strcmp(key,
"quad_segs") )
1347 quadsegs = atoi(val);
1352 "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1357 POSTGIS_DEBUGF(3,
"joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1361 lwgeom_result =
lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1364 lwpgerror(
"ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1366 gser_result = geometry_serialize(lwgeom_result);
1369 PG_RETURN_POINTER(gser_result);
1378 LWGEOM *lwgeom1, *lwgeom2, *lwresult;
1381 geom1 = PG_GETARG_GSERIALIZED_P(0);
1382 geom2 = PG_GETARG_GSERIALIZED_P(1);
1383 if (PG_NARGS() > 2 && ! PG_ARGISNULL(2))
1384 prec = PG_GETARG_FLOAT8(2);
1390 result = geometry_serialize(lwresult);
1396 PG_FREE_IF_COPY(geom1, 0);
1397 PG_FREE_IF_COPY(geom2, 1);
1399 PG_RETURN_POINTER(
result);
1408 LWGEOM *lwgeom1, *lwgeom2, *lwresult;
1411 geom1 = PG_GETARG_GSERIALIZED_P(0);
1412 geom2 = PG_GETARG_GSERIALIZED_P(1);
1413 if (PG_NARGS() > 2 && ! PG_ARGISNULL(2))
1414 prec = PG_GETARG_FLOAT8(2);
1420 result = geometry_serialize(lwresult);
1426 PG_FREE_IF_COPY(geom1, 0);
1427 PG_FREE_IF_COPY(geom2, 1);
1429 PG_RETURN_POINTER(
result);
1440 LWGEOM *lwgeom, *lwresult;
1442 geom = PG_GETARG_GSERIALIZED_P(0);
1447 PG_FREE_IF_COPY(geom, 0);
1449 if (!lwresult) PG_RETURN_NULL();
1451 result = geometry_serialize(lwresult);
1453 PG_RETURN_POINTER(
result);
1460 LWGEOM *lwgeom, *lwresult;
1462 geom = PG_GETARG_GSERIALIZED_P(0);
1467 PG_FREE_IF_COPY(geom, 0);
1469 if (!lwresult) PG_RETURN_NULL();
1471 result = geometry_serialize(lwresult);
1473 PG_RETURN_POINTER(
result);
1481 LWGEOM *lwgeom, *lwresult;
1482 double gridSize = PG_GETARG_FLOAT8(1);
1483 geom = PG_GETARG_GSERIALIZED_P(0);
1488 PG_FREE_IF_COPY(geom, 0);
1490 if (!lwresult) PG_RETURN_NULL();
1492 result = geometry_serialize(lwresult);
1494 PG_RETURN_POINTER(
result);
1501 static const uint32_t geom_idx = 0;
1502 static const uint32_t box2d_idx = 1;
1504 LWGEOM *lwgeom1, *lwresult ;
1514 PG_RETURN_DATUM(PG_GETARG_DATUM(geom_idx));
1518 bbox2 = (
GBOX *)PG_GETARG_POINTER(box2d_idx);
1524 PG_RETURN_DATUM(PG_GETARG_DATUM(geom_idx));
1532 result = geometry_serialize(lwresult) ;
1534 PG_RETURN_POINTER(
result);
1546 result = geometry_serialize(lwresult) ;
1547 PG_RETURN_POINTER(
result);
1561 geom1 = PG_GETARG_GSERIALIZED_P(0);
1565 PG_RETURN_BOOL(
true);
1572 lwpgerror(
"unable to deserialize input");
1579 PG_RETURN_BOOL(
false);
1582 result = GEOSisValid(g1);
1583 GEOSGeom_destroy(g1);
1587 elog(ERROR,
"GEOS isvalid() threw an error!");
1591 PG_FREE_IF_COPY(geom1, 0);
1599 char *reason_str = NULL;
1601 const GEOSGeometry *g1 = NULL;
1603 geom = PG_GETARG_GSERIALIZED_P(0);
1610 reason_str = GEOSisValidReason(g1);
1611 GEOSGeom_destroy((GEOSGeometry *)g1);
1613 result = cstring_to_text(reason_str);
1614 GEOSFree(reason_str);
1621 PG_FREE_IF_COPY(geom, 0);
1622 PG_RETURN_POINTER(
result);
1629 const GEOSGeometry *g1 = NULL;
1631 char *geos_reason = NULL;
1632 char *reason = NULL;
1633 GEOSGeometry *geos_location = NULL;
1639 AttInMetadata *attinmeta;
1646 get_call_result_type(fcinfo, 0, &tupdesc);
1647 BlessTupleDesc(tupdesc);
1653 attinmeta = TupleDescGetAttInMetadata(tupdesc);
1655 geom = PG_GETARG_GSERIALIZED_P(0);
1656 flags = PG_GETARG_INT32(1);
1664 valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1665 GEOSGeom_destroy((GEOSGeometry *)g1);
1668 reason = pstrdup(geos_reason);
1669 GEOSFree(geos_reason);
1671 if ( geos_location )
1673 location =
GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1674 GEOSGeom_destroy(geos_location);
1680 lwpgerror(
"GEOS isvaliddetail() threw an exception!");
1691 values[0] = valid ?
"t" :
"f";
1699 tuple = BuildTupleFromCStrings(attinmeta, values);
1700 result = (HeapTupleHeader) palloc(tuple->t_len);
1701 memcpy(
result, tuple->t_data, tuple->t_len);
1702 heap_freetuple(tuple);
1704 PG_RETURN_HEAPTUPLEHEADER(
result);
1719 GEOSGeometry *g1, *g2;
1723 geom1 = PG_GETARG_GSERIALIZED_P(0);
1724 geom2 = PG_GETARG_GSERIALIZED_P(1);
1729 PG_RETURN_BOOL(
false);
1740 PG_RETURN_BOOL(
false);
1754 GEOSGeom_destroy(g1);
1758 result = GEOSOverlaps(g1,g2);
1760 GEOSGeom_destroy(g1);
1761 GEOSGeom_destroy(g2);
1764 PG_FREE_IF_COPY(geom1, 0);
1765 PG_FREE_IF_COPY(geom2, 1);
1774 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
1775 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
1776 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
1777 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
1779 GEOSGeometry *g1, *g2;
1786 PG_RETURN_BOOL(
false);
1788 POSTGIS_DEBUG(3,
"contains called.");
1798 PG_RETURN_BOOL(
false);
1807 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
1808 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
1809 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
1810 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
1814 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
1821 retval = (pip_result == 1);
1826 int found_completely_inside =
LW_FALSE;
1829 for (uint32_t i = 0; i < mpoint->
ngeoms; i++)
1840 if (pip_result == 1)
1841 found_completely_inside =
LW_TRUE;
1843 if (pip_result == -1)
1850 retval = retval && found_completely_inside;
1856 elog(ERROR,
"Type isn't point or multipoint!");
1857 PG_RETURN_BOOL(
false);
1877 POSTGIS_DEBUG(4,
"containsPrepared: cache is live, running preparedcontains");
1879 GEOSGeom_destroy(g1);
1884 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
1889 GEOSGeom_destroy(g1);
1891 POSTGIS_DEBUG(4,
"containsPrepared: cache is not ready, running standard contains");
1892 result = GEOSContains( g1, g2);
1893 GEOSGeom_destroy(g1);
1894 GEOSGeom_destroy(g2);
1899 PG_RETURN_BOOL(
result > 0);
1906 PG_RETURN_DATUM(CallerFInfoFunctionCall2(
contains, fcinfo->flinfo, InvalidOid,
1907 PG_GETARG_DATUM(1), PG_GETARG_DATUM(0)));
1915 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
1916 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
1917 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
1918 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
1927 PG_RETURN_BOOL(
false);
1937 PG_RETURN_BOOL(
false);
1947 if (!g)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
1949 GEOSGeom_destroy(g);
1957 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
1961 GEOSGeom_destroy(g1);
1964 result = GEOSRelatePattern( g1, g2,
"T**FF*FF*" );
1965 GEOSGeom_destroy(g1);
1966 GEOSGeom_destroy(g2);
1981 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
1982 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
1983 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
1984 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
1992 PG_RETURN_BOOL(
false);
2005 PG_RETURN_BOOL(
false);
2014 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
2015 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
2016 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
2017 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
2021 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
2028 retval = (pip_result != -1);
2036 for (i = 0; i < mpoint->
ngeoms; i++)
2052 elog(ERROR,
"Type isn't point or multipoint!");
2056 PG_RETURN_BOOL(retval);
2070 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
2072 GEOSGeom_destroy(g1);
2080 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
2084 GEOSGeom_destroy(g1);
2087 result = GEOSRelatePattern( g1, g2,
"******FF*" );
2088 GEOSGeom_destroy(g1);
2089 GEOSGeom_destroy(g2);
2112 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
2113 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
2114 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
2115 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
2116 GEOSGeometry *g1, *g2;
2119 char *patt =
"**F**F***";
2125 PG_RETURN_BOOL(
false);
2136 PG_RETURN_BOOL(
false);
2139 POSTGIS_DEBUG(3,
"bounding box short-circuit missed.");
2147 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
2148 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
2149 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
2150 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
2154 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
2161 retval = (pip_result != -1);
2169 for (i = 0; i < mpoint->
ngeoms; i++)
2185 elog(ERROR,
"Type isn't point or multipoint!");
2189 PG_RETURN_BOOL(retval);
2207 GEOSGeom_destroy(g1);
2211 result = GEOSRelatePattern(g1,g2,patt);
2213 GEOSGeom_destroy(g1);
2214 GEOSGeom_destroy(g2);
2226 GEOSGeometry *g1, *g2;
2230 geom1 = PG_GETARG_GSERIALIZED_P(0);
2231 geom2 = PG_GETARG_GSERIALIZED_P(1);
2236 PG_RETURN_BOOL(
false);
2247 PG_RETURN_BOOL(
false);
2260 GEOSGeom_destroy(g1);
2264 result = GEOSCrosses(g1,g2);
2266 GEOSGeom_destroy(g1);
2267 GEOSGeom_destroy(g2);
2271 PG_FREE_IF_COPY(geom1, 0);
2272 PG_FREE_IF_COPY(geom2, 1);
2280 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
2281 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
2282 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
2283 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
2292 PG_RETURN_BOOL(
false);
2302 PG_RETURN_BOOL(
false);
2311 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
2312 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
2313 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
2314 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
2318 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
2325 retval = (pip_result != -1);
2331 for (uint32_t i = 0; i < mpoint->
ngeoms; i++)
2347 elog(ERROR,
"Type isn't point or multipoint!");
2351 PG_RETURN_BOOL(retval);
2359 if ( prep_cache->
gcache.argnum == 1 )
2364 GEOSGeom_destroy(g);
2372 GEOSGeom_destroy(g);
2380 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
2384 GEOSGeom_destroy(g1);
2387 result = GEOSIntersects( g1, g2);
2388 GEOSGeom_destroy(g1);
2389 GEOSGeom_destroy(g2);
2403 GEOSGeometry *g1, *g2;
2407 geom1 = PG_GETARG_GSERIALIZED_P(0);
2408 geom2 = PG_GETARG_GSERIALIZED_P(1);
2413 PG_RETURN_BOOL(
false);
2424 PG_RETURN_BOOL(
false);
2437 GEOSGeom_destroy(g1);
2441 result = GEOSTouches(g1,g2);
2443 GEOSGeom_destroy(g1);
2444 GEOSGeom_destroy(g2);
2448 PG_FREE_IF_COPY(geom1, 0);
2449 PG_FREE_IF_COPY(geom2, 1);
2460 GEOSGeometry *g1, *g2;
2464 geom1 = PG_GETARG_GSERIALIZED_P(0);
2465 geom2 = PG_GETARG_GSERIALIZED_P(1);
2470 PG_RETURN_BOOL(
true);
2481 PG_RETURN_BOOL(
true);
2494 GEOSGeom_destroy(g1);
2498 result = GEOSDisjoint(g1,g2);
2500 GEOSGeom_destroy(g1);
2501 GEOSGeom_destroy(g2);
2505 PG_FREE_IF_COPY(geom1, 0);
2506 PG_FREE_IF_COPY(geom2, 1);
2520 GEOSGeometry *g1, *g2;
2523 geom1 = PG_GETARG_GSERIALIZED_P(0);
2524 geom2 = PG_GETARG_GSERIALIZED_P(1);
2537 GEOSGeom_destroy(g1);
2542 ptxt = DatumGetTextP(DirectFunctionCall2(text_left,
2543 PG_GETARG_DATUM(2), Int32GetDatum(9)));
2544 patt = text_to_cstring(ptxt);
2549 for ( i = 0; i < strlen(patt); i++ )
2551 if ( patt[i] ==
't' ) patt[i] =
'T';
2552 if ( patt[i] ==
'f' ) patt[i] =
'F';
2555 result = GEOSRelatePattern(g1,g2,patt);
2556 GEOSGeom_destroy(g1);
2557 GEOSGeom_destroy(g2);
2562 PG_FREE_IF_COPY(geom1, 0);
2563 PG_FREE_IF_COPY(geom2, 1);
2575 GEOSGeometry *g1, *g2;
2578 int bnr = GEOSRELATE_BNR_OGC;
2581 geom1 = PG_GETARG_GSERIALIZED_P(0);
2582 geom2 = PG_GETARG_GSERIALIZED_P(1);
2585 if ( PG_NARGS() > 2 )
2586 bnr = PG_GETARG_INT32(2);
2596 GEOSGeom_destroy(g1);
2600 POSTGIS_DEBUG(3,
"constructed geometries ");
2602 POSTGIS_DEBUGF(3,
"%s", GEOSGeomToWKT(g1));
2603 POSTGIS_DEBUGF(3,
"%s", GEOSGeomToWKT(g2));
2605 relate_str = GEOSRelateBoundaryNodeRule(g1, g2, bnr);
2607 GEOSGeom_destroy(g1);
2608 GEOSGeom_destroy(g2);
2612 result = cstring_to_text(relate_str);
2613 GEOSFree(relate_str);
2615 PG_FREE_IF_COPY(geom1, 0);
2616 PG_FREE_IF_COPY(geom2, 1);
2618 PG_RETURN_TEXT_P(
result);
2627 GEOSGeometry *g1, *g2;
2631 geom1 = PG_GETARG_GSERIALIZED_P(0);
2632 geom2 = PG_GETARG_GSERIALIZED_P(1);
2637 PG_RETURN_BOOL(
true);
2648 PG_RETURN_BOOL(
false);
2656 if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
2657 PG_RETURN_BOOL(
true);
2671 GEOSGeom_destroy(g1);
2675 result = GEOSEquals(g1,g2);
2677 GEOSGeom_destroy(g1);
2678 GEOSGeom_destroy(g2);
2682 PG_FREE_IF_COPY(geom1, 0);
2683 PG_FREE_IF_COPY(geom2, 1);
2695 POSTGIS_DEBUG(2,
"issimple called");
2697 geom = PG_GETARG_GSERIALIZED_P(0);
2700 PG_RETURN_BOOL(
true);
2705 PG_FREE_IF_COPY(geom, 0);
2721 geom = PG_GETARG_GSERIALIZED_P(0);
2725 PG_RETURN_BOOL(
false);
2733 if ( GEOSGeomTypeId(g1) != GEOS_LINESTRING )
2735 GEOSGeom_destroy(g1);
2736 elog(ERROR,
"ST_IsRing() should only be called on a linear feature");
2740 GEOSGeom_destroy(g1);
2744 PG_FREE_IF_COPY(geom, 0);
2757 lwpgerror(
"%s: GEOS2LWGEOM returned NULL", __func__);
2761 POSTGIS_DEBUGF(4,
"%s: GEOS2LWGEOM returned a %s", __func__,
lwgeom_summary(lwgeom, 0));
2765 result = geometry_serialize(lwgeom);
2780 lwpgerror(
"POSTGIS2GEOS: unable to deserialize input");
2790 ArrayIterator iterator;
2793 uint32_t nelems_not_null = 0;
2794 iterator = array_create_iterator(array, 0, NULL);
2795 while(array_iterate(iterator, &
value, &isnull) )
2799 array_free_iterator(iterator);
2801 return nelems_not_null;
2807 ArrayIterator iterator;
2810 bool gotsrid =
false;
2815 iterator = array_create_iterator(array, 0, NULL);
2817 while (array_iterate(iterator, &
value, &isnull))
2829 lwpgerror(
"Geometry deserializing geometry");
2847 GEOSGeometry**
ARRAY2GEOS(ArrayType* array, uint32_t nelems,
int* is3d,
int* srid)
2849 ArrayIterator iterator;
2852 bool gotsrid =
false;
2855 GEOSGeometry** geos_geoms = palloc(nelems *
sizeof(GEOSGeometry*));
2857 iterator = array_create_iterator(array, 0, NULL);
2859 while(array_iterate(iterator, &
value, &isnull))
2872 lwpgerror(
"Geometry could not be converted to GEOS");
2874 for (j = 0; j < i; j++) {
2875 GEOSGeom_destroy(geos_geoms[j]);
2888 for (j = 0; j <= i; j++) {
2889 GEOSGeom_destroy(geos_geoms[j]);
2898 array_free_iterator(iterator);
2906 GEOSGeometry *geosgeom;
2911 geom = PG_GETARG_GSERIALIZED_P(0);
2913 if ( ! geosgeom ) PG_RETURN_NULL();
2916 GEOSGeom_destroy(geosgeom);
2918 PG_FREE_IF_COPY(geom, 0);
2920 PG_RETURN_POINTER(lwgeom_result);
2930 GEOSGeometry *geos_result;
2931 const GEOSGeometry **vgeoms;
2933 #if POSTGIS_DEBUG_LEVEL >= 3
2937 #if POSTGIS_DEBUG_LEVEL >= 3
2941 if (PG_ARGISNULL(0))
2944 array = PG_GETARG_ARRAYTYPE_P(0);
2950 POSTGIS_DEBUGF(3,
"polygonize_garray: number of non-null elements: %d", nelems);
2955 vgeoms = (
const GEOSGeometry**)
ARRAY2GEOS(array, nelems, &is3d, &srid);
2957 POSTGIS_DEBUG(3,
"polygonize_garray: invoking GEOSpolygonize");
2959 geos_result = GEOSPolygonize(vgeoms, nelems);
2961 POSTGIS_DEBUG(3,
"polygonize_garray: GEOSpolygonize returned");
2963 for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
2966 if ( ! geos_result ) PG_RETURN_NULL();
2968 GEOSSetSRID(geos_result, srid);
2970 GEOSGeom_destroy(geos_result);
2973 elog(ERROR,
"%s returned an error", __func__);
2977 PG_RETURN_POINTER(
result);
2984 Datum* result_array_data;
2985 ArrayType *array, *
result;
2987 uint32 nelems, nclusters, i;
2988 GEOSGeometry **geos_inputs, **geos_results;
2997 if (PG_ARGISNULL(0))
3000 array = PG_GETARG_ARRAYTYPE_P(0);
3003 POSTGIS_DEBUGF(3,
"clusterintersecting_garray: number of non-null elements: %d", nelems);
3005 if ( nelems == 0 ) PG_RETURN_NULL();
3012 geos_inputs =
ARRAY2GEOS(array, nelems, &is3d, &srid);
3020 elog(ERROR,
"clusterintersecting: Error performing clustering");
3025 if (!geos_results) PG_RETURN_NULL();
3027 result_array_data = palloc(nclusters *
sizeof(Datum));
3028 for (i=0; i<nclusters; ++i)
3030 result_array_data[i] = PointerGetDatum(
GEOS2POSTGIS(geos_results[i], is3d));
3031 GEOSGeom_destroy(geos_results[i]);
3035 get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3036 result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3040 elog(ERROR,
"clusterintersecting: Error constructing return-array");
3044 PG_RETURN_POINTER(
result);
3050 Datum* result_array_data;
3051 ArrayType *array, *
result;
3053 uint32 nelems, nclusters, i;
3065 if (PG_ARGISNULL(0))
3068 array = PG_GETARG_ARRAYTYPE_P(0);
3070 tolerance = PG_GETARG_FLOAT8(1);
3073 lwpgerror(
"Tolerance must be a positive number.");
3079 POSTGIS_DEBUGF(3,
"cluster_within_distance_garray: number of non-null elements: %d", nelems);
3081 if ( nelems == 0 ) PG_RETURN_NULL();
3096 elog(ERROR,
"cluster_within: Error performing clustering");
3101 if (!lw_results) PG_RETURN_NULL();
3103 result_array_data = palloc(nclusters *
sizeof(Datum));
3104 for (i=0; i<nclusters; ++i)
3106 result_array_data[i] = PointerGetDatum(geometry_serialize(lw_results[i]));
3111 get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3112 result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3116 elog(ERROR,
"clusterwithin: Error constructing return-array");
3120 PG_RETURN_POINTER(
result);
3128 LWGEOM *lwgeom1, *lwresult ;
3130 geom1 = PG_GETARG_GSERIALIZED_P(0);
3136 result = geometry_serialize(lwresult) ;
3141 PG_FREE_IF_COPY(geom1, 0);
3143 PG_RETURN_POINTER(
result);
3158 LWGEOM *lwgeom_in, *lwgeom_out;
3160 geom = PG_GETARG_GSERIALIZED_P(0);
3168 PG_FREE_IF_COPY(geom, 0);
3172 result = geometry_serialize(lwgeom_out) ;
3175 PG_FREE_IF_COPY(geom, 0);
3176 PG_RETURN_POINTER(
result);
3188 LWGEOM *lwgeom_in, *lwgeom_out;
3189 double tolerance = 0.0;
3192 geom = PG_GETARG_GSERIALIZED_P(0);
3193 tolerance = PG_GETARG_FLOAT8(1);
3194 flags = PG_GETARG_INT32(2);
3202 PG_FREE_IF_COPY(geom, 0);
3206 result = geometry_serialize(lwgeom_out) ;
3209 PG_FREE_IF_COPY(geom, 0);
3210 PG_RETURN_POINTER(
result);
3218 Datum
ST_Snap(PG_FUNCTION_ARGS);
3223 LWGEOM *lwgeom1, *lwgeom2, *lwresult;
3226 geom1 = PG_GETARG_GSERIALIZED_P(0);
3227 geom2 = PG_GETARG_GSERIALIZED_P(1);
3228 tolerance = PG_GETARG_FLOAT8(2);
3233 lwresult =
lwgeom_snap(lwgeom1, lwgeom2, tolerance);
3236 PG_FREE_IF_COPY(geom1, 0);
3237 PG_FREE_IF_COPY(geom2, 1);
3239 result = geometry_serialize(lwresult);
3242 PG_RETURN_POINTER(
result);
3274 LWGEOM *lwgeom_in, *lwblade_in, *lwgeom_out;
3276 in = PG_GETARG_GSERIALIZED_P(0);
3277 blade_in = PG_GETARG_GSERIALIZED_P(1);
3285 lwpgerror(
"Input Geometry contains invalid coordinates");
3291 lwpgerror(
"Blade Geometry contains invalid coordinates");
3302 PG_FREE_IF_COPY(in, 0);
3303 PG_FREE_IF_COPY(blade_in, 1);
3307 out = geometry_serialize(lwgeom_out);
3309 PG_FREE_IF_COPY(in, 0);
3310 PG_FREE_IF_COPY(blade_in, 1);
3312 PG_RETURN_POINTER(out);
3335 LWGEOM *g1, *g2, *lwgeom_out;
3337 geom1 = PG_GETARG_GSERIALIZED_P(0);
3338 geom2 = PG_GETARG_GSERIALIZED_P(1);
3349 PG_FREE_IF_COPY(geom1, 0);
3350 PG_FREE_IF_COPY(geom2, 1);
3354 out = geometry_serialize(lwgeom_out);
3357 PG_FREE_IF_COPY(geom1, 0);
3358 PG_FREE_IF_COPY(geom2, 1);
3359 PG_RETURN_POINTER(out);
3371 Datum
ST_Node(PG_FUNCTION_ARGS);
3378 geom1 = PG_GETARG_GSERIALIZED_P(0);
3387 PG_FREE_IF_COPY(geom1, 0);
3391 out = geometry_serialize(lwgeom_out);
3394 PG_FREE_IF_COPY(geom1, 0);
3395 PG_RETURN_POINTER(out);
3417 int custom_clip_envelope;
3418 int return_polygons;
3421 if (PG_ARGISNULL(0))
3425 if (PG_ARGISNULL(2))
3427 lwpgerror(
"Tolerance must be a positive number.");
3431 tolerance = PG_GETARG_FLOAT8(2);
3435 lwpgerror(
"Tolerance must be a positive number.");
3440 if (PG_ARGISNULL(3))
3442 lwpgerror(
"return_polygons must be true or false.");
3445 return_polygons = PG_GETARG_BOOL(3);
3448 custom_clip_envelope = !PG_ARGISNULL(1);
3449 if (custom_clip_envelope) {
3450 clip = PG_GETARG_GSERIALIZED_P(1);
3453 lwpgerror(
"Could not determine envelope of clipping geometry.");
3454 PG_FREE_IF_COPY(clip, 1);
3457 PG_FREE_IF_COPY(clip, 1);
3461 input = PG_GETARG_GSERIALIZED_P(0);
3467 lwpgerror(
"Could not read input geometry.");
3468 PG_FREE_IF_COPY(input, 0);
3472 lwgeom_result =
lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3477 lwpgerror(
"Error computing Voronoi diagram.");
3478 PG_FREE_IF_COPY(input, 0);
3482 result = geometry_serialize(lwgeom_result);
3485 PG_FREE_IF_COPY(input, 0);
3486 PG_RETURN_POINTER(
result);
3501 GEOSGeometry* input_geos;
3507 input = PG_GETARG_GSERIALIZED_P(0);
3512 error = GEOSMinimumClearance(input_geos, &
result);
3513 GEOSGeom_destroy(input_geos);
3516 PG_FREE_IF_COPY(input, 0);
3517 PG_RETURN_FLOAT8(
result);
3533 GEOSGeometry* input_geos;
3534 GEOSGeometry* result_geos;
3539 input = PG_GETARG_GSERIALIZED_P(0);
3545 result_geos = GEOSMinimumClearanceLine(input_geos);
3546 GEOSGeom_destroy(input_geos);
3550 GEOSSetSRID(result_geos, srid);
3552 GEOSGeom_destroy(result_geos);
3554 PG_FREE_IF_COPY(input, 0);
3555 PG_RETURN_POINTER(
result);
3569 GEOSGeometry* input_geos;
3570 GEOSGeometry* result_geos;
3575 input = PG_GETARG_GSERIALIZED_P(0);
3581 result_geos = GEOSMinimumRotatedRectangle(input_geos);
3582 GEOSGeom_destroy(input_geos);
3586 GEOSSetSRID(result_geos, srid);
3588 GEOSGeom_destroy(result_geos);
3590 PG_FREE_IF_COPY(input, 0);
3591 PG_RETURN_POINTER(
result);
char result[OUT_DOUBLE_BUFFER_SIZE]
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
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)
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_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
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.
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_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.
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
int cluster_within_distance(LWGEOM **geoms, uint32_t num_geoms, double tolerance, LWGEOM ***clusterGeoms, uint32_t *num_clusters)
Takes an array of LWGEOM* and constructs an array of LWGEOM*, where each element in the constructed a...
int cluster_intersecting(GEOSGeometry **geoms, uint32_t num_geoms, GEOSGeometry ***clusterGeoms, uint32_t *num_clusters)
Takes an array of GEOSGeometry* and constructs an array of GEOSGeometry*, where each element in the c...
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
LWGEOM * lwgeom_centroid(const LWGEOM *geom)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
void lwmpoint_free(LWMPOINT *mpt)
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
int lwgeom_is_simple(const LWGEOM *lwgeom)
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
const char * lwgeom_geos_version(void)
Return GEOS version string (not to be freed)
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
LWGEOM * lwgeom_pointonsurface(const LWGEOM *geom)
LWGEOM * lwgeom_sharedpaths(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
LWGEOM * lwgeom_difference_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
LWGEOM * lwgeom_union_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
LWGEOM * lwgeom_unaryunion_prec(const LWGEOM *geom1, double gridSize)
LWGEOM * lwgeom_buildarea(const LWGEOM *geom)
Take a geometry and return an areal geometry (Polygon or MultiPolygon).
LWGEOM * lwgeom_symdifference_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
void lwcollection_free(LWCOLLECTION *col)
LWGEOM * lwgeom_intersection_prec(const LWGEOM *geom1, const LWGEOM *geom2, double gridSize)
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
LWGEOM * lwgeom_reduceprecision(const LWGEOM *geom, double gridSize)
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, uint32_t npoints, int32_t seed)
#define LW_TRUE
Return types for functions with status returns.
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
#define SRID_UNKNOWN
Unknown SRID value.
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
This library is the generic geometry handling section of PostGIS.
int lwpoint_is_empty(const LWPOINT *point)
int point_in_multipolygon(LWMPOLY *mpolygon, LWPOINT *point)
int point_in_multipolygon_rtree(RTREE_NODE **root, int polyCount, int *ringCounts, LWPOINT *point)
int point_in_polygon(LWPOLY *polygon, LWPOINT *point)
PrepGeomCache * GetPrepGeomCache(FunctionCallInfo fcinfo, SHARED_GSERIALIZED *g1, SHARED_GSERIALIZED *g2)
Given a couple potential geometries and a function call context, return a prepared structure for one ...
RTREE_POLY_CACHE * GetRtreeCache(FunctionCallInfo fcinfo, SHARED_GSERIALIZED *g1)
Checks for a cache hit against the provided geometry and returns a pre-built index structure (RTREE_P...
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
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)
uint32_t array_nelems_not_null(ArrayType *array)
Datum ST_ReducePrecision(PG_FUNCTION_ARGS)
Datum polygonize_garray(PG_FUNCTION_ARGS)
Datum contains(PG_FUNCTION_ARGS)
Datum coveredby(PG_FUNCTION_ARGS)
Datum ST_Intersection(PG_FUNCTION_ARGS)
Datum isvaliddetail(PG_FUNCTION_ARGS)
#define HANDLE_GEOS_ERROR(label)
Datum isvalid(PG_FUNCTION_ARGS)
static char is_point(const GSERIALIZED *g)
Datum ST_Snap(PG_FUNCTION_ARGS)
Datum ST_Union(PG_FUNCTION_ARGS)
Datum ST_BuildArea(PG_FUNCTION_ARGS)
Datum ST_Split(PG_FUNCTION_ARGS)
Datum covers(PG_FUNCTION_ARGS)
Datum ST_Node(PG_FUNCTION_ARGS)
Datum ST_GeneratePoints(PG_FUNCTION_ARGS)
Datum hausdorffdistancedensify(PG_FUNCTION_ARGS)
Datum ST_OffsetCurve(PG_FUNCTION_ARGS)
Datum cluster_within_distance_garray(PG_FUNCTION_ARGS)
Datum centroid(PG_FUNCTION_ARGS)
Datum touches(PG_FUNCTION_ARGS)
Datum disjoint(PG_FUNCTION_ARGS)
Datum ST_MinimumClearance(PG_FUNCTION_ARGS)
Datum ST_Intersects(PG_FUNCTION_ARGS)
Datum GEOSnoop(PG_FUNCTION_ARGS)
Datum ST_FrechetDistance(PG_FUNCTION_ARGS)
Datum buffer(PG_FUNCTION_ARGS)
Datum convexhull(PG_FUNCTION_ARGS)
static int pip_short_circuit(RTREE_POLY_CACHE *poly_cache, LWPOINT *point, const GSERIALIZED *gpoly)
Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
Datum crosses(PG_FUNCTION_ARGS)
Datum ST_SymDifference(PG_FUNCTION_ARGS)
Datum relate_full(PG_FUNCTION_ARGS)
Datum relate_pattern(PG_FUNCTION_ARGS)
Datum issimple(PG_FUNCTION_ARGS)
Datum symdifference(PG_FUNCTION_ARGS)
LWGEOM ** ARRAY2LWGEOM(ArrayType *array, uint32_t nelems, int *is3d, int *srid)
Datum topologypreservesimplify(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(postgis_geos_version)
Datum ST_MaximumInscribedCircle(PG_FUNCTION_ARGS)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
Datum ST_DelaunayTriangles(PG_FUNCTION_ARGS)
static char is_poly(const GSERIALIZED *g)
Datum boundary(PG_FUNCTION_ARGS)
Datum postgis_geos_version(PG_FUNCTION_ARGS)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
Datum ST_UnaryUnion(PG_FUNCTION_ARGS)
Datum overlaps(PG_FUNCTION_ARGS)
Datum ST_Equals(PG_FUNCTION_ARGS)
Datum within(PG_FUNCTION_ARGS)
Datum ST_OrientedEnvelope(PG_FUNCTION_ARGS)
Datum ST_SharedPaths(PG_FUNCTION_ARGS)
Datum ST_MinimumClearanceLine(PG_FUNCTION_ARGS)
Datum ST_Voronoi(PG_FUNCTION_ARGS)
Datum clusterintersecting_garray(PG_FUNCTION_ARGS)
Datum pgis_geometry_union_finalfn(PG_FUNCTION_ARGS)
GEOSGeometry ** ARRAY2GEOS(ArrayType *array, uint32_t nelems, int *is3d, int *srid)
Datum ST_Difference(PG_FUNCTION_ARGS)
Datum pgis_union_geometry_array(PG_FUNCTION_ARGS)
Datum hausdorffdistance(PG_FUNCTION_ARGS)
Datum isvalidreason(PG_FUNCTION_ARGS)
Datum isring(PG_FUNCTION_ARGS)
Datum linemerge(PG_FUNCTION_ARGS)
Datum pointonsurface(PG_FUNCTION_ARGS)
Datum containsproperly(PG_FUNCTION_ARGS)
#define POSTGIS_GEOS_VERSION
const GEOSPreparedGeometry * prepared_geom
RTREE_NODE ** ringIndices
The tree structure used for fast P-i-P tests by point_in_multipolygon_rtree()