PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ convexhull()

Datum convexhull ( PG_FUNCTION_ARGS  )

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

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(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), and topologypreservesimplify().

Referenced by boundary().

729 {
730  GSERIALIZED *geom1;
731  GEOSGeometry *g1, *g3;
732  GSERIALIZED *result;
733  LWGEOM *lwout;
734  int srid;
735  GBOX bbox;
736 
737  geom1 = PG_GETARG_GSERIALIZED_P(0);
738 
739  /* Empty.ConvexHull() == Empty */
740  if ( gserialized_is_empty(geom1) )
741  PG_RETURN_POINTER(geom1);
742 
743  srid = gserialized_get_srid(geom1);
744 
745  initGEOS(lwpgnotice, lwgeom_geos_error);
746 
747  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
748 
749  if ( 0 == g1 ) /* exception thrown at construction */
750  {
751  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
752  PG_RETURN_NULL();
753  }
754 
755  g3 = (GEOSGeometry *)GEOSConvexHull(g1);
756  GEOSGeom_destroy(g1);
757 
758  if (g3 == NULL)
759  {
760  HANDLE_GEOS_ERROR("GEOSConvexHull");
761  PG_RETURN_NULL(); /* never get here */
762  }
763 
764  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
765 
766  GEOSSetSRID(g3, srid);
767 
768  lwout = GEOS2LWGEOM(g3, gserialized_has_z(geom1));
769  GEOSGeom_destroy(g3);
770 
771  if (lwout == NULL)
772  {
773  elog(ERROR,"convexhull() failed to convert GEOS geometry to LWGEOM");
774  PG_RETURN_NULL(); /* never get here */
775  }
776 
777  /* Copy input bbox if any */
778  if ( gserialized_get_gbox_p(geom1, &bbox) )
779  {
780  /* Force the box to have the same dimensionality as the lwgeom */
781  bbox.flags = lwout->flags;
782  lwout->bbox = gbox_copy(&bbox);
783  }
784 
785  result = geometry_serialize(lwout);
786  lwgeom_free(lwout);
787 
788  if (result == NULL)
789  {
790  elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
791  PG_RETURN_NULL(); /* never get here */
792  }
793 
794  PG_FREE_IF_COPY(geom1, 0);
795  PG_RETURN_POINTER(result);
796 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:642
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
GBOX * bbox
Definition: liblwgeom.h:398
uint8_t flags
Definition: liblwgeom.h:397
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
void lwgeom_geos_error(const char *fmt,...)
uint8_t flags
Definition: liblwgeom.h:291
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
Here is the call graph for this function:
Here is the caller graph for this function: