PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum convexhull ( PG_FUNCTION_ARGS  )

Definition at line 702 of file postgis/lwgeom_geos.c.

References LWGEOM::bbox, GBOX::flags, LWGEOM::flags, gbox_copy(), geometry_serialize(), GEOS2LWGEOM(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_has_z(), gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_free(), lwgeom_geos_error(), and POSTGIS2GEOS().

703 {
704  GSERIALIZED *geom1;
705  GEOSGeometry *g1, *g3;
706  GSERIALIZED *result;
707  LWGEOM *lwout;
708  int srid;
709  GBOX bbox;
710 
711  geom1 = PG_GETARG_GSERIALIZED_P(0);
712 
713  /* Empty.ConvexHull() == Empty */
714  if ( gserialized_is_empty(geom1) )
715  PG_RETURN_POINTER(geom1);
716 
717  srid = gserialized_get_srid(geom1);
718 
719  initGEOS(lwpgnotice, lwgeom_geos_error);
720 
721  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
722 
723  if (!g1)
724  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
725 
726  g3 = (GEOSGeometry *)GEOSConvexHull(g1);
727  GEOSGeom_destroy(g1);
728 
729  if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
730 
731  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
732 
733  GEOSSetSRID(g3, srid);
734 
735  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
736  GEOSGeom_destroy(g3);
737 
738  if (!lwout)
739  {
740  elog(ERROR,
741  "convexhull() failed to convert GEOS geometry to LWGEOM");
742  PG_RETURN_NULL(); /* never get here */
743  }
744 
745  /* Copy input bbox if any */
746  if ( gserialized_get_gbox_p(geom1, &bbox) )
747  {
748  /* Force the box to have the same dimensionality as the lwgeom */
749  bbox.flags = lwout->flags;
750  lwout->bbox = gbox_copy(&bbox);
751  }
752 
753  result = geometry_serialize(lwout);
754  lwgeom_free(lwout);
755 
756  if (!result)
757  {
758  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
759  PG_RETURN_NULL(); /* never get here */
760  }
761 
762  PG_FREE_IF_COPY(geom1, 0);
763  PG_RETURN_POINTER(result);
764 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:639
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
GBOX * bbox
Definition: liblwgeom.h:397
uint8_t flags
Definition: liblwgeom.h:396
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
void lwgeom_geos_error(const char *fmt,...)
uint8_t flags
Definition: liblwgeom.h:290
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:99

Here is the call graph for this function: