Closed pnorman closed 3 years ago
I've found a case where imposm emits an invalid geometry for a self-intersecting polygon.
as I see - the w120717877
has 4 nodes ;
so probably your example related to this change "Skips slow GEOS IsValid calls for polygons with only 4 corners." https://github.com/omniscale/imposm3/commit/a367850f6f7648561ebb3c078d67bd55eedc088a
modifying the code solves your problem.
root@2d0f4fac8032:/tools/imposm3# git diff
diff --git a/writer/ways.go b/writer/ways.go
index 6db70e7..8219523 100644
--- a/writer/ways.go
+++ b/writer/ways.go
@@ -147,7 +147,7 @@ func (ww *WayWriter) buildAndInsert(
if isPolygon {
geosgeom, err = geomp.Polygon(g, way.Nodes)
if err == nil {
- if g.NumCoordinates(geosgeom) > 5 {
+ if g.NumCoordinates(geosgeom) > 4 {
// only check for valididty for non-simple geometries
geosgeom, err = g.MakeValid(geosgeom)
}
tested with Geos 3.8.1
osmdb=# select osm_id, st_isvalid(geometry) from import.osm_water_polygon;
+-----------+------------+
| osm_id | st_isvalid |
+-----------+------------+
| 120717877 | t |
+-----------+------------+
(1 row)
I've found a case where imposm emits an invalid geometry for a self-intersecting polygon. The polygon is a figure-eight shape, and the files and commands to reproduce are below.
The invalid polygon causes later operations to fail like st_pointonsurface.
Files
w120717877.osm
water.yaml
Commands to reproduce