PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

References buffer(), GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), and POSTGIS2GEOS().

Referenced by convexhull().

768 {
769  GSERIALIZED *geom1;
770  double tolerance;
771  GEOSGeometry *g1, *g3;
772  GSERIALIZED *result;
773 
774  geom1 = PG_GETARG_GSERIALIZED_P(0);
775  tolerance = PG_GETARG_FLOAT8(1);
776 
777  /* Empty.Simplify() == Empty */
778  if ( gserialized_is_empty(geom1) )
779  PG_RETURN_POINTER(geom1);
780 
781  initGEOS(lwpgnotice, lwgeom_geos_error);
782 
783  g1 = POSTGIS2GEOS(geom1);
784  if (!g1)
785  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
786 
787  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
788  GEOSGeom_destroy(g1);
789 
790  if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
791 
792  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
793 
794  GEOSSetSRID(g3, gserialized_get_srid(geom1));
795 
796  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
797  GEOSGeom_destroy(g3);
798 
799  if (!result)
800  {
801  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
802  PG_RETURN_NULL(); /* never get here */
803  }
804 
805  PG_FREE_IF_COPY(geom1, 0);
806  PG_RETURN_POINTER(result);
807 }
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:178
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom 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:99
Here is the call graph for this function:
Here is the caller graph for this function: