From 5b4a43633680e2de976d62b33d10690c3dcfa580 Mon Sep 17 00:00:00 2001 From: jpolchlo Date: Fri, 8 Oct 2021 10:42:22 -0400 Subject: [PATCH] Correct faulty input geometries --- .../org/globalforestwatch/features/SpatialFeatureDF.scala | 4 +++- version.sbt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/org/globalforestwatch/features/SpatialFeatureDF.scala b/src/main/scala/org/globalforestwatch/features/SpatialFeatureDF.scala index e001af6e..56eba1ae 100644 --- a/src/main/scala/org/globalforestwatch/features/SpatialFeatureDF.scala +++ b/src/main/scala/org/globalforestwatch/features/SpatialFeatureDF.scala @@ -48,9 +48,11 @@ object SpatialFeatureDF { FeatureDF(input, featureObj, filters, spark, delimiter) val emptyPolygonWKB = "0106000020E610000000000000" + // ST_PrecisionReduce may create invalid geometry if it contains a "sliver" that is below the precision threshold + // ST_Buffer(0) fixes these invalid geometries featureDF .selectExpr( - s"ST_PrecisionReduce(ST_GeomFromWKB(${wkbField}), 11) AS polyshape", + s"ST_Buffer(ST_PrecisionReduce(ST_GeomFromWKB(${wkbField}), 11), 0) AS polyshape", s"struct(${featureObj.featureIdExpr}) as featureId" ) .where(s"${wkbField} != '${emptyPolygonWKB}'") diff --git a/version.sbt b/version.sbt index 9246f2da..d6a2044d 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "1.7.6" +version in ThisBuild := "1.7.7"