omniscale / imposm3

Imposm imports OpenStreetMap data into PostGIS
http://imposm.org/docs/imposm3/latest/
Apache License 2.0
710 stars 156 forks source link

IDs are inconsistent #239

Closed zbycz closed 4 years ago

zbycz commented 4 years ago

Context

I use imposm for creating vector tiles (MVT) using the openmaptiles project. My ultimate goal is to create a universal OSM browser with clickable map and rich info panel - beta here: https://osmapp.org/?id=w34633854

Unfortunately, the IDs in imposm are still a mystery to me. I found out that id starting with 0 is a node and with 1 is a way, but very often the id is a small integer which doesnt comply with this system.

Expected Behavior

The id has some system which can be decoded. For eg.

Actual Behavior

Some ids are in form of 0<nodeid> or 1<wayid>, but some features (relations?) have ids like 4<randomnumber>. And some even have integers like 123 which doesnt refer to any schema(?).

Steps to Reproduce

Just see any output from imposm. Can provide steps if needed :-)

.

//ref https://github.com/openmaptiles/openmaptiles/issues/792

ImreSamu commented 4 years ago

Unfortunately, the IDs in imposm are still a mystery to me.

imho:

in sql

-- sql code fragment ...

-- nodes positive
WHEN  (id >=     0 )               THEN 'n'|| id::text

--  ways negative
WHEN  (id >= -1e17 ) AND (id < 0 ) THEN 'w'|| (abs(id))::text

--  relations negative -1e17
WHEN  (id <  -1e17 )               THEN 'r'|| (abs(id) -1e17)::text

and check/read the issues .. related this flag ..

imho2:

ImreSamu commented 4 years ago

IDs are inconsistent

imho3:

if you want to understand the logic of imposm3 .. then you have to check the code, ( singleIDSpace == use_single_id_space )

writer/ways.go#L60

func (ww *WayWriter) wayID(id int64) int64 {
    if !ww.singleIDSpace {
        return id
    }
    return -id
}

writer/relations.go#L66

func (rw *RelationWriter) relID(id int64) int64 {
    if !rw.singleIDSpace {
        return -id
    }
    return element.RelIDOffset - id
}
ImreSamu commented 4 years ago

I use imposm for creating vector tiles (MVT) using the openmaptiles project.

related openmaptiles issue ( with more workaround ) : https://github.com/openmaptiles/openmaptiles/issues/303

zbycz commented 4 years ago

@ImreSamu Thank you very much. You solved the mystery for me! 👍👍🎉🎉

I had two issues and mistaken them as one:

1) openmaptiles outputs OSM ids only for some layers. I have mixed it altogether, and was surprised that some ids are just sequential integers. (I guess that means that they use use_single_id_space correctly)

2) I discovered 0X=node and 1X=way, but didnt realised that 4X are really just relations. Now it works perfectly. (They use SQL like CASE WHEN osm_id<0 THEN -osm_id*10+4 ELSE osm_id*10+1)