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

◆ topologypreservesimplify()

Datum topologypreservesimplify ( PG_FUNCTION_ARGS  )

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

833{
834 GSERIALIZED *gs1;
835 LWGEOM *lwg1;
836 double tolerance;
837 GEOSGeometry *g1, *g3;
838 GSERIALIZED *result;
839 uint32_t type;
840
841 gs1 = PG_GETARG_GSERIALIZED_P(0);
842 tolerance = PG_GETARG_FLOAT8(1);
843 lwg1 = lwgeom_from_gserialized(gs1);
844
845 /* Empty.Simplify() == Empty */
846 type = lwgeom_get_type(lwg1);
847 if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
848 PG_RETURN_POINTER(gs1);
849
850 if (!lwgeom_isfinite(lwg1))
851 {
852 lwpgerror("Geometry contains invalid coordinates");
853 PG_RETURN_NULL();
854 }
855
856 initGEOS(lwpgnotice, lwgeom_geos_error);
857
858 g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
859 lwgeom_free(lwg1);
860 if (!g1)
861 HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
862
863 g3 = GEOSTopologyPreserveSimplify(g1,tolerance);
864 GEOSGeom_destroy(g1);
865
866 if (!g3) HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
867
868 POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
869
870 GEOSSetSRID(g3, gserialized_get_srid(gs1));
871
872 result = GEOS2POSTGIS(g3, gserialized_has_z(gs1));
873 GEOSGeom_destroy(g3);
874
875 if (!result)
876 {
877 elog(ERROR,"GEOS topologypreservesimplify() threw an error (result postgis geometry formation)!");
878 PG_RETURN_NULL(); /* never get here */
879 }
880
881 PG_FREE_IF_COPY(gs1, 0);
882 PG_RETURN_POINTER(result);
883}
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:1138
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition lwgeom.c:2529
#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:135
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:193
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(), TINTYPE, and TRIANGLETYPE.

Here is the call graph for this function: