Replies: 2 comments 2 replies
-
And that's something you can already do with osm2pgsql, just not very efficiently. You can create one table with, say, all nodes tagged with The problem for osm2pgsql is: It can only see one object at a time. For a node it imports it can know whether it contains a A way to solve this with current osm2pgsql is to just import that huge table as described above and then run an SQL query after the import removing all the node/way combinations that are no interesting. Not great either, but it would work. An alternative would be to add a trigger to that table connection nodes with ways that will check whether a node added has a And another possibility: When you have an updatable database, ie. in slim mode, you aready have the list of member nodes for all ways available in the database. So you can run an SQL query after import that finds all ways having a The way to think about this is: Osm2pgsql can only work on one object at a time, but after the import (or update) you do have a database with all sorts of clever functions in it. So you can prepare the data in osm2pgsql in a useful way but then in a second step So this is already something that can arguably be solved with current osm2pgsql and some basic SQL and doesn't necessarily need spatial joins or other complex spatial queries. A way to make this easier could be to add some functionality in osm2pgsql that would allow you to query member nodes from Lua when importing ways. But that adds a huge overhead because of the many database queries needed, not a great solution either, but certainly something we are considering. |
Beta Was this translation helpful? Give feedback.
-
|
I did some experiments over the last month with different kinds of queries joining "nodes" with "ways" in various way in the database. Either through ids using a "nodes" array, special join tables connecting node_ids with way_ids or using the spatial indexes. This in various combinations of using the middle tables or creating special tables for this use case and so on. All the options were quite slow. Interestingly enough, the spatial queries worked somewhat better than going through ids. So I believe we currently have no good way of handling this use case, at least for databases that are updated often. Running joins like this on a database that needs half a day to import and then lives for a long time isn't a huge problem, because it doesn't add that much extra processing time, but if we want minutely updates, the current situation is clearly not great. So I thought about what kind of functionality we could add to osm2pgsql to help with this use case. Here is the idea:
Here is an example to make this clearer:
In this example it can happen that a barrier node is in more than one highway way. At render time you can choose, for instance, only to render the barrier on the highest road class or something like that. That kind of processing is cheap, because there is no join involved any more and you only have very few entries in your bounding box in the barriers_on_highways table. I have some proof-of-concept code that makes all of this happen and it looks reasonable to me so far. This solution has the advantage that it doesn't add much memory overhead (as long as the table cached isn't too large) and is reasonably easy to understand (much easier than two-stage processing) and works okay with updates. But it will not work with really large lists of nodes, I wouldn't want to do this for all addresses or so. We'll have to see in practice how far we can stretch this. Does this sound like a reasonable approach? Can you see any problems with this? Does it address the use cases you have? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As discussed in the development Roadmap, there is currently limited "linkage" between different geometry types.
This isn't a problem for 95% of rendering, but there are cases where it is necessary to cross-reference between a node and the way(s) it is part of. Currently, for example, the turning circle / loop / mini-roundabout rendering in OSM Carto requires a relatively expensive and inelegant spatial join (
ST_DWithin) to (re)determine the types of highways that a turning circle is connected to and then render with the correct colour etc. There are other places where we would like to do similar things, e.g. resolve problems with level crossings where the starting zoom level should be adjusted based on the type of railway it attached to, adjust station rendering depending on railway type etc.As I understand, "linkage" between ways and multipolygons is achieved with callback functions so that relevant tags from the MP can be attached to constituent ways. You can imagine a similar mechanism for nodes / ways, where specific node types register a callback for further tag processing. That said, I don't think this callback mechanism is the most flexible / elegant solution, not least because you would need to make decisions about combining tags from multiple ways at import time.
I think the most flexible approach would be an explicit "node/way correlation table" with a row for every "connection of interest" e.g. turning circles, level crossings, railway stations etc. You would probably need to add primary key (serial-like type) to the node and way tables, rather than use the OSM ID as key/index. But having done this, the spatial joins would be simply replaced by normal SQL joins.
In the longer term, I'm sure there would be other applications of linking ways and nodes e.g. site-like relations where you would then know which nodes were contained within which bounding area.
[There was some related, but unresolved discussion in #2311.]
Beta Was this translation helpful? Give feedback.
All reactions