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 @
osmosis
Charge un extract OSM en base
Prétraitement pour faire des requêtes
Ajout d'index sur les tags
Ajout de colonne géométrique aux ways
Schéma
relations
ways
nodes
way_nodes
relation_members
Schéma : nodes
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 |
SELECT tags->’name’ , tags->’ref’ FROM ways WHERE tags?’highway’
"Avenue Tiers" , "N 32"
Schéma : relations
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
Requête sur relations
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'
Requêtes géospatiales
Extension PostGIS à Postgres
ST_Distance
ST_NPoints
ST_X, ST_Y
ST_Buffer
ST_Union
ST_Intersects
ST_AsText, ST_AsKML, ST_AsGeoJSON
…
Requête géospatiale
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
Utilisation des index
En unité de référence
Export géospatial
Pgsql2shp -> QGis
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%'
Export plus facilement manipulable dans QGis
Cas des tags à valeurs multiples
Manque junction=roundabout
Un giratoire c'est quoi ?
Moins de 25 nodes Moins de 70m de diamètre Plus de 60% d'un cercle
Manque junction=roundabout
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