Skip to content

Commit 36c46e1

Browse files
committed
Attempt to fix invalid way geometries
1 parent e5d7934 commit 36c46e1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Adds `riverbank`, `stream_end`, `dam`, `weir`, `waterfall`, and `pressurised`
2525
to the list of waterway features
2626
- Populates `nds` and `members` for deleted elements from the previous version
27+
- Attempt to fix invalid way geometries by buffering them (this will result in
28+
more way geometries for certain datasets)
2729

2830
### Fixed
2931

src/main/scala/vectorpipe/internal/package.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.sql.Timestamp
55
import org.locationtech.jts.{geom => jts}
66
import geotrellis.vector._
77
import org.apache.log4j.Logger
8+
import org.apache.spark.internal.Logging
89
import org.apache.spark.sql._
910
import org.apache.spark.sql.catalyst.encoders.RowEncoder
1011
import org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema
@@ -17,14 +18,12 @@ import vectorpipe.functions.asDouble
1718
import vectorpipe.functions.osm._
1819
import vectorpipe.relations.{MultiPolygons, Routes}
1920

20-
package object internal {
21+
package object internal extends Logging {
2122
val NodeType: Byte = 1
2223
val WayType: Byte = 2
2324
val RelationType: Byte = 3
2425
val MultiPolygonRoles: Seq[String] = Set("", "outer", "inner").toSeq
2526

26-
@transient lazy val logger: Logger = Logger.getLogger(getClass)
27-
2827
lazy val BareElementSchema = StructType(
2928
StructField("changeset", LongType, nullable = false) ::
3029
StructField("id", LongType, nullable = false) ::
@@ -332,6 +331,16 @@ package object internal {
332331
}
333332
val geometry = geom match {
334333
case Some(g) if g.isValid => g
334+
case Some(g) if !g.isEmpty =>
335+
val buffered = g.buffer(0)
336+
337+
if (buffered.isValid) {
338+
logWarning(s"Invalid way geometry, fixed by buffering: $id@$version ($updated): $g)")
339+
buffered
340+
} else {
341+
logWarning(s"Invalid way geometry: $id@$version ($updated): $g)")
342+
null
343+
}
335344
case _ => null
336345
}
337346
new GenericRowWithSchema(Array(changeset, id, version, updated, geometry), BareElementSchema): Row

0 commit comments

Comments
 (0)