diff --git a/test/completedb_test.go b/test/completedb_test.go index eb82d4a..ba9b4b6 100644 --- a/test/completedb_test.go +++ b/test/completedb_test.go @@ -332,9 +332,12 @@ func TestComplete_GeneralizedLinestringIsValid(t *testing.T) { } func TestComplete_RingWithGap(t *testing.T) { - // Multipolygon and way with gap (overlapping but different endpoints) gets closed + // Multipolygon with gap (overlapping but different endpoints) gets closed assertGeomValid(t, checkElem{"osm_landusages", -7301, Missing, nil}) - assertGeomValid(t, checkElem{"osm_landusages", 7311, Missing, nil}) + // but not way + assertRecords(t, []checkElem{ + checkElem{"osm_landusages", 7311, Missing, nil}, + }) } func TestComplete_MultipolygonWithOpenRing(t *testing.T) { diff --git a/writer/ways.go b/writer/ways.go index a11de60..25b63e5 100644 --- a/writer/ways.go +++ b/writer/ways.go @@ -78,17 +78,29 @@ func (ww *WayWriter) loop() { continue } - err = ww.osmCache.Coords.FillWay(w) - if err != nil { - continue + filled := false + // fill loads all coords. call only if we have a match + fill := func(w *element.Way) bool { + if filled { + return true + } + err := ww.osmCache.Coords.FillWay(w) + if err != nil { + return false + } + ww.NodesToSrid(w.Nodes) + filled = true + return true } - ww.NodesToSrid(w.Nodes) w.Id = ww.wayId(w.Id) inserted := false insertedPolygon := false if matches := ww.lineMatcher.MatchWay(w); len(matches) > 0 { + if !fill(w) { + continue + } err, inserted = ww.buildAndInsert(geos, w, matches, false) if err != nil { if errl, ok := err.(ErrorLevel); !ok || errl.Level() > 0 { @@ -97,23 +109,28 @@ func (ww *WayWriter) loop() { continue } } - if !insertedAsRelation && (w.IsClosed() || w.TryClose(ww.maxGap)) { + if !insertedAsRelation { // only add polygons that were not inserted as a MultiPolygon relation if matches := ww.polygonMatcher.MatchWay(w); len(matches) > 0 { - err, insertedPolygon = ww.buildAndInsert(geos, w, matches, true) - if err != nil { - if errl, ok := err.(ErrorLevel); !ok || errl.Level() > 0 { - log.Warn(err) - } + if !fill(w) { continue } + if w.IsClosed() { + err, insertedPolygon = ww.buildAndInsert(geos, w, matches, true) + if err != nil { + if errl, ok := err.(ErrorLevel); !ok || errl.Level() > 0 { + log.Warn(err) + } + continue + } + } } } if (inserted || insertedPolygon) && ww.expireor != nil { expire.ExpireProjectedNodes(ww.expireor, w.Nodes, ww.srid, insertedPolygon) } - if ww.diffCache != nil { + if (inserted || insertedPolygon) && ww.diffCache != nil { ww.diffCache.Coords.AddFromWay(w) } }