Introduce new "id cache" for node tables#2460
Open
joto wants to merge 1 commit intoosm2pgsql-dev:masterfrom
Open
Introduce new "id cache" for node tables#2460joto wants to merge 1 commit intoosm2pgsql-dev:masterfrom
joto wants to merge 1 commit intoosm2pgsql-dev:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_tabletheidssection can now contain a fieldcache = 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 withtablename:in_id_cache(). Usually this would be used to query all the member nodes of a way:...:in_id_cache(object.nodes). Thein_id_cache()function returns the indexes into theobject.nodesarray where the id matches. From there it is possible to get the id of the matching node (withobject.nodes[idx]) or the location of that node (withobject: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.