support for __any__: [__any__] mappings

master
Oliver Tonnhofer 2016-06-15 13:37:20 +02:00
parent 3c271279b2
commit 8213d072c1
5 changed files with 130 additions and 1 deletions

View File

@ -22,7 +22,7 @@ The most important part is the ``tables`` definition. Each table is a YAML objec
~~~~~~~~~~~
``mapping`` defines which OSM key/values an element needs to have to be imported into this table. ``mapping`` is a YAML object with the OSM `key` as the object key and a list of all OSM `values` to be matched as the object value.
You can use the value ``__any__`` to match all values.
You can use ``__any__`` to match all values (e.g. ``amenity: [__any__]``). To match elements regardless of their tags use ``__any__: [__any__]``. You need to use :ref:`load_all<tags>` in this case so that Imposm has access to all tags.
To import all polygons with `tourism=zoo`, `natural=wood` or `natural=land` into the ``landusages`` table:

View File

@ -127,7 +127,10 @@ func (tm *tagMatcher) match(tags *element.Tags) []Match {
}
tables[t.DestTable] = this
}
}
if values, ok := tm.mappings[Key("__any__")]; ok {
addTables("__any__", "__any__", values["__any__"])
}
for k, v := range *tags {

21
test/any_any.osm Normal file
View File

@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="Osmosis SNAPSHOT-r25240">
<node id="10000" version="1" timestamp="2011-11-11T00:11:11Z" lat="42" lon="9">
</node>
<node id="10001" version="1" timestamp="2011-11-11T00:11:11Z" lat="42" lon="10">
<tag k="random" v="tag"/>
</node>
<node id="10002" version="1" timestamp="2011-11-11T00:11:11Z" lat="42" lon="11">
<tag k="amenity" v="shop"/>
</node>
<node id="10003" version="1" timestamp="2011-11-11T00:11:11Z" lat="42" lon="12">
<tag k="random" v="tag"/>
<tag k="but" v="mapped"/>
<tag k="amenity" v="shop"/>
</node>
</osm>

56
test/any_any_mapping.json Normal file
View File

@ -0,0 +1,56 @@
{
"tags": {
"load_all": true,
"exclude": [
"created_by",
"source"
]
},
"tables": {
"all": {
"fields": [
{
"type": "id",
"name": "osm_id"
},
{
"type": "geometry",
"name": "geometry"
},
{
"type": "hstore_tags",
"name": "tags"
}
],
"type": "point",
"mapping": {
"__any__": ["__any__"]
}
},
"amenities": {
"fields": [
{
"type": "id",
"name": "osm_id"
},
{
"type": "geometry",
"name": "geometry"
},
{
"type": "hstore_tags",
"name": "tags"
},
{
"type": "mapping_value",
"name": "type"
},
],
"type": "point",
"mapping": {
"amenity": ["__any__"]
}
}
}
}

49
test/any_any_test.go Normal file
View File

@ -0,0 +1,49 @@
package test
import (
"database/sql"
"testing"
"github.com/omniscale/imposm3/geom/geos"
)
func TestAnyAny_Prepare(t *testing.T) {
ts.dir = "/tmp/imposm3test"
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
osmFileName: "build/any_any.pbf",
mappingFileName: "any_any_mapping.json",
}
ts.g = geos.NewGeos()
var err error
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
}
func TestAnyAny_Import(t *testing.T) {
if ts.tableExists(t, dbschemaImport, "osm_all") != false {
t.Fatalf("table osm_all exists in schema %s", dbschemaImport)
}
ts.importOsm(t)
ts.deployOsm(t)
if ts.tableExists(t, dbschemaProduction, "osm_all") != true {
t.Fatalf("table osm_all does not exists in schema %s", dbschemaProduction)
}
}
func TestAnyAny_InsertedNodes(t *testing.T) {
assertHstore(t, []checkElem{
{"osm_all", 10000, "", nil}, // nodes without tags are not inserted
{"osm_all", 10001, "*", map[string]string{"random": "tag"}},
{"osm_all", 10002, "*", map[string]string{"amenity": "shop"}},
{"osm_all", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
{"osm_amenities", 10002, "*", map[string]string{"amenity": "shop"}},
{"osm_amenities", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
})
}