PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

973 {
974  GSERIALIZED *gs1;
975  LWGEOM *lwg1;
976  double tolerance;
977  GEOSGeometry *g1, *g3;
979  uint32_t type;
980 
981  gs1 = PG_GETARG_GSERIALIZED_P(0);
982  tolerance = PG_GETARG_FLOAT8(1);
983  lwg1 = lwgeom_from_gserialized(gs1);
984 
985  /* Empty.Simplify() == Empty */
986  type = lwgeom_get_type(lwg1);
987  if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
988  PG_RETURN_POINTER(gs1);
989 
990  if (!lwgeom_isfinite(lwg1))
991  {
992  lwpgerror("Geometry contains invalid coordinates");
993  PG_RETURN_NULL();
994  }
995 
996  initGEOS(lwpgnotice, lwgeom_geos_error);
997 
998  g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
999  lwgeom_free(lwg1);
1000  if (!g1)
1001  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1002 
1003  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
1004  GEOSGeom_destroy(g1);
1005 
1006  if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
1007 
1008  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
1009 
1010  GEOSSetSRID(g3, gserialized_get_srid(gs1));
1011 
1013  GEOSGeom_destroy(g3);
1014 
1015  if (!result)
1016  {
1017  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
1018  PG_RETURN_NULL(); /* never get here */
1019  }
1020 
1021  PG_FREE_IF_COPY(gs1, 0);
1022  PG_RETURN_POINTER(result);
1023 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
Definition: gserialized.c:174
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition: lwgeom.c:2540
#define TINTYPE
Definition: liblwgeom.h:130
#define TRIANGLETYPE
Definition: liblwgeom.h:129
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwinline.h:145
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
type
Definition: ovdump.py:42
#define HANDLE_GEOS_ERROR(label)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)

References GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), HANDLE_GEOS_ERROR, LW_TRUE, LWGEOM2GEOS(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_geos_error(), lwgeom_get_type(), lwgeom_is_empty(), lwgeom_isfinite(), result, TINTYPE, TRIANGLETYPE, and ovdump::type.

Here is the call graph for this function: