From 53bb80726ca9456e4a0857b38803f9ccfe8e33fd Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Mon, 18 Jan 2021 12:03:19 +0100 Subject: [PATCH] mapping: fix (way)zorder for non-int32 layer values --- mapping/columns.go | 9 ++++++++- mapping/columns_test.go | 9 ++++++++- test/complete_db.osc | 11 +++++++++++ test/complete_db.osm | 10 ++++++++++ test/completedb_test.go | 21 ++++++++++++++++----- test/helper_test.go | 2 ++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/mapping/columns.go b/mapping/columns.go index ca873618..75cb241d 100644 --- a/mapping/columns.go +++ b/mapping/columns.go @@ -217,7 +217,8 @@ func MakeWayZOrder(columnName string, columnType ColumnType, column config.Colum wayZOrder := func(val string, elem *osm.Element, geom *geom.Geometry, match Match) interface{} { var z int - layer, _ := strconv.ParseInt(elem.Tags["layer"], 10, 64) + layer, _ := strconv.ParseInt(elem.Tags["layer"], 10, 32) + z += int(layer) * levelOffset rank, ok := ranks[match.Value] @@ -236,6 +237,9 @@ func MakeWayZOrder(columnName string, columnType ColumnType, column config.Colum z += levelOffset } + if z < math.MinInt32 || z > math.MaxInt32 { + return nil + } return z } return wayZOrder, nil @@ -285,6 +289,9 @@ func DefaultWayZOrder(val string, elem *osm.Element, geom *geom.Geometry, match z += 10 } + if z < math.MinInt32 || z > math.MaxInt32 { + return nil + } return z } diff --git a/mapping/columns_test.go b/mapping/columns_test.go index 3db192b8..5a930d9f 100644 --- a/mapping/columns_test.go +++ b/mapping/columns_test.go @@ -208,6 +208,7 @@ func TestWayZOrder(t *testing.T) { t.Fatal(err) } + NIL := 999 // marker value tests := []struct { key string tags osm.Tags @@ -223,12 +224,18 @@ func TestWayZOrder(t *testing.T) { {"path", osm.Tags{"tunnel": "yes"}, -10}, {"unknown", osm.Tags{"tunnel": "yes"}, -6}, {"unknown", osm.Tags{"tunnel": "yes", "layer": "1"}, 5}, + {"unknown", osm.Tags{"tunnel": "yes", "layer": "123456789123456789"}, NIL}, } for _, test := range tests { elem := &osm.Element{Tags: test.tags} match := Match{Value: test.key} - if v := zOrder("", elem, nil, match); v.(int) != test.expected { + if test.expected == NIL { + if v := zOrder("", elem, nil, match); v != nil { + t.Errorf("%v %v %#v != nil", test.key, test.tags, v) + } + + } else if v := zOrder("", elem, nil, match); v.(int) != test.expected { t.Errorf("%v %v %d != %d", test.key, test.tags, v, test.expected) } } diff --git a/test/complete_db.osc b/test/complete_db.osc index 3554b2f0..0b5b355a 100644 --- a/test/complete_db.osc +++ b/test/complete_db.osc @@ -96,6 +96,17 @@ + + + + + + + + + + + diff --git a/test/complete_db.osm b/test/complete_db.osm index 5bba391a..b886098e 100644 --- a/test/complete_db.osm +++ b/test/complete_db.osm @@ -743,6 +743,16 @@ + + + + + + + + + + diff --git a/test/completedb_test.go b/test/completedb_test.go index 1c3b7e27..ce17a556 100644 --- a/test/completedb_test.go +++ b/test/completedb_test.go @@ -5,16 +5,13 @@ import ( "fmt" "io/ioutil" "os" + "testing" osm "github.com/omniscale/go-osm" "github.com/omniscale/imposm3/cache" - "github.com/omniscale/imposm3/geom" - "github.com/omniscale/imposm3/proj" - - "testing" - "github.com/omniscale/imposm3/geom/geos" + "github.com/omniscale/imposm3/proj" ) func TestComplete(t *testing.T) { @@ -171,6 +168,13 @@ func TestComplete(t *testing.T) { }) }) + t.Run("WayWithInvalidLayer", func(t *testing.T) { + // Layer value is not a valid int32. + ts.assertRecords(t, []checkElem{ + {"osm_roads", 17003, "residential", map[string]string{"z_order": "NULL"}}, + }) + }) + t.Run("NodeWayInsertedTwice", func(t *testing.T) { // Way with multiple mappings is inserted twice in same table rows := ts.queryRows(t, "osm_roads", 18001) @@ -591,6 +595,13 @@ func TestComplete(t *testing.T) { ts.assertGeomArea(t, checkElem{"osm_landusages", -16001, "park", nil}, 12779350582) }) + t.Run("WayWithInvalidLayerUpdate", func(t *testing.T) { + // Layer value is now a valid int32. + ts.assertRecords(t, []checkElem{ + {"osm_roads", 17003, "residential", map[string]string{"z_order": "23"}}, + }) + }) + t.Run("NodeWayRefAfterDelete2", func(t *testing.T) { // Node does not referece deleted way diff --git a/test/helper_test.go b/test/helper_test.go index a1f5a828..1d55b3a4 100644 --- a/test/helper_test.go +++ b/test/helper_test.go @@ -245,6 +245,8 @@ func (ts *importTestSuite) query(t *testing.T, table string, id int64, keys []st for k, v := range h.Map { if v.Valid { r.tags[k] = v.String + } else { + r.tags[k] = "NULL" } }