392{
393#if POSTGIS_GEOS_VERSION < 30900
394
395 lwpgerror("The GEOS version this PostGIS binary "
396 "was compiled against (%d) doesn't support "
397 "'GEOSMaximumInscribedCircle' function (3.9.0+ required)",
399 PG_RETURN_NULL();
400
401#else
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;
414
415 if (PG_ARGISNULL(0))
416 PG_RETURN_NULL();
417
418 geom = PG_GETARG_GSERIALIZED_P(0);
419 tolerance = PG_GETARG_FLOAT8(1);
420 boundary = PG_GETARG_GSERIALIZED_P(2);
423
425 hasBoundary = true;
426
427
429 {
432 center = geometry_serialize(lwcenter);
433 nearest = geometry_serialize(lwnearest);
434 radius = 0.0;
435 }
436 else
437 {
438 GEOSGeometry *ginput, *gcircle, *gcenter, *gnearest;
439 GEOSGeometry *gboundary = NULL;
440 double width, height, size;
445 {
446 lwpgerror("Geometry contains invalid coordinates");
447 PG_RETURN_NULL();
448 }
450
451
453 PG_RETURN_NULL();
454
455 if (tolerance <= 0)
456 {
459 size = width > height ? width : height;
460 tolerance = size / 1000.0;
461 }
462
464
466 if (!ginput)
468
469 if (hasBoundary)
470 {
472 if (!gboundary)
474 }
475
476 gcircle = GEOSLargestEmptyCircle(ginput, gboundary, tolerance);
477 if (!gcircle)
478 {
479 lwpgerror("Error calculating GEOSLargestEmptyCircle.");
480 GEOSGeom_destroy(ginput);
481 PG_RETURN_NULL();
482 }
483
484 gcenter = GEOSGeomGetStartPoint(gcircle);
485 gnearest = GEOSGeomGetEndPoint(gcircle);
486 GEOSDistance(gcenter, gnearest, &radius);
487 GEOSSetSRID(gcenter, srid);
488 GEOSSetSRID(gnearest, srid);
489
492 GEOSGeom_destroy(gcenter);
493 GEOSGeom_destroy(gnearest);
494 GEOSGeom_destroy(gcircle);
495 GEOSGeom_destroy(ginput);
496 if (gboundary) GEOSGeom_destroy(gboundary);
497 }
498
499 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
500 BlessTupleDesc(resultTupleDesc);
501
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);
509
510 result = HeapTupleGetDatum(resultTuple);
511
513
514#endif
515}
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)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
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,...)
void lwgeom_free(LWGEOM *geom)
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
#define SRID_UNKNOWN
Unknown SRID value.
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
Datum boundary(PG_FUNCTION_ARGS)
#define HANDLE_GEOS_ERROR(label)
#define POSTGIS_GEOS_VERSION