338 #if POSTGIS_GEOS_VERSION < 30900
340 lwpgerror(
"The GEOS version this PostGIS binary "
341 "was compiled against (%d) doesn't support "
342 "'GEOSMaximumInscribedCircle' function (3.9.0+ required)",
350 TupleDesc resultTupleDesc;
351 HeapTuple resultTuple;
353 Datum result_values[3];
354 bool result_is_null[3];
362 geom = PG_GETARG_GSERIALIZED_P(0);
371 center = geometry_serialize(lwcenter);
372 nearest = geometry_serialize(lwnearest);
377 GEOSGeometry *ginput, *gcircle, *gcenter, *gnearest;
378 double width, height, size, tolerance;
385 lwpgerror(
"Geometry contains invalid coordinates");
395 size = width > height ? width : height;
396 tolerance = size / 1000.0;
407 gcircle = GEOSMaximumInscribedCircle(ginput, tolerance);
410 lwpgerror(
"Error calculating GEOSMaximumInscribedCircle.");
411 GEOSGeom_destroy(ginput);
417 gcircle = GEOSLargestEmptyCircle(ginput, NULL, tolerance);
420 lwpgerror(
"Error calculating GEOSLargestEmptyCircle.");
421 GEOSGeom_destroy(ginput);
426 gcenter = GEOSGeomGetStartPoint(gcircle);
427 gnearest = GEOSGeomGetEndPoint(gcircle);
428 GEOSDistance(gcenter, gnearest, &radius);
429 GEOSSetSRID(gcenter, srid);
430 GEOSSetSRID(gnearest, srid);
434 GEOSGeom_destroy(gcenter);
435 GEOSGeom_destroy(gnearest);
436 GEOSGeom_destroy(gcircle);
437 GEOSGeom_destroy(ginput);
440 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
441 BlessTupleDesc(resultTupleDesc);
443 result_values[0] = PointerGetDatum(center);
444 result_is_null[0] =
false;
445 result_values[1] = PointerGetDatum(nearest);
446 result_is_null[1] =
false;
447 result_values[2] = Float8GetDatum(radius);
448 result_is_null[2] =
false;
449 resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
451 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.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
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)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
#define POSTGIS_GEOS_VERSION