-
Notifications
You must be signed in to change notification settings - Fork 1
creation of a backend for osm2pgsql #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
I corrected 3 bugs :
|
|
I've improved |
|
Salut @frodrigo j'ai bien avancé. La plupart des requêtes fonctionnent (sélection d'1 élément, filtrage par tag, filtrage par area) mais pas le filtrage sur une bbox : ça ne donne pas d'erreur, mais ça renvoie toujours 0 éléments... Quand je copie la requête sql complète depuis le terminal dans pgadmin pour tester, je vois que c'est bien cette ligne qui pose pb, celle qui teste l'intersection de la bbox avec les objets : J'ai beau faire des modifs dans cette ligne, je n'arrive pas à la faire fonctionner. Peux tu me confirmer que ça marche bien dans la version pour osmosis ? Une idée d'où pourrait venir le pb ? |
|
Nice. Please can you move the non docker readme part to an other PR , but into the main readme, as non specific to any backend. |
It as about projection mismatch, no ? Overpass-QL are in 4326, but osm2Pgsql data should be in other (3857 ?). |
a7e1cfc to
ef28ff9
Compare
You were right, thanks! I modified my view.sql with I forced push 1 commit merging all the previous ones, but based on #4. Maybe I will have to rebase this PR after you merge #4?
Warning: I only tested with bundle. I did not manage to test with docker. Is it possible to set the DATABASE_URL value in the yaml file so as to connect to my local database ?!? |
|
@frodrigo I managed to run the server using docker! I documented in the readme the changes I made in The instance is currently deployed at http://51.159.100.169:9292/interpreter covering whole France, you can try it. In my first tests, tags and bbox filtering works well. But area filtering reaches timeout... It is not the case on my local instance with a filtered Bretagne. Any idea of how to solve it? |
@frodrigo I spoke too soon, and I've understood where the timeouts come from: requests using geom in SRID 4632 are 50x slower than exactly the same request using geom in SRID 3857 (whether the geometry is transformed on the fly or pre-calculated in a separate column) For example this simple request (2 playgrounds in a park) takes 44ms using SRID 3857 and 2,2s using SRID 4632 Is this normal and known? Or is there a bug somewhere? What can I do to fix it? Thanks! |
|
The issue is the The good way to to this is to transform the bbox (or other spatial filter) to database projection, to use the spatial index, then transform the result to 4326. Maybe the transformation should be done in at the engine level. |
yes! I'd thought of that myself in the meantime, thanks for confirming!
You mean here in overpass_parser-rb ? |
More here, the to_sql should know the projection and transform the filter |
OK understood I need to transform the filter from 4326 (used in bbox coordinates) to the one used in DB geom (3857 here) before comparing to geom. For example for a bbox filter, it gives : But I don't know how to optimally detect the SRID of the geom column in the DB... and where to put this detection. I though about using |
|
I was just thinking about passing it to the program, without any kind of detection. Eg; with en env var, like the DB conn. |
|
OK clear. I tried but in fact there is 9 different definitions |
|
I've just discovered that osm2pgsql has a But it won't work for people who already have their osm2pgsql database (created with default 3857) before deploying an Underpass instance (Typically if OSM-FR wants to deploy an instance on the database used for raster tiles computation ...). @frodrigo What do you think about it? |
|
If you osm2pgsql import is also used for tile rendering you need to be in 3857. Because standard tiles are based on it.
Filter are used from query_object It called from https://github.com/teritorio/overpass_parser-rb/blob/master/lib/overpass_parser/nodes/query_objects.rb#L56 |
|
May I suggest that you have a look at the |
Yes indeed! When I started this PR, I was a beginner on osm2pgsql, so I thought I could write sql queries adapted to existing osm2pgsql DBs (I only knew the pgsql output*). I've since realised that this makes no sense, as there are as many possible schemas as there are users, thanks to the power of flex output. So I'm thinking of rewriting this PR for the case of a new osm2pgsql DB, which would be built specifically for a new underpass instance to mimic overpass with all OSM elements (at least in a given geographic area). My strategy :
|
aa159f8 to
ddbf255
Compare
joto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick comments from glancing over the code.
| -- Returns true if there are no tags left. | ||
|
|
||
| -- modifié : retourne vrai si aucun tag | ||
| local function clean_tags(tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this if you don't change the tags. The process_* functions will no be called for objects without tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ! I've kept it in case the user (including myself) changes his mind and wants to filter tags. For example, to remove all objects that only have the building key, since they're almost useless for an underpass instance. But this will only reduce the size of the base slightly, as it's the middle tables that weigh the most.
| @@ -0,0 +1,8 @@ | |||
| CREATE EXTENSION IF NOT EXISTS htsore; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need hstore? If yes, htsore will not work. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops a typo 😬 Anyway, I don't know if it's worth keeping the postgres docker or not ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo fixed on original postgres backend.
|
|
||
| tables.points:insert({ | ||
| -- tags = object.tags, | ||
| geom = geom -- the point will be automatically be projected to 3857 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is wrong, because you set 4326 above.
| -- modif : on enregistre la géométrie directement en multilinestring | ||
| -- en mergeant les lignes le plus possible | ||
| tables.lines:insert({ | ||
| geom = object:as_multilinestring():line_merge() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
geom = object:as_linestring() is sufficient. A way can not contain a multilinestring that needs to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed I had mixed up with the relations
| local relation_type = object:grab_tag('type') | ||
|
|
||
| -- Store route relations as multilinestrings | ||
| if relation_type == 'route' or relation_type == 'associatedStreet' or relation_type == 'public_transport' or relation_type == 'waterway' then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you representing an associatedStreet relation as a linestring? It is supposed to connected streets with houses. The "geometry" of that is much more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I wanted to include associatedStreet relations since the French community loves them, but this lines table isn't appropriate. But neither is the polygons table, since I wanted to include in it only the geometries corresponding to areas in overpass...
backends/postgres_osm2pgsql/view.sql
Outdated
| @@ -0,0 +1,156 @@ | |||
| /************** ABOUT TABLES *****************/ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of these comments are out of date now.
Thanks a lot for the review and the constructive comments! |
|
@joto By the way, what do you think about the strategy? (using middle tables for tags, and flex output tables for geometries) Do you have any advice or warning ? I made this choice since I want a synchronised DB. But in the end, I think I'll also push another backend (or another view.sql) for people who want a very light instance with no middle tables. |
|
@etienneJr It is certainly a valid approach. Queries will be a bit slower but uses less disk space. If you are using a flat node file though, you'll not have all nodes in the database, which might or might not be what you want. |
|
Note. I just add the support for SRID and ST_Transform. |
Thanks, that's perfect for existing osm2pgsql databases which use SRID 3857. |
3492185 to
b064726
Compare
|
I pushed a new version yesterday to solve an issue with negative ids for relations in osm2pgsql polygons table (area type) : indexation was not used when I wanted to join the middle table (which uses positive ids) with an output table (which uses negative ids), so the execution time was very long. So I choose to store geometries in 1 table per element type ( But when I try this new version, I am wondering whether I still have indexation issues or not. For example this simple SQL request (to get 419 playgrounds near Rennes): takes :
(geom has been automatically indexed by osm2pgsql, tags(json) has been indexed manually after DB creation) 2 different people told me that I may have an issue in indexation since the execution time should be almost the same whatever the DB size if the indexation is correct. EXPLAIN ANALYZE on FR database |
20c8b5f to
e9bad11
Compare
Hi,
I have adapted the osmosis backend for osm2pgsql.
If anyone would like to try it, that would be great!
Comments welcome! Thanks!