omniscale/imposm3

IDs are inconsistent

zbycz opened this issue ยท 4 comments

zbycz commented

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.

  • XXX0 - osm node with id XXX
  • YYY1 - osm way with id YYY
  • ZZZ2 - osm relation with id ZZZ

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 openmaptiles/openmaptiles#792

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

imho:

	// SingleIDSpace mangles the overlapping node/way/relation IDs
	// to be unique (nodes positive, ways negative, relations negative -1e17)

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:

  • There are other workarounds ... but this is the simplest (use_single_id_space) ...

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
}

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

related openmaptiles issue ( with more workaround ) : openmaptiles/openmaptiles#303

zbycz commented

@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)