PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

759 {
760  GSERIALIZED *geom1;
761  GEOSGeometry *g1, *g3;
763  LWGEOM *lwout;
764  int32_t srid;
765  GBOX bbox;
766 
767  geom1 = PG_GETARG_GSERIALIZED_P(0);
768 
769  /* Empty.ConvexHull() == Empty */
770  if ( gserialized_is_empty(geom1) )
771  PG_RETURN_POINTER(geom1);
772 
773  srid = gserialized_get_srid(geom1);
774 
775  initGEOS(lwpgnotice, lwgeom_geos_error);
776 
777  g1 = POSTGIS2GEOS(geom1);
778 
779  if (!g1)
780  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
781 
782  g3 = GEOSConvexHull(g1);
783  GEOSGeom_destroy(g1);
784 
785  if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
786 
787  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
788 
789  GEOSSetSRID(g3, srid);
790 
791  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
792  GEOSGeom_destroy(g3);
793 
794  if (!lwout)
795  {
796  elog(ERROR,
797  "convexhull() failed to convert GEOS geometry to LWGEOM");
798  PG_RETURN_NULL(); /* never get here */
799  }
800 
801  /* Copy input bbox if any */
802  if ( gserialized_get_gbox_p(geom1, &bbox) )
803  {
804  /* Force the box to have the same dimensionality as the lwgeom */
805  bbox.flags = lwout->flags;
806  lwout->bbox = gbox_copy(&bbox);
807  }
808 
809  result = geometry_serialize(lwout);
810  lwgeom_free(lwout);
811 
812  if (!result)
813  {
814  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
815  PG_RETURN_NULL(); /* never get here */
816  }
817 
818  PG_FREE_IF_COPY(geom1, 0);
819  PG_RETURN_POINTER(result);
820 }
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:1155
#define HANDLE_GEOS_ERROR(label)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
lwflags_t flags
Definition: liblwgeom.h:368
GBOX * bbox
Definition: liblwgeom.h:473
lwflags_t flags
Definition: liblwgeom.h:476

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: