PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

936{
937 GSERIALIZED *gs1;
938 LWGEOM *lwg1;
939 double tolerance;
940 GEOSGeometry *g1, *g3;
942 uint32_t type;
943
944 gs1 = PG_GETARG_GSERIALIZED_P(0);
945 tolerance = PG_GETARG_FLOAT8(1);
946 lwg1 = lwgeom_from_gserialized(gs1);
947
948 /* Empty.Simplify() == Empty */
949 type = lwgeom_get_type(lwg1);
950 if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
951 PG_RETURN_POINTER(gs1);
952
953 if (!lwgeom_isfinite(lwg1))
954 {
955 lwpgerror("Geometry contains invalid coordinates");
956 PG_RETURN_NULL();
957 }
958
959 initGEOS(lwpgnotice, lwgeom_geos_error);
960
961 g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
962 lwgeom_free(lwg1);
963 if (!g1)
964 HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
965
966 g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
967 GEOSGeom_destroy(g1);
968
969 if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
970
971 POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
972
973 GEOSSetSRID(g3, gserialized_get_srid(gs1));
974
976 GEOSGeom_destroy(g3);
977
978 if (!result)
979 {
980 elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
981 PG_RETURN_NULL(); /* never get here */
982 }
983
984 PG_FREE_IF_COPY(gs1, 0);
985 PG_RETURN_POINTER(result);
986}
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)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition lwgeom.c:2835
#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:141
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:199
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, and TRIANGLETYPE.

Here is the call graph for this function: