PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

References GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), gserialized_is_empty(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), and result.

1047 {
1048  GSERIALIZED *geom1;
1049  double tolerance;
1050  GEOSGeometry *g1, *g3;
1052 
1053  geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1054  tolerance = PG_GETARG_FLOAT8(1);
1055 
1056  /* Empty.Simplify() == Empty */
1057  if ( gserialized_is_empty(geom1) )
1058  PG_RETURN_POINTER(geom1);
1059 
1060  initGEOS(lwnotice, lwgeom_geos_error);
1061 
1062  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
1063  if ( 0 == g1 ) /* exception thrown at construction */
1064  {
1065  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1066  PG_RETURN_NULL();
1067  }
1068 
1069  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
1070  GEOSGeom_destroy(g1);
1071 
1072  if (g3 == NULL)
1073  {
1074  lwerror("GEOSTopologyPreserveSimplify: %s", lwgeom_geos_errmsg);
1075  PG_RETURN_NULL(); /* never get here */
1076  }
1077 
1078  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
1079 
1080  GEOSSetSRID(g3, gserialized_get_srid(geom1));
1081 
1082  result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
1083  GEOSGeom_destroy(g3);
1084 
1085  if (result == NULL)
1086  {
1087  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
1088  PG_RETURN_NULL(); /* never get here */
1089  }
1090 
1091  PG_FREE_IF_COPY(geom1, 0);
1092  PG_RETURN_POINTER(result);
1093 }
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
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:70

Here is the call graph for this function: