PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

998 {
999  GSERIALIZED *gs1;
1000  LWGEOM *lwg1;
1001  double tolerance;
1002  GEOSGeometry *g1, *g3;
1004  uint32_t type;
1005 
1006  gs1 = PG_GETARG_GSERIALIZED_P(0);
1007  tolerance = PG_GETARG_FLOAT8(1);
1008  lwg1 = lwgeom_from_gserialized(gs1);
1009 
1010  /* Empty.Simplify() == Empty */
1011  type = lwgeom_get_type(lwg1);
1012  if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
1013  PG_RETURN_POINTER(gs1);
1014 
1015  if (!lwgeom_isfinite(lwg1))
1016  {
1017  lwpgerror("Geometry contains invalid coordinates");
1018  PG_RETURN_NULL();
1019  }
1020 
1021  initGEOS(lwpgnotice, lwgeom_geos_error);
1022 
1023  g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
1024  lwgeom_free(lwg1);
1025  if (!g1)
1026  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
1027 
1028  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
1029  GEOSGeom_destroy(g1);
1030 
1031  if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
1032 
1033  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
1034 
1035  GEOSSetSRID(g3, gserialized_get_srid(gs1));
1036 
1038  GEOSGeom_destroy(g3);
1039 
1040  if (!result)
1041  {
1042  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
1043  PG_RETURN_NULL(); /* never get here */
1044  }
1045 
1046  PG_FREE_IF_COPY(gs1, 0);
1047  PG_RETURN_POINTER(result);
1048 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:1155
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition: lwgeom.c:2681
#define TINTYPE
Definition: liblwgeom.h:116
#define TRIANGLETYPE
Definition: liblwgeom.h:115
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
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
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
#define HANDLE_GEOS_ERROR(label)

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: