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);
1525 PG_RETURN_DATUM(PG_GETARG_DATUM(geom_idx));
1533 result = geometry_serialize(lwresult) ;
1535 PG_RETURN_POINTER(
result);
1547 result = geometry_serialize(lwresult) ;
1548 PG_RETURN_POINTER(
result);
1562 geom1 = PG_GETARG_GSERIALIZED_P(0);
1566 PG_RETURN_BOOL(
true);
1573 lwpgerror(
"unable to deserialize input");
1580 PG_RETURN_BOOL(
false);
1583 result = GEOSisValid(g1);
1584 GEOSGeom_destroy(g1);
1588 elog(ERROR,
"GEOS isvalid() threw an error!");
1592 PG_FREE_IF_COPY(geom1, 0);
1600 char *reason_str = NULL;
1602 const GEOSGeometry *g1 = NULL;
1604 geom = PG_GETARG_GSERIALIZED_P(0);
1611 reason_str = GEOSisValidReason(g1);
1612 GEOSGeom_destroy((GEOSGeometry *)g1);
1614 result = cstring_to_text(reason_str);
1615 GEOSFree(reason_str);
1622 PG_FREE_IF_COPY(geom, 0);
1623 PG_RETURN_POINTER(
result);
1630 const GEOSGeometry *g1 = NULL;
1632 char *geos_reason = NULL;
1633 char *reason = NULL;
1634 GEOSGeometry *geos_location = NULL;
1640 AttInMetadata *attinmeta;
1647 get_call_result_type(fcinfo, 0, &tupdesc);
1648 BlessTupleDesc(tupdesc);
1654 attinmeta = TupleDescGetAttInMetadata(tupdesc);
1656 geom = PG_GETARG_GSERIALIZED_P(0);
1657 flags = PG_GETARG_INT32(1);
1665 valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1666 GEOSGeom_destroy((GEOSGeometry *)g1);
1669 reason = pstrdup(geos_reason);
1670 GEOSFree(geos_reason);
1672 if ( geos_location )
1674 location =
GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1675 GEOSGeom_destroy(geos_location);
1681 lwpgerror(
"GEOS isvaliddetail() threw an exception!");
1692 values[0] = valid ?
"t" :
"f";
1700 tuple = BuildTupleFromCStrings(attinmeta, values);
1701 result = (HeapTupleHeader) palloc(tuple->t_len);
1702 memcpy(
result, tuple->t_data, tuple->t_len);
1703 heap_freetuple(tuple);
1705 PG_RETURN_HEAPTUPLEHEADER(
result);
1720 GEOSGeometry *g1, *g2;
1724 geom1 = PG_GETARG_GSERIALIZED_P(0);
1725 geom2 = PG_GETARG_GSERIALIZED_P(1);
1730 PG_RETURN_BOOL(
false);
1741 PG_RETURN_BOOL(
false);
1755 GEOSGeom_destroy(g1);
1759 result = GEOSOverlaps(g1,g2);
1761 GEOSGeom_destroy(g1);
1762 GEOSGeom_destroy(g2);
1765 PG_FREE_IF_COPY(geom1, 0);
1766 PG_FREE_IF_COPY(geom2, 1);
1775 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
1776 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
1777 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
1778 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
1780 GEOSGeometry *g1, *g2;
1787 PG_RETURN_BOOL(
false);
1789 POSTGIS_DEBUG(3,
"contains called.");
1799 PG_RETURN_BOOL(
false);
1808 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
1809 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
1810 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
1811 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
1815 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
1822 retval = (pip_result == 1);
1827 int found_completely_inside =
LW_FALSE;
1830 for (uint32_t i = 0; i < mpoint->
ngeoms; i++)
1841 if (pip_result == 1)
1842 found_completely_inside =
LW_TRUE;
1844 if (pip_result == -1)
1851 retval = retval && found_completely_inside;
1857 elog(ERROR,
"Type isn't point or multipoint!");
1858 PG_RETURN_BOOL(
false);
1878 POSTGIS_DEBUG(4,
"containsPrepared: cache is live, running preparedcontains");
1880 GEOSGeom_destroy(g1);
1885 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
1890 GEOSGeom_destroy(g1);
1892 POSTGIS_DEBUG(4,
"containsPrepared: cache is not ready, running standard contains");
1893 result = GEOSContains( g1, g2);
1894 GEOSGeom_destroy(g1);
1895 GEOSGeom_destroy(g2);
1900 PG_RETURN_BOOL(
result > 0);
1907 PG_RETURN_DATUM(CallerFInfoFunctionCall2(
contains, fcinfo->flinfo, InvalidOid,
1908 PG_GETARG_DATUM(1), PG_GETARG_DATUM(0)));
1916 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
1917 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
1918 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
1919 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
1928 PG_RETURN_BOOL(
false);
1938 PG_RETURN_BOOL(
false);
1948 if (!g)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
1950 GEOSGeom_destroy(g);
1958 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
1962 GEOSGeom_destroy(g1);
1965 result = GEOSRelatePattern( g1, g2,
"T**FF*FF*" );
1966 GEOSGeom_destroy(g1);
1967 GEOSGeom_destroy(g2);
1982 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
1983 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
1984 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
1985 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
1993 PG_RETURN_BOOL(
false);
2006 PG_RETURN_BOOL(
false);
2015 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
2016 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
2017 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
2018 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
2022 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
2029 retval = (pip_result != -1);
2037 for (i = 0; i < mpoint->
ngeoms; i++)
2053 elog(ERROR,
"Type isn't point or multipoint!");
2057 PG_RETURN_BOOL(retval);
2071 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
2073 GEOSGeom_destroy(g1);
2081 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
2085 GEOSGeom_destroy(g1);
2088 result = GEOSRelatePattern( g1, g2,
"******FF*" );
2089 GEOSGeom_destroy(g1);
2090 GEOSGeom_destroy(g2);
2113 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
2114 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
2115 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
2116 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
2117 GEOSGeometry *g1, *g2;
2120 char *patt =
"**F**F***";
2126 PG_RETURN_BOOL(
false);
2137 PG_RETURN_BOOL(
false);
2140 POSTGIS_DEBUG(3,
"bounding box short-circuit missed.");
2148 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
2149 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
2150 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
2151 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
2155 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
2162 retval = (pip_result != -1);
2170 for (i = 0; i < mpoint->
ngeoms; i++)
2186 elog(ERROR,
"Type isn't point or multipoint!");
2190 PG_RETURN_BOOL(retval);
2208 GEOSGeom_destroy(g1);
2212 result = GEOSRelatePattern(g1,g2,patt);
2214 GEOSGeom_destroy(g1);
2215 GEOSGeom_destroy(g2);
2227 GEOSGeometry *g1, *g2;
2231 geom1 = PG_GETARG_GSERIALIZED_P(0);
2232 geom2 = PG_GETARG_GSERIALIZED_P(1);
2237 PG_RETURN_BOOL(
false);
2248 PG_RETURN_BOOL(
false);
2261 GEOSGeom_destroy(g1);
2265 result = GEOSCrosses(g1,g2);
2267 GEOSGeom_destroy(g1);
2268 GEOSGeom_destroy(g2);
2272 PG_FREE_IF_COPY(geom1, 0);
2273 PG_FREE_IF_COPY(geom2, 1);
2281 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
2282 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
2283 const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
2284 const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
2293 PG_RETURN_BOOL(
false);
2303 PG_RETURN_BOOL(
false);
2312 SHARED_GSERIALIZED *shared_gpoly =
is_poly(geom1) ? shared_geom1 : shared_geom2;
2313 SHARED_GSERIALIZED *shared_gpoint =
is_point(geom1) ? shared_geom1 : shared_geom2;
2314 const GSERIALIZED *gpoly = shared_gserialized_get(shared_gpoly);
2315 const GSERIALIZED *gpoint = shared_gserialized_get(shared_gpoint);
2319 POSTGIS_DEBUG(3,
"Point in Polygon test requested...short-circuiting.");
2326 retval = (pip_result != -1);
2332 for (uint32_t i = 0; i < mpoint->
ngeoms; i++)
2348 elog(ERROR,
"Type isn't point or multipoint!");
2352 PG_RETURN_BOOL(retval);
2360 if ( prep_cache->
gcache.argnum == 1 )
2365 GEOSGeom_destroy(g);
2373 GEOSGeom_destroy(g);
2381 if (!g1)
HANDLE_GEOS_ERROR(
"First argument geometry could not be converted to GEOS");
2385 GEOSGeom_destroy(g1);
2388 result = GEOSIntersects( g1, g2);
2389 GEOSGeom_destroy(g1);
2390 GEOSGeom_destroy(g2);
2404 GEOSGeometry *g1, *g2;
2408 geom1 = PG_GETARG_GSERIALIZED_P(0);
2409 geom2 = PG_GETARG_GSERIALIZED_P(1);
2414 PG_RETURN_BOOL(
false);
2425 PG_RETURN_BOOL(
false);
2438 GEOSGeom_destroy(g1);
2442 result = GEOSTouches(g1,g2);
2444 GEOSGeom_destroy(g1);
2445 GEOSGeom_destroy(g2);
2449 PG_FREE_IF_COPY(geom1, 0);
2450 PG_FREE_IF_COPY(geom2, 1);
2461 GEOSGeometry *g1, *g2;
2465 geom1 = PG_GETARG_GSERIALIZED_P(0);
2466 geom2 = PG_GETARG_GSERIALIZED_P(1);
2471 PG_RETURN_BOOL(
true);
2482 PG_RETURN_BOOL(
true);
2495 GEOSGeom_destroy(g1);
2499 result = GEOSDisjoint(g1,g2);
2501 GEOSGeom_destroy(g1);
2502 GEOSGeom_destroy(g2);
2506 PG_FREE_IF_COPY(geom1, 0);
2507 PG_FREE_IF_COPY(geom2, 1);
2521 GEOSGeometry *g1, *g2;
2524 geom1 = PG_GETARG_GSERIALIZED_P(0);
2525 geom2 = PG_GETARG_GSERIALIZED_P(1);
2538 GEOSGeom_destroy(g1);
2543 ptxt = DatumGetTextP(DirectFunctionCall2(text_left,
2544 PG_GETARG_DATUM(2), Int32GetDatum(9)));
2545 patt = text_to_cstring(ptxt);
2550 for ( i = 0; i < strlen(patt); i++ )
2552 if ( patt[i] ==
't' ) patt[i] =
'T';
2553 if ( patt[i] ==
'f' ) patt[i] =
'F';
2556 result = GEOSRelatePattern(g1,g2,patt);
2557 GEOSGeom_destroy(g1);
2558 GEOSGeom_destroy(g2);
2563 PG_FREE_IF_COPY(geom1, 0);
2564 PG_FREE_IF_COPY(geom2, 1);
2576 GEOSGeometry *g1, *g2;
2579 int bnr = GEOSRELATE_BNR_OGC;
2582 geom1 = PG_GETARG_GSERIALIZED_P(0);
2583 geom2 = PG_GETARG_GSERIALIZED_P(1);
2586 if ( PG_NARGS() > 2 )
2587 bnr = PG_GETARG_INT32(2);
2597 GEOSGeom_destroy(g1);
2601 POSTGIS_DEBUG(3,
"constructed geometries ");
2603 POSTGIS_DEBUGF(3,
"%s", GEOSGeomToWKT(g1));
2604 POSTGIS_DEBUGF(3,
"%s", GEOSGeomToWKT(g2));
2606 relate_str = GEOSRelateBoundaryNodeRule(g1, g2, bnr);
2608 GEOSGeom_destroy(g1);
2609 GEOSGeom_destroy(g2);
2613 result = cstring_to_text(relate_str);
2614 GEOSFree(relate_str);
2616 PG_FREE_IF_COPY(geom1, 0);
2617 PG_FREE_IF_COPY(geom2, 1);
2619 PG_RETURN_TEXT_P(
result);
2628 GEOSGeometry *g1, *g2;
2632 geom1 = PG_GETARG_GSERIALIZED_P(0);
2633 geom2 = PG_GETARG_GSERIALIZED_P(1);
2638 PG_RETURN_BOOL(
true);
2649 PG_RETURN_BOOL(
false);
2657 if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
2658 PG_RETURN_BOOL(
true);
2672 GEOSGeom_destroy(g1);
2676 result = GEOSEquals(g1,g2);
2678 GEOSGeom_destroy(g1);
2679 GEOSGeom_destroy(g2);
2683 PG_FREE_IF_COPY(geom1, 0);
2684 PG_FREE_IF_COPY(geom2, 1);
2696 POSTGIS_DEBUG(2,
"issimple called");
2698 geom = PG_GETARG_GSERIALIZED_P(0);
2701 PG_RETURN_BOOL(
true);
2706 PG_FREE_IF_COPY(geom, 0);
2722 geom = PG_GETARG_GSERIALIZED_P(0);
2726 PG_RETURN_BOOL(
false);
2734 if ( GEOSGeomTypeId(g1) != GEOS_LINESTRING )
2736 GEOSGeom_destroy(g1);
2737 elog(ERROR,
"ST_IsRing() should only be called on a linear feature");
2741 GEOSGeom_destroy(g1);
2745 PG_FREE_IF_COPY(geom, 0);
2758 lwpgerror(
"%s: GEOS2LWGEOM returned NULL", __func__);
2762 POSTGIS_DEBUGF(4,
"%s: GEOS2LWGEOM returned a %s", __func__,
lwgeom_summary(lwgeom, 0));
2766 result = geometry_serialize(lwgeom);
2781 lwpgerror(
"POSTGIS2GEOS: unable to deserialize input");
2791 ArrayIterator iterator;
2794 uint32_t nelems_not_null = 0;
2795 iterator = array_create_iterator(array, 0, NULL);
2796 while(array_iterate(iterator, &
value, &isnull) )
2800 array_free_iterator(iterator);
2802 return nelems_not_null;
2808 ArrayIterator iterator;
2811 bool gotsrid =
false;
2816 iterator = array_create_iterator(array, 0, NULL);
2818 while (array_iterate(iterator, &
value, &isnull))
2830 lwpgerror(
"Geometry deserializing geometry");
2848 GEOSGeometry**
ARRAY2GEOS(ArrayType* array, uint32_t nelems,
int* is3d,
int* srid)
2850 ArrayIterator iterator;
2853 bool gotsrid =
false;
2856 GEOSGeometry** geos_geoms = palloc(nelems *
sizeof(GEOSGeometry*));
2858 iterator = array_create_iterator(array, 0, NULL);
2860 while(array_iterate(iterator, &
value, &isnull))
2873 lwpgerror(
"Geometry could not be converted to GEOS");
2875 for (j = 0; j < i; j++) {
2876 GEOSGeom_destroy(geos_geoms[j]);
2889 for (j = 0; j <= i; j++) {
2890 GEOSGeom_destroy(geos_geoms[j]);
2899 array_free_iterator(iterator);
2907 GEOSGeometry *geosgeom;
2912 geom = PG_GETARG_GSERIALIZED_P(0);
2914 if ( ! geosgeom ) PG_RETURN_NULL();
2917 GEOSGeom_destroy(geosgeom);
2919 PG_FREE_IF_COPY(geom, 0);
2921 PG_RETURN_POINTER(lwgeom_result);
2931 GEOSGeometry *geos_result;
2932 const GEOSGeometry **vgeoms;
2934 #if POSTGIS_DEBUG_LEVEL >= 3
2938 #if POSTGIS_DEBUG_LEVEL >= 3
2942 if (PG_ARGISNULL(0))
2945 array = PG_GETARG_ARRAYTYPE_P(0);
2951 POSTGIS_DEBUGF(3,
"polygonize_garray: number of non-null elements: %d", nelems);
2956 vgeoms = (
const GEOSGeometry**)
ARRAY2GEOS(array, nelems, &is3d, &srid);
2958 POSTGIS_DEBUG(3,
"polygonize_garray: invoking GEOSpolygonize");
2960 geos_result = GEOSPolygonize(vgeoms, nelems);
2962 POSTGIS_DEBUG(3,
"polygonize_garray: GEOSpolygonize returned");
2964 for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
2967 if ( ! geos_result ) PG_RETURN_NULL();
2969 GEOSSetSRID(geos_result, srid);
2971 GEOSGeom_destroy(geos_result);
2974 elog(ERROR,
"%s returned an error", __func__);
2978 PG_RETURN_POINTER(
result);
2985 Datum* result_array_data;
2986 ArrayType *array, *
result;
2988 uint32 nelems, nclusters, i;
2989 GEOSGeometry **geos_inputs, **geos_results;
2998 if (PG_ARGISNULL(0))
3001 array = PG_GETARG_ARRAYTYPE_P(0);
3004 POSTGIS_DEBUGF(3,
"clusterintersecting_garray: number of non-null elements: %d", nelems);
3006 if ( nelems == 0 ) PG_RETURN_NULL();
3013 geos_inputs =
ARRAY2GEOS(array, nelems, &is3d, &srid);
3021 elog(ERROR,
"clusterintersecting: Error performing clustering");
3026 if (!geos_results) PG_RETURN_NULL();
3028 result_array_data = palloc(nclusters *
sizeof(Datum));
3029 for (i=0; i<nclusters; ++i)
3031 result_array_data[i] = PointerGetDatum(
GEOS2POSTGIS(geos_results[i], is3d));
3032 GEOSGeom_destroy(geos_results[i]);
3036 get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3037 result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3041 elog(ERROR,
"clusterintersecting: Error constructing return-array");
3045 PG_RETURN_POINTER(
result);
3051 Datum* result_array_data;
3052 ArrayType *array, *
result;
3054 uint32 nelems, nclusters, i;
3066 if (PG_ARGISNULL(0))
3069 array = PG_GETARG_ARRAYTYPE_P(0);
3071 tolerance = PG_GETARG_FLOAT8(1);
3074 lwpgerror(
"Tolerance must be a positive number.");
3080 POSTGIS_DEBUGF(3,
"cluster_within_distance_garray: number of non-null elements: %d", nelems);
3082 if ( nelems == 0 ) PG_RETURN_NULL();
3097 elog(ERROR,
"cluster_within: Error performing clustering");
3102 if (!lw_results) PG_RETURN_NULL();
3104 result_array_data = palloc(nclusters *
sizeof(Datum));
3105 for (i=0; i<nclusters; ++i)
3107 result_array_data[i] = PointerGetDatum(geometry_serialize(lw_results[i]));
3112 get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3113 result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3117 elog(ERROR,
"clusterwithin: Error constructing return-array");
3121 PG_RETURN_POINTER(
result);
3129 LWGEOM *lwgeom1, *lwresult ;
3131 geom1 = PG_GETARG_GSERIALIZED_P(0);
3137 result = geometry_serialize(lwresult) ;
3142 PG_FREE_IF_COPY(geom1, 0);
3144 PG_RETURN_POINTER(
result);
3159 LWGEOM *lwgeom_in, *lwgeom_out;
3161 geom = PG_GETARG_GSERIALIZED_P(0);
3169 PG_FREE_IF_COPY(geom, 0);
3173 result = geometry_serialize(lwgeom_out) ;
3176 PG_FREE_IF_COPY(geom, 0);
3177 PG_RETURN_POINTER(
result);
3189 LWGEOM *lwgeom_in, *lwgeom_out;
3190 double tolerance = 0.0;
3193 geom = PG_GETARG_GSERIALIZED_P(0);
3194 tolerance = PG_GETARG_FLOAT8(1);
3195 flags = PG_GETARG_INT32(2);
3203 PG_FREE_IF_COPY(geom, 0);
3207 result = geometry_serialize(lwgeom_out) ;
3210 PG_FREE_IF_COPY(geom, 0);
3211 PG_RETURN_POINTER(
result);
3219 Datum
ST_Snap(PG_FUNCTION_ARGS);
3224 LWGEOM *lwgeom1, *lwgeom2, *lwresult;
3227 geom1 = PG_GETARG_GSERIALIZED_P(0);
3228 geom2 = PG_GETARG_GSERIALIZED_P(1);
3229 tolerance = PG_GETARG_FLOAT8(2);
3234 lwresult =
lwgeom_snap(lwgeom1, lwgeom2, tolerance);
3237 PG_FREE_IF_COPY(geom1, 0);
3238 PG_FREE_IF_COPY(geom2, 1);
3240 result = geometry_serialize(lwresult);
3243 PG_RETURN_POINTER(
result);
3275 LWGEOM *lwgeom_in, *lwblade_in, *lwgeom_out;
3277 in = PG_GETARG_GSERIALIZED_P(0);
3278 blade_in = PG_GETARG_GSERIALIZED_P(1);
3286 lwpgerror(
"Input Geometry contains invalid coordinates");
3292 lwpgerror(
"Blade Geometry contains invalid coordinates");
3303 PG_FREE_IF_COPY(in, 0);
3304 PG_FREE_IF_COPY(blade_in, 1);
3308 out = geometry_serialize(lwgeom_out);
3310 PG_FREE_IF_COPY(in, 0);
3311 PG_FREE_IF_COPY(blade_in, 1);
3313 PG_RETURN_POINTER(out);
3336 LWGEOM *g1, *g2, *lwgeom_out;
3338 geom1 = PG_GETARG_GSERIALIZED_P(0);
3339 geom2 = PG_GETARG_GSERIALIZED_P(1);
3350 PG_FREE_IF_COPY(geom1, 0);
3351 PG_FREE_IF_COPY(geom2, 1);
3355 out = geometry_serialize(lwgeom_out);
3358 PG_FREE_IF_COPY(geom1, 0);
3359 PG_FREE_IF_COPY(geom2, 1);
3360 PG_RETURN_POINTER(out);
3372 Datum
ST_Node(PG_FUNCTION_ARGS);
3379 geom1 = PG_GETARG_GSERIALIZED_P(0);
3388 PG_FREE_IF_COPY(geom1, 0);
3392 out = geometry_serialize(lwgeom_out);
3395 PG_FREE_IF_COPY(geom1, 0);
3396 PG_RETURN_POINTER(out);
3418 int custom_clip_envelope;
3419 int return_polygons;
3422 if (PG_ARGISNULL(0))
3426 if (PG_ARGISNULL(2))
3428 lwpgerror(
"Tolerance must be a positive number.");
3432 tolerance = PG_GETARG_FLOAT8(2);
3436 lwpgerror(
"Tolerance must be a positive number.");
3441 if (PG_ARGISNULL(3))
3443 lwpgerror(
"return_polygons must be true or false.");
3446 return_polygons = PG_GETARG_BOOL(3);
3449 custom_clip_envelope = !PG_ARGISNULL(1);
3450 if (custom_clip_envelope) {
3451 clip = PG_GETARG_GSERIALIZED_P(1);
3454 lwpgerror(
"Could not determine envelope of clipping geometry.");
3455 PG_FREE_IF_COPY(clip, 1);
3458 PG_FREE_IF_COPY(clip, 1);
3462 input = PG_GETARG_GSERIALIZED_P(0);
3468 lwpgerror(
"Could not read input geometry.");
3469 PG_FREE_IF_COPY(input, 0);
3473 lwgeom_result =
lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3478 lwpgerror(
"Error computing Voronoi diagram.");
3479 PG_FREE_IF_COPY(input, 0);
3483 result = geometry_serialize(lwgeom_result);
3486 PG_FREE_IF_COPY(input, 0);
3487 PG_RETURN_POINTER(
result);
3502 GEOSGeometry* input_geos;
3508 input = PG_GETARG_GSERIALIZED_P(0);
3513 error = GEOSMinimumClearance(input_geos, &
result);
3514 GEOSGeom_destroy(input_geos);
3517 PG_FREE_IF_COPY(input, 0);
3518 PG_RETURN_FLOAT8(
result);
3534 GEOSGeometry* input_geos;
3535 GEOSGeometry* result_geos;
3540 input = PG_GETARG_GSERIALIZED_P(0);
3546 result_geos = GEOSMinimumClearanceLine(input_geos);
3547 GEOSGeom_destroy(input_geos);
3551 GEOSSetSRID(result_geos, srid);
3553 GEOSGeom_destroy(result_geos);
3555 PG_FREE_IF_COPY(input, 0);
3556 PG_RETURN_POINTER(
result);
3570 GEOSGeometry* input_geos;
3571 GEOSGeometry* result_geos;
3576 input = PG_GETARG_GSERIALIZED_P(0);
3582 result_geos = GEOSMinimumRotatedRectangle(input_geos);
3583 GEOSGeom_destroy(input_geos);
3587 GEOSSetSRID(result_geos, srid);
3589 GEOSGeom_destroy(result_geos);
3591 PG_FREE_IF_COPY(input, 0);
3592 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()