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

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

814{
815 GSERIALIZED *geom1;
816 GEOSGeometry *g1, *g3;
818 LWGEOM *lwout;
819 int32_t srid;
820 GBOX bbox;
821
822 geom1 = PG_GETARG_GSERIALIZED_P(0);
823
824 /* Empty.ConvexHull() == Empty */
825 if ( gserialized_is_empty(geom1) )
826 PG_RETURN_POINTER(geom1);
827
828 srid = gserialized_get_srid(geom1);
829
830 initGEOS(lwpgnotice, lwgeom_geos_error);
831
832 g1 = POSTGIS2GEOS(geom1);
833
834 if (!g1)
835 HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
836
837 g3 = GEOSConvexHull(g1);
838 GEOSGeom_destroy(g1);
839
840 if (!g3) HANDLE_GEOS_ERROR("GEOSConvexHull");
841
842 POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
843
844 GEOSSetSRID(g3, srid);
845
846 lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
847 GEOSGeom_destroy(g3);
848
849 if (!lwout)
850 {
851 elog(ERROR,
852 "convexhull() failed to convert GEOS geometry to LWGEOM");
853 PG_RETURN_NULL(); /* never get here */
854 }
855
856 /* Copy input bbox if any */
857 if ( gserialized_get_gbox_p(geom1, &bbox) )
858 {
859 /* Force the box to have the same dimensionality as the lwgeom */
860 bbox.flags = lwout->flags;
861 lwout->bbox = gbox_copy(&bbox);
862 }
863
864 result = geometry_serialize(lwout);
865 lwgeom_free(lwout);
866
867 if (!result)
868 {
869 elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
870 PG_RETURN_NULL(); /* never get here */
871 }
872
873 PG_FREE_IF_COPY(geom1, 0);
874 PG_RETURN_POINTER(result);
875}
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:438
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:94
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.
void lwgeom_geos_error(const char *fmt,...)
void(*) LWGEOM GEOS2LWGEOM)(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
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(), 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: