Skip to content

Introduce new "id cache" for node tables#2460

Open
joto wants to merge 1 commit intoosm2pgsql-dev:masterfrom
joto:id-cache
Open

Introduce new "id cache" for node tables#2460
joto wants to merge 1 commit intoosm2pgsql-dev:masterfrom
joto:id-cache

Conversation

@joto
Copy link
Copy Markdown
Collaborator

@joto joto commented Apr 7, 2026

It is sometimes useful to know whether a way contains nodes of a certain type, i.e. with certain tags. This commit adds a new functionality called "id caches" that allows to find out.

When defining a node table in Lua with define_table the ids section can now contain a field cache = true. If this is set the ids of all nodes written to that table are stored in memory. Later, when processing ways, that cache can be queried with tablename:in_id_cache(). Usually this would be used to query all the member nodes of a way: ...:in_id_cache(object.nodes). The in_id_cache() function returns the indexes into the object.nodes array where the id matches. From there it is possible to get the id of the matching node (with object.nodes[idx]) or the location of that node (with object:as_point(idx). This information can be stored in a way table which will be correctly updated in append mode. (In append mode the in-memory id cache is populated with all the ids of the table for which the cache was defined.)

The whole thing only works for node tables and querying only works in the process_way() function. It can possibly be extended later to work in other contexts.

It is sometimes useful to know whether a way contains nodes of a certain
type, i.e. with certain tags. This commit adds a new functionality
called "id caches" that allows to find out.

When defining a node table in Lua with `define_table` the `ids` section
can now contain a field `cache = true`. If this is set the ids of all
nodes written to that table are stored in memory. Later, when processing
ways, that cache can be queried with `tablename:in_id_cache()`. Usually
this would be used to query all the member nodes of a way:
`...:in_id_cache(object.nodes)`. The `in_id_cache()` function returns
the indexes into the `object.nodes` array where the id matches. From
there it is possible to get the id of the matching node (with
`object.nodes[idx]`) or the location of that node (with
`object:as_point(idx)`. This information can be stored in a way table
which will be correctly updated in append mode. (In append mode the
in-memory id cache is populated with all the ids of the table for which
the cache was defined.)

The whole thing only works for node tables and querying only works in
the process_way() function. It can possibly be extended later to work
in other contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant