PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

908 {
909  GSERIALIZED *geom1;
910  GEOSGeometry *g1, *g3;
912  LWGEOM *lwout;
913  int32_t srid;
914  GBOX bbox;
915 
916  geom1 = PG_GETARG_GSERIALIZED_P(0);
917 
918  /* Empty.ConvexHull() == Empty */
919  if ( gserialized_is_empty(geom1) )
920  PG_RETURN_POINTER(geom1);
921 
922  srid = gserialized_get_srid(geom1);
923 
924  initGEOS(lwpgnotice, lwgeom_geos_error);
925 
926  g1 = POSTGIS2GEOS(geom1);
927 
928  if (!g1)
929  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
930 
931  g3 = GEOSConvexHull(g1);
932  GEOSGeom_destroy(g1);
933 
934  if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
935 
936  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
937 
938  GEOSSetSRID(g3, srid);
939 
940  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
941  GEOSGeom_destroy(g3);
942 
943  if (!lwout)
944  {
945  elog(ERROR,
946  "convexhull() failed to convert GEOS geometry to LWGEOM");
947  PG_RETURN_NULL(); /* never get here */
948  }
949 
950  /* Copy input bbox if any */
951  if ( gserialized_get_gbox_p(geom1, &bbox) )
952  {
953  /* Force the box to have the same dimensionality as the lwgeom */
954  bbox.flags = lwout->flags;
955  lwout->bbox = gbox_copy(&bbox);
956  }
957 
958  result = geometry_serialize(lwout);
959  lwgeom_free(lwout);
960 
961  if (!result)
962  {
963  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
964  PG_RETURN_NULL(); /* never get here */
965  }
966 
967  PG_FREE_IF_COPY(geom1, 0);
968  PG_RETURN_POINTER(result);
969 }
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: