PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

Definition at line 724 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().

725 {
726  GSERIALIZED *geom1;
727  double tolerance;
728  GEOSGeometry *g1, *g3;
729  GSERIALIZED *result;
730 
731  geom1 = PG_GETARG_GSERIALIZED_P(0);
732  tolerance = PG_GETARG_FLOAT8(1);
733 
734  /* Empty.Simplify() == Empty */
735  if ( gserialized_is_empty(geom1) )
736  PG_RETURN_POINTER(geom1);
737 
738  initGEOS(lwpgnotice, lwgeom_geos_error);
739 
740  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
741  if ( 0 == g1 ) /* exception thrown at construction */
742  {
743  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
744  PG_RETURN_NULL();
745  }
746 
747  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
748  GEOSGeom_destroy(g1);
749 
750  if (g3 == NULL)
751  {
752  HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
753  PG_RETURN_NULL(); /* never get here */
754  }
755 
756  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
757 
758  GEOSSetSRID(g3, gserialized_get_srid(geom1));
759 
760  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
761  GEOSGeom_destroy(g3);
762 
763  if (result == NULL)
764  {
765  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
766  PG_RETURN_NULL(); /* never get here */
767  }
768 
769  PG_FREE_IF_COPY(geom1, 0);
770  PG_RETURN_POINTER(result);
771 }
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:38
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
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:83
Here is the call graph for this function:
Here is the caller graph for this function: