From dd806106e13f05e08479124e8c6d349d3fca114e Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Sat, 14 Sep 2019 19:04:46 +0000 Subject: [PATCH] Use GEOSMakeValid and GEOSBuildArea for GEOS 3.8+ Fixes #4507 Closes https://github.com/postgis/postgis/pull/477 git-svn-id: http://svn.osgeo.org/postgis/trunk@17810 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + liblwgeom/lwgeom_geos.c | 7 ++++++- liblwgeom/lwgeom_geos.h | 2 ++ liblwgeom/lwgeom_geos_clean.c | 9 +++++++++ postgis/mvt.c | 5 +++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 1d67b5ff4..acaabc9cf 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12 - #4501, Allow postgis_tiger_geocoder to be installable by non-super users (Regina Obe) - #4503, Speed up the calculation of cartesian bbox (Raúl Marín) - #4504, shp2pgsql -D not working with schema qualified tables + - #4507, Use GEOSMakeValid and GEOSBuildArea for GEOS 3.8+ (Dan Baston) PostGIS 3.0.0alpha4 2019/08/10 diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index de6c7f1e2..6b2914d40 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -919,7 +919,7 @@ lwgeom_clip_by_rect(const LWGEOM *geom1, double x1, double y1, double x2, double } /* ------------ BuildArea stuff ---------------------------------------------------------------------{ */ - +#if POSTGIS_GEOS_VERSION < 38 typedef struct Face_t { const GEOSGeometry* geom; @@ -1165,6 +1165,7 @@ LWGEOM_GEOS_buildArea(const GEOSGeometry* geom_in) return shp; } +#endif LWGEOM* lwgeom_buildarea(const LWGEOM* geom) @@ -1183,7 +1184,11 @@ lwgeom_buildarea(const LWGEOM* geom) if (!(g1 = LWGEOM2GEOS(geom, AUTOFIX))) GEOS_FAIL(); +#if POSTGIS_GEOS_VERSION < 38 g3 = LWGEOM_GEOS_buildArea(g1); +#else + g3 = GEOSBuildArea(g1); +#endif if (!g3) GEOS_FREE_AND_FAIL(g1); GEOSSetSRID(g3, srid); diff --git a/liblwgeom/lwgeom_geos.h b/liblwgeom/lwgeom_geos.h index 9845cff11..ae21aef79 100644 --- a/liblwgeom/lwgeom_geos.h +++ b/liblwgeom/lwgeom_geos.h @@ -34,8 +34,10 @@ LWGEOM* GEOS2LWGEOM(const GEOSGeometry* geom, uint8_t want3d); GEOSGeometry* LWGEOM2GEOS(const LWGEOM* g, uint8_t autofix); GEOSGeometry* GBOX2GEOS(const GBOX* g); +#if POSTGIS_GEOS_VERSION < 38 GEOSGeometry* LWGEOM_GEOS_buildArea(const GEOSGeometry* geom_in); GEOSGeometry* LWGEOM_GEOS_makeValid(const GEOSGeometry*); +#endif GEOSGeometry* make_geos_point(double x, double y); GEOSGeometry* make_geos_segment(double x1, double y1, double x2, double y2); diff --git a/liblwgeom/lwgeom_geos_clean.c b/liblwgeom/lwgeom_geos_clean.c index 7cc9c76d5..9ef310875 100644 --- a/liblwgeom/lwgeom_geos_clean.c +++ b/liblwgeom/lwgeom_geos_clean.c @@ -35,6 +35,7 @@ /* #define PARANOIA_LEVEL 2 */ #undef LWGEOM_PROFILE_MAKEVALID +#if POSTGIS_GEOS_VERSION < 38 /* * Return Nth vertex in GEOSGeometry as a POINT. * May return NULL if the geometry has NO vertex. @@ -108,6 +109,7 @@ LWGEOM_GEOS_getPointN(const GEOSGeometry* g_in, uint32_t n) return GEOSGeom_createPoint(seq_out); } +#endif LWGEOM* lwcollection_make_geos_friendly(LWCOLLECTION* g); LWGEOM* lwline_make_geos_friendly(LWLINE* line); @@ -314,6 +316,8 @@ lwcollection_make_geos_friendly(LWCOLLECTION* g) return (LWGEOM*)ret; } +#if POSTGIS_GEOS_VERSION < 38 + /* * Fully node given linework */ @@ -843,6 +847,7 @@ LWGEOM_GEOS_makeValid(const GEOSGeometry* gin) return gout; } +#endif /* Exported. Uses GEOS internally */ LWGEOM* @@ -889,7 +894,11 @@ lwgeom_make_valid(LWGEOM* lwgeom_in) lwgeom_out = lwgeom_in; } +#if POSTGIS_GEOS_VERSION < 38 geosout = LWGEOM_GEOS_makeValid(geosgeom); +#else + geosout = GEOSMakeValid(geosgeom); +#endif GEOSGeom_destroy(geosgeom); if (!geosout) return NULL; diff --git a/postgis/mvt.c b/postgis/mvt.c index 495e64359..e1fc08540 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -1050,7 +1050,12 @@ mvt_grid_and_validate_geos(LWGEOM *ng, uint8_t basic_type) while (!valid && iterations < max_iterations) { +#if POSTGIS_GEOS_VERSION < 38 GEOSGeometry *geo_valid = LWGEOM_GEOS_makeValid(geo); +#else + GEOSGeometry *geo_valid = GEOSMakeValid(geo); +#endif + GEOSGeom_destroy(geo); if (!geo_valid) return NULL; -- 2.50.0