393 #if POSTGIS_GEOS_VERSION < 30900
395 lwpgerror(
"The GEOS version this PostGIS binary "
396 "was compiled against (%d) doesn't support "
397 "'GEOSMaximumInscribedCircle' function (3.9.0+ required)",
406 TupleDesc resultTupleDesc;
407 HeapTuple resultTuple;
409 Datum result_values[3];
410 bool result_is_null[3];
411 double radius = 0.0, tolerance = 0.0;
413 bool is3d =
false, hasBoundary =
false;
418 geom = PG_GETARG_GSERIALIZED_P(0);
419 tolerance = PG_GETARG_FLOAT8(1);
420 boundary = PG_GETARG_GSERIALIZED_P(2);
432 center = geometry_serialize(lwcenter);
433 nearest = geometry_serialize(lwnearest);
438 GEOSGeometry *ginput, *gcircle, *gcenter, *gnearest;
439 GEOSGeometry *gboundary = NULL;
440 double width, height, size;
446 lwpgerror(
"Geometry contains invalid coordinates");
459 size = width > height ? width : height;
460 tolerance = size / 1000.0;
476 gcircle = GEOSLargestEmptyCircle(ginput, gboundary, tolerance);
479 lwpgerror(
"Error calculating GEOSLargestEmptyCircle.");
480 GEOSGeom_destroy(ginput);
484 gcenter = GEOSGeomGetStartPoint(gcircle);
485 gnearest = GEOSGeomGetEndPoint(gcircle);
486 GEOSDistance(gcenter, gnearest, &radius);
487 GEOSSetSRID(gcenter, srid);
488 GEOSSetSRID(gnearest, srid);
492 GEOSGeom_destroy(gcenter);
493 GEOSGeom_destroy(gnearest);
494 GEOSGeom_destroy(gcircle);
495 GEOSGeom_destroy(ginput);
496 if (gboundary) GEOSGeom_destroy(gboundary);
499 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
500 BlessTupleDesc(resultTupleDesc);
502 result_values[0] = PointerGetDatum(center);
503 result_is_null[0] =
false;
504 result_values[1] = PointerGetDatum(nearest);
505 result_is_null[1] =
false;
506 result_values[2] = Float8GetDatum(radius);
507 result_is_null[2] =
false;
508 resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
510 result = HeapTupleGetDatum(resultTuple);
char result[OUT_DOUBLE_BUFFER_SIZE]
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.
void lwgeom_geos_error(const char *fmt,...)
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
void lwgeom_free(LWGEOM *geom)
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
#define SRID_UNKNOWN
Unknown SRID value.
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
Datum boundary(PG_FUNCTION_ARGS)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
#define POSTGIS_GEOS_VERSION