PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

881 {
882  GSERIALIZED *gs1;
883  LWGEOM *lwg1;
884  double tolerance;
885  GEOSGeometry *g1, *g3;
887  uint32_t type;
888 
889  gs1 = PG_GETARG_GSERIALIZED_P(0);
890  tolerance = PG_GETARG_FLOAT8(1);
891  lwg1 = lwgeom_from_gserialized(gs1);
892 
893  /* Empty.Simplify() == Empty */
894  type = lwgeom_get_type(lwg1);
895  if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
896  PG_RETURN_POINTER(gs1);
897 
898  if (!lwgeom_isfinite(lwg1))
899  {
900  lwpgerror("Geometry contains invalid coordinates");
901  PG_RETURN_NULL();
902  }
903 
904  initGEOS(lwpgnotice, lwgeom_geos_error);
905 
906  g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
907  lwgeom_free(lwg1);
908  if (!g1)
909  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
910 
911  g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
912  GEOSGeom_destroy(g1);
913 
914  if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
915 
916  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
917 
918  GEOSSetSRID(g3, gserialized_get_srid(gs1));
919 
921  GEOSGeom_destroy(g3);
922 
923  if (!result)
924  {
925  elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
926  PG_RETURN_NULL(); /* never get here */
927  }
928 
929  PG_FREE_IF_COPY(gs1, 0);
930  PG_RETURN_POINTER(result);
931 }
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:1155
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition: lwgeom.c:2707
#define TINTYPE
Definition: liblwgeom.h:131
#define TRIANGLETYPE
Definition: liblwgeom.h:130
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
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: