Requêtes osmosis + gis

1,082 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,082
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • http://datenkueche.com/osmlive/
  • Requêtes osmosis + gis

    1. 1. Requêtes osmosis + GIS Frédéric Rodrigo <fred.rodrigo gmail.com> La Cantine - Paris 07/10/2011 – (c)left 2011 - CC-BY-SA v3.0 @
    2. 2. <ul>osmosis </ul><ul><li>Charge un extract OSM en base </li><ul><li>Prétraitement pour faire des requêtes </li><ul><li>Ajout d'index sur les tags
    3. 3. Ajout de colonne géométrique aux ways </li></ul></ul></ul>
    4. 4. <ul>Schéma </ul><ul>relations </ul><ul>ways </ul><ul>nodes </ul><ul>way_nodes </ul><ul>relation_members </ul>
    5. 5. <ul>Schéma : nodes </ul>Colonne | Type | Modificateurs --------------+-----------------------------+--------------- id | bigint | non NULL version | integer | non NULL user_id | integer | non NULL tstamp | timestamp without time zone | non NULL changeset_id | bigint | non NULL tags | hstore | geom | geometry |
    6. 6. <ul>Requête sur nodes & hstore </ul><ul><li>SELECT tags FROM nodes; </li></ul><ul><ul><li>&quot;man_made&quot;=>&quot;water_tower&quot;, &quot;ele&quot;=>&quot;120&quot; </li></ul></ul><ul><li>SELECT tags->’name’ FROM nodes; </li></ul><ul><ul><li>&quot;L’assiette&quot; </li></ul></ul><ul><li>SELECT tags->’name’ , tags->’ref:INSEE’ FROM nodes WHERE tags?’place’ </li></ul><ul><ul><li>&quot;Saint-Jean-de-Luz&quot; , &quot;64483&quot; </li></ul></ul>
    7. 7. <ul>Schéma : ways </ul>Colonne | Type | Modificateurs --------------+-----------------------------+--------------- id | bigint | non NULL version | integer | non NULL user_id | integer | non NULL tstamp | timestamp without time zone | non NULL changeset_id | bigint | non NULL tags | hstore | nodes | bigint[] | bbox | geometry | linestring | geometry | Colonne | Type | Modificateurs -------------+---------+--------------- way_id | bigint | non NULL node_id | bigint | non NULL sequence_id | integer | non NULL
    8. 8. <ul>Requête sur ways </ul><ul><li>SELECT tags FROM ways; </li></ul><ul><ul><li>&quot;building&quot;=>&quot;yes&quot;, &quot;wall&quot;=>&quot;no&quot; </li></ul></ul><ul><li>SELECT tags->’name’ FROM ways; </li></ul><ul><ul><li>&quot;Rue des Lilas&quot; </li></ul></ul><ul><li>SELECT tags->’name’ , tags->’ref’ FROM ways WHERE tags?’highway’ </li></ul><ul><ul><li>&quot;Avenue Tiers&quot; , &quot;N 32&quot; </li></ul></ul>
    9. 9. <ul>Schéma : relations </ul>Colonne | Type | Modificateurs --------------+-----------------------------+--------------- id | bigint | non NULL version | integer | non NULL user_id | integer | non NULL tstamp | timestamp without time zone | non NULL changeset_id | bigint | non NULL tags | hstore | Colonne | Type | Modificateurs -------------+--------------+--------------- relation_id | bigint | non NULL member_id | bigint | non NULL member_type | character(1) | non NULL member_role | text | non NULL sequence_id | integer | non NULL
    10. 10. <ul>Requête sur relations </ul><ul>SELECT relation.id FROM relations JOIN relation_members ON relations.id = relation_members.relation_id AND relation_members.member_type = 'W' JOIN ways ON relation_members.member_id = ways.id WHERE relations.tags?'type' AND relations.tags->'type' = 'road' AND ways.tags?'highway' AND ways.tags->'highway' = 'service' </ul>
    11. 11. <ul>Requêtes géospatiales </ul><ul><li>Extension PostGIS à Postgres </li></ul><ul><ul><li>ST_Distance
    12. 12. ST_NPoints
    13. 13. ST_X, ST_Y
    14. 14. ST_Buffer
    15. 15. ST_Union
    16. 16. ST_Intersects
    17. 17. ST_AsText, ST_AsKML, ST_AsGeoJSON
    18. 18. … </li></ul></ul>
    19. 19. <ul>Requête géospatiale </ul><ul>SELECT po.id, MIN(ST_Distance(po.geom, po.pb) AS dist FROM nodes AS pb, nodes AS po WHERE pb.tags?'amenity' AND pb.tags->'amenity' = 'post_box' AND po.tags?'amenity' AND po.tags->'amenity' = 'post_office' AND GROUP BY po.id </ul><ul>Utilisation des index </ul><ul>En unité de référence </ul>
    20. 20. <ul>Export géospatial </ul><ul><li>Pgsql2shp -> QGis </li></ul><ul>SELECT id, tags->'source' AS source, ST_Simplify(linestring, 1e-3) AS geom FROM ways WHERE tags?'source' AND tags->'source' LIKE '%Cartographes Associés%' </ul><ul>Export plus facilement manipulable dans QGis </ul><ul>Cas des tags à valeurs multiples </ul>
    21. 21. <ul>Manque junction=roundabout </ul><ul><li>Un giratoire c'est quoi ? </li></ul>Moins de 25 nodes Moins de 70m de diamètre Plus de 60% d'un cercle
    22. 22. <ul>Manque junction=roundabout </ul>SELECT ways.id FROM ways WHERE -- tags ways.tags?'highway' AND (NOT ways.tags?'junction' OR ways.tags->'junction' != 'roundabout') AND -- geometry ST_NPoints(linestring) < 24 AND ST_MaxDistance(linestring,linestring) < 70 AND ST_Area(linestring) / ST_Area(ST_MinimumBoundingCircle(linestring)) > 0.6

    ×