PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

876 {
877  GSERIALIZED *geom1;
878  GEOSGeometry *g1, *g3;
880  LWGEOM *lwout;
881  int32_t srid;
882  GBOX bbox;
883 
884  geom1 = PG_GETARG_GSERIALIZED_P(0);
885 
886  /* Empty.ConvexHull() == Empty */
887  if ( gserialized_is_empty(geom1) )
888  PG_RETURN_POINTER(geom1);
889 
890  srid = gserialized_get_srid(geom1);
891 
892  initGEOS(lwpgnotice, lwgeom_geos_error);
893 
894  g1 = POSTGIS2GEOS(geom1);
895 
896  if (!g1)
897  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
898 
899  g3 = GEOSConvexHull(g1);
900  GEOSGeom_destroy(g1);
901 
902  if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
903 
904  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
905 
906  GEOSSetSRID(g3, srid);
907 
908  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
909  GEOSGeom_destroy(g3);
910 
911  if (!lwout)
912  {
913  elog(ERROR,
914  "convexhull() failed to convert GEOS geometry to LWGEOM");
915  PG_RETURN_NULL(); /* never get here */
916  }
917 
918  /* Copy input bbox if any */
919  if ( gserialized_get_gbox_p(geom1, &bbox) )
920  {
921  /* Force the box to have the same dimensionality as the lwgeom */
922  bbox.flags = lwout->flags;
923  lwout->bbox = gbox_copy(&bbox);
924  }
925 
926  result = geometry_serialize(lwout);
927  lwgeom_free(lwout);
928 
929  if (!result)
930  {
931  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
932  PG_RETURN_NULL(); /* never get here */
933  }
934 
935  PG_FREE_IF_COPY(geom1, 0);
936  PG_RETURN_POINTER(result);
937 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:1155
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
lwflags_t flags
Definition: liblwgeom.h:353
GBOX * bbox
Definition: liblwgeom.h:458
lwflags_t flags
Definition: liblwgeom.h:461

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: