463 #if POSTGIS_GEOS_VERSION < 30900
465 lwpgerror(
"The GEOS version this PostGIS binary "
466 "was compiled against (%d) doesn't support "
467 "'GEOSMaximumInscribedCircle' function (3.9.0+ required)",
476 TupleDesc resultTupleDesc;
477 HeapTuple resultTuple;
479 Datum result_values[3];
480 bool result_is_null[3];
481 double radius = 0.0, tolerance = 0.0;
483 bool is3d =
false, hasBoundary =
false;
488 geom = PG_GETARG_GSERIALIZED_P(0);
489 tolerance = PG_GETARG_FLOAT8(1);
490 boundary = PG_GETARG_GSERIALIZED_P(2);
502 center = geometry_serialize(lwcenter);
503 nearest = geometry_serialize(lwnearest);
508 GEOSGeometry *ginput, *gcircle, *gcenter, *gnearest;
509 GEOSGeometry *gboundary = NULL;
510 double width, height, size;
516 lwpgerror(
"Geometry contains invalid coordinates");
529 size = width > height ? width : height;
530 tolerance = size / 1000.0;
546 gcircle = GEOSLargestEmptyCircle(ginput, gboundary, tolerance);
549 lwpgerror(
"Error calculating GEOSLargestEmptyCircle.");
550 GEOSGeom_destroy(ginput);
554 gcenter = GEOSGeomGetStartPoint(gcircle);
555 gnearest = GEOSGeomGetEndPoint(gcircle);
556 GEOSDistance(gcenter, gnearest, &radius);
557 GEOSSetSRID(gcenter, srid);
558 GEOSSetSRID(gnearest, srid);
562 GEOSGeom_destroy(gcenter);
563 GEOSGeom_destroy(gnearest);
564 GEOSGeom_destroy(gcircle);
565 GEOSGeom_destroy(ginput);
566 if (gboundary) GEOSGeom_destroy(gboundary);
569 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
570 BlessTupleDesc(resultTupleDesc);
572 result_values[0] = PointerGetDatum(center);
573 result_is_null[0] =
false;
574 result_values[1] = PointerGetDatum(nearest);
575 result_is_null[1] =
false;
576 result_values[2] = Float8GetDatum(radius);
577 result_is_null[2] =
false;
578 resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
580 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