PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

687 {
688  GSERIALIZED *geom1;
689  GEOSGeometry *g1, *g3;
690  GSERIALIZED *result;
691  LWGEOM *lwout;
692  int srid;
693  GBOX bbox;
694 
695  geom1 = PG_GETARG_GSERIALIZED_P(0);
696 
697  /* Empty.ConvexHull() == Empty */
698  if ( gserialized_is_empty(geom1) )
699  PG_RETURN_POINTER(geom1);
700 
701  srid = gserialized_get_srid(geom1);
702 
703  initGEOS(lwpgnotice, lwgeom_geos_error);
704 
705  g1 = POSTGIS2GEOS(geom1);
706 
707  if (!g1)
708  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
709 
710  g3 = GEOSConvexHull(g1);
711  GEOSGeom_destroy(g1);
712 
713  if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
714 
715  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
716 
717  GEOSSetSRID(g3, srid);
718 
719  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
720  GEOSGeom_destroy(g3);
721 
722  if (!lwout)
723  {
724  elog(ERROR,
725  "convexhull() failed to convert GEOS geometry to LWGEOM");
726  PG_RETURN_NULL(); /* never get here */
727  }
728 
729  /* Copy input bbox if any */
730  if ( gserialized_get_gbox_p(geom1, &bbox) )
731  {
732  /* Force the box to have the same dimensionality as the lwgeom */
733  bbox.flags = lwout->flags;
734  lwout->bbox = gbox_copy(&bbox);
735  }
736 
737  result = geometry_serialize(lwout);
738  lwgeom_free(lwout);
739 
740  if (!result)
741  {
742  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
743  PG_RETURN_NULL(); /* never get here */
744  }
745 
746  PG_FREE_IF_COPY(geom1, 0);
747  PG_RETURN_POINTER(result);
748 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
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:100
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:179
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:640
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define HANDLE_GEOS_ERROR(label)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t flags
Definition: liblwgeom.h:294
GBOX * bbox
Definition: liblwgeom.h:401
uint8_t flags
Definition: liblwgeom.h:400

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().

Here is the call graph for this function: