PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

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

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().

Here is the call graph for this function: