PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

843 {
844  GSERIALIZED *geom1;
845  GEOSGeometry *g1, *g3;
847  LWGEOM *lwout;
848  int32_t srid;
849  GBOX bbox;
850 
851  geom1 = PG_GETARG_GSERIALIZED_P(0);
852 
853  /* Empty.ConvexHull() == Empty */
854  if ( gserialized_is_empty(geom1) )
855  PG_RETURN_POINTER(geom1);
856 
857  srid = gserialized_get_srid(geom1);
858 
859  initGEOS(lwpgnotice, lwgeom_geos_error);
860 
861  g1 = POSTGIS2GEOS(geom1);
862 
863  if (!g1)
864  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
865 
866  g3 = GEOSConvexHull(g1);
867  GEOSGeom_destroy(g1);
868 
869  if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
870 
871  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
872 
873  GEOSSetSRID(g3, srid);
874 
875  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
876  GEOSGeom_destroy(g3);
877 
878  if (!lwout)
879  {
880  elog(ERROR,
881  "convexhull() failed to convert GEOS geometry to LWGEOM");
882  PG_RETURN_NULL(); /* never get here */
883  }
884 
885  /* Copy input bbox if any */
886  if ( gserialized_get_gbox_p(geom1, &bbox) )
887  {
888  /* Force the box to have the same dimensionality as the lwgeom */
889  bbox.flags = lwout->flags;
890  lwout->bbox = gbox_copy(&bbox);
891  }
892 
893  result = geometry_serialize(lwout);
894  lwgeom_free(lwout);
895 
896  if (!result)
897  {
898  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
899  PG_RETURN_NULL(); /* never get here */
900  }
901 
902  PG_FREE_IF_COPY(geom1, 0);
903  PG_RETURN_POINTER(result);
904 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
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)...
Definition: gserialized.c:126
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
Definition: gserialized.c:65
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
Definition: gserialized.c:174
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define HANDLE_GEOS_ERROR(label)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
lwflags_t flags
Definition: liblwgeom.h:367
GBOX * bbox
Definition: liblwgeom.h:472
lwflags_t flags
Definition: liblwgeom.h:475

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

Here is the call graph for this function: