From 251e5c9941b9a90e64ce2d8cec0de870c7f94855 Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Fri, 28 Mar 2014 11:14:02 +0100 Subject: [PATCH] fix for mappings where key and name of field differ --- mapping/fields.go | 6 +++--- test/imposm_system_test.py | 6 ++++++ test/test.osm | 12 ++++++++++++ test/test_mapping.json | 6 ++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mapping/fields.go b/mapping/fields.go index 318b707..fe7fb49 100644 --- a/mapping/fields.go +++ b/mapping/fields.go @@ -37,13 +37,13 @@ type MakeValue func(string, *element.OSMElem, Match) interface{} type MakeMakeValue func(string, FieldType, Field) (MakeValue, error) type FieldSpec struct { - Name string + Key string Type FieldType } func (f *FieldSpec) Value(elem *element.OSMElem, match Match) interface{} { if f.Type.Func != nil { - return f.Type.Func(elem.Tags[f.Name], elem, match) + return f.Type.Func(elem.Tags[f.Key], elem, match) } return nil } @@ -79,7 +79,7 @@ func (t *Table) TableFields() *TableFields { for _, mappingField := range t.Fields { field := FieldSpec{} - field.Name = mappingField.Name + field.Key = mappingField.Key fieldType := mappingField.FieldType() if fieldType != nil { diff --git a/test/imposm_system_test.py b/test/imposm_system_test.py index e10ee5a..eda7506 100644 --- a/test/imposm_system_test.py +++ b/test/imposm_system_test.py @@ -237,6 +237,12 @@ def test_missing_nodes(): place_10000 = query_row(db_conf, 'osm_places', 10000) assert place_10000['name'] == 'Foo', place_10000 +def test_name_tags(): + """Road contains multiple names""" + road = query_row(db_conf, 'osm_roads', 1101) + assert road['name'] == 'name', road + assert road['name:de'] == 'name:de', road + assert road['name_en'] == 'name:en', road def test_landusage_to_waterarea_1(): """Parks inserted into landusages""" diff --git a/test/test.osm b/test/test.osm index ac8ed2b..58eac63 100644 --- a/test/test.osm +++ b/test/test.osm @@ -302,6 +302,18 @@ + + + + + + + + + + + + diff --git a/test/test_mapping.json b/test/test_mapping.json index 3e6349c..201ff38 100644 --- a/test/test_mapping.json +++ b/test/test_mapping.json @@ -689,6 +689,12 @@ "name": "name:de", "key": "name:de" }, + { + "type": "string", + "#": " check for different name/keys", + "name": "name_en", + "key": "name:en" + }, { "type": "boolint", "name": "tunnel",