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

Definition at line 653 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().

654 {
655  GSERIALIZED *geom1;
656  GEOSGeometry *g1, *g3;
657  GSERIALIZED *result;
658  LWGEOM *lwout;
659  int srid;
660  GBOX bbox;
661 
662  geom1 = PG_GETARG_GSERIALIZED_P(0);
663 
664  /* Empty.ConvexHull() == Empty */
665  if ( gserialized_is_empty(geom1) )
666  PG_RETURN_POINTER(geom1);
667 
668  srid = gserialized_get_srid(geom1);
669 
670  initGEOS(lwpgnotice, lwgeom_geos_error);
671 
672  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
673 
674  if ( 0 == g1 ) /* exception thrown at construction */
675  {
676  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
677  PG_RETURN_NULL();
678  }
679 
680  g3 = (GEOSGeometry *)GEOSConvexHull(g1);
681  GEOSGeom_destroy(g1);
682 
683  if (g3 == NULL)
684  {
685  HANDLE_GEOS_ERROR("GEOSConvexHull");
686  PG_RETURN_NULL(); /* never get here */
687  }
688 
689  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
690 
691  GEOSSetSRID(g3, srid);
692 
693  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
694  GEOSGeom_destroy(g3);
695 
696  if (lwout == NULL)
697  {
698  elog(ERROR,"convexhull() failed to convert GEOS geometry to LWGEOM");
699  PG_RETURN_NULL(); /* never get here */
700  }
701 
702  /* Copy input bbox if any */
703  if ( gserialized_get_gbox_p(geom1, &bbox) )
704  {
705  /* Force the box to have the same dimensionality as the lwgeom */
706  bbox.flags = lwout->flags;
707  lwout->bbox = gbox_copy(&bbox);
708  }
709 
710  result = geometry_serialize(lwout);
711  lwgeom_free(lwout);
712 
713  if (result == NULL)
714  {
715  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
716  PG_RETURN_NULL(); /* never get here */
717  }
718 
719  PG_FREE_IF_COPY(geom1, 0);
720  PG_RETURN_POINTER(result);
721 }
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:398
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
GBOX * bbox
Definition: liblwgeom.h:397
uint8_t flags
Definition: liblwgeom.h:396
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:38
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
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:83

Here is the call graph for this function: