OSM Planet: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| (14 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= OSM Planet SPARQL | == Links == | ||
* https://wiki.openstreetmap.org/wiki/Sophox | |||
* https://qlever.cs.uni-freiburg.de/osm | |||
* https://wiki.bitplan.com/index.php?title=OSM_Planet | |||
* https://wiki.openstreetmap.org/wiki/Sophox/Example_queries | |||
* https://wiki.openstreetmap.org/wiki/OpenTripPlanner | |||
= OSM Planet SPARQL Queries with pylodstorage query tool = | |||
== Configuration for pylodstorage sparqlquery tool == | |||
see https://pypi.org/project/pyLodStorage/ | |||
=== installation === | |||
<source lang='bash'> | |||
pip install pylodstorage | |||
</source> | |||
The configuration files need to be in $HOME/.pylodstorage or you have to explicitly give the path with the -ep and -qp options | |||
=== endpoints.yaml === | === endpoints.yaml === | ||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
| Line 8: | Line 21: | ||
endpoint: https://sophox.org/sparql | endpoint: https://sophox.org/sparql | ||
website: https://sophox.org | website: https://sophox.org | ||
database: | database: blazegraph | ||
method: POST | method: POST | ||
lang: sparql | lang: sparql | ||
| Line 18: | Line 31: | ||
osm-qlever: | osm-qlever: | ||
endpoint: https://qlever.cs.uni-freiburg.de/api/osm | endpoint: https://qlever.cs.uni-freiburg.de/api/osm-planet | ||
website: https://qlever.cs.uni-freiburg.de/osm | website: https://qlever.cs.uni-freiburg.de/osm-planet | ||
database: qlever | database: qlever | ||
method: POST | method: POST | ||
| Line 28: | Line 41: | ||
PREFIX osmm: <https://www.openstreetmap.org/meta/> | PREFIX osmm: <https://www.openstreetmap.org/meta/> | ||
PREFIX geo: <http://www.opengis.net/ont/geosparql#> | PREFIX geo: <http://www.opengis.net/ont/geosparql#> | ||
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#> | |||
PREFIX osmway: <https://www.openstreetmap.org/way/> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== osmplanet.yaml === | === osmplanet.yaml (or queries.yaml as default) === | ||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
# OSMPlanet Query Examples | |||
# Wolfgang Fahl | |||
# 2025-01-20 | |||
# | |||
# SPARQL queries for exploring OpenStreetMap data via: | |||
# - https://sophox.org/sparql (Sophox endpoint) | |||
# - https://qlever.cs.uni-freiburg.de/osm (Qlever endpoint) | |||
# | |||
# See also: | |||
# - https://www.openstreetmap.org/ | |||
# - https://wiki.bitplan.com/index.php?title=OSM_Planet | |||
# | |||
# Motivation: Explore OSM relations and their predicates/objects to analyze | |||
# connectivity and relationships between OSM entities | |||
'RelationStats': | |||
param_list: | |||
- name: relid | |||
type: str | |||
default_value: "6843452" | |||
sparql: | | |||
# Get statistics about predicates used in an OSM relation | |||
PREFIX osmrel: <https://www.openstreetmap.org/relation/> | |||
SELECT ?p (COUNT(?o) as ?count) | |||
WHERE { | |||
osmrel:{{relid}} ?p ?o . | |||
} | |||
GROUP BY ?p | |||
HAVING (?count > 1) | |||
ORDER BY DESC(?count) | |||
'RelationNodes': | |||
# Get all nodes for a given OSM relation relid e.g. Renfe R16019 | |||
param_list: | param_list: | ||
- name: relid | - name: relid | ||
| Line 39: | Line 83: | ||
default_value: "6843452" | default_value: "6843452" | ||
sparql: | | sparql: | | ||
PREFIX osmrel: <https://www.openstreetmap.org/relation/> | |||
SELECT ?p ( | SELECT ?p ?o (STR(?label) as ?plabel) | ||
WHERE { | WHERE { | ||
osmrel:{{relid}} ?p ?o . | osmrel:{{relid}} ?p ?o . | ||
FILTER(STRSTARTS(STR(?o), "https://www.openstreetmap.org/node/")) | |||
} | |||
'RelationNodesGeo': | |||
# get geometry data for relation elements with a given role including lat/lon filtering | |||
param_list: | |||
- name: relid | |||
type: str | |||
default_value: "10492086" | |||
- name: role | |||
type: str | |||
default_value: "stop" | |||
- name: min_lat | |||
type: float | |||
default_value: 36.00 | |||
- name: max_lat | |||
type: float | |||
default_value: 44.00 | |||
- name: min_lon | |||
type: float | |||
default_value: -9.00 | |||
- name: max_lon | |||
type: float | |||
default_value: 4.00 | |||
sparql: | | |||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |||
PREFIX geo: <http://www.opengis.net/ont/geosparql#> | |||
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#> | |||
PREFIX osmrel: <https://www.openstreetmap.org/relation/> | |||
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:> | |||
PREFIX geof: <http://www.opengis.net/def/function/geosparql/> | |||
SELECT | |||
?rel_name | |||
?rel | |||
?rel_pos | |||
?member | |||
?node | |||
?node_name | |||
?node_ref | |||
?role | |||
?lat | |||
?lon | |||
WHERE { | |||
VALUES (?rel ?role ?minlat ?maxlat ?minlon ?maxlon) { | |||
(osmrel:{{relid}} "{{role}}" {{min_lat}} {{max_lat}} {{min_lon}} {{max_lon}}) | |||
} | |||
?rel osmkey:ref ?rel_name . | |||
?rel osmrel:member ?member . | |||
?member osm2rdfmember:pos ?rel_pos . | |||
?member osm2rdfmember:role ?role . | |||
?member osm2rdfmember:id ?node . | |||
OPTIONAL { ?node osmkey:name ?node_name}. | |||
OPTIONAL { ?node osmkey:ref ?node_ref}. | |||
?node geo:hasGeometry/geo:asWKT ?loc . | |||
BIND(geof:latitude(?loc) AS ?lat) | |||
BIND(geof:longitude(?loc) AS ?lon) | |||
FILTER (?lat > ?minlat && ?lat < ?maxlat && ?lon > ?minlon && ?lon < ?maxlon) | |||
} | |||
ORDER BY ?rel_pos | |||
'RelationRoleHistogram': | |||
# Get a histogram of roles for a given OSM relation | |||
param_list: | |||
- name: relid | |||
type: str | |||
default_value: "10492086" | |||
sparql: | | |||
PREFIX osmrel: <https://www.openstreetmap.org/relation/> | |||
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#> | |||
SELECT ?role (COUNT(?member) as ?count) | |||
WHERE { | |||
osmrel:{{relid}} osmrel:member ?member . | |||
?member osm2rdfmember:role ?role . | |||
} | } | ||
GROUP BY ? | GROUP BY ?role | ||
ORDER BY DESC(?count) | ORDER BY DESC(?count) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== test === | |||
<source lang='bash' highlight='1'> | |||
sparqlquery -en qlever-osm -qp osmplanet.yaml --list | |||
RelationStats:RelationStats | |||
RelationNodes:RelationNodes | |||
RelationNodesGeo:RelationNodesGeo | |||
RelationRoleHistogram:RelationRoleHistogram | |||
</source> | |||
= Sophox Example Queries = | |||
== RouteTypeHistogram == | |||
<source lang='bash' highlight='1'> | |||
sparqlquery -qp osmplanet.yaml -en osm-sophox -p -qn RouteTypeHistogram --limit 10 --format mediawiki | |||
</source> | |||
=== query === | |||
<source lang='sparql'> | |||
SELECT | |||
?route_type (COUNT(?route_type) AS ?count) | |||
WHERE { | |||
?route | |||
osmt:type "route"; | |||
osmt:route ?route_type; | |||
osmm:type "r"; | |||
osmt:ref ?ref; | |||
} | |||
GROUP BY ?route_type | |||
ORDER BY DESC(?count) | |||
</source> | |||
[https://sophox.org/#SELECT%0A%20%20%3Froute_type%20%28COUNT%28%3Froute_type%29%20AS%20%3Fcount%29%0AWHERE%20%7B%0A%20%20%20%3Froute%0A%20%20%20osmt%3Atype%20%22route%22%3B%0A%20%20%20osmt%3Aroute%20%3Froute_type%3B%0A%20%20%20osmm%3Atype%20%22r%22%3B%0A%20%20%20osmt%3Aref%20%3Fref%3B%0A%7D%0AGROUP%20BY%20%3Froute_type%0AORDER%20BY%20DESC%28%3Fcount%29%0A try it!] | |||
=== result === | |||
{| class="wikitable" style="text-align: left;" | |||
|+ <!-- caption --> | |||
|- | |||
! route_type !! align="right"| count | |||
|- | |||
| bus || align="right"| 286484 | |||
|- | |||
| road || align="right"| 242360 | |||
|- | |||
| hiking || align="right"| 106522 | |||
|- | |||
| bicycle || align="right"| 71364 | |||
|- | |||
| foot || align="right"| 49011 | |||
|- | |||
| train || align="right"| 13673 | |||
|- | |||
| mtb || align="right"| 8649 | |||
|- | |||
| power || align="right"| 5660 | |||
|- | |||
| railway || align="right"| 5239 | |||
|- | |||
| tram || align="right"| 4739 | |||
|} | |||
<source lang='bash' highlight='1'> | |||
sparqlquery -qp osmplanet.yaml -qn RelationStats -en osm-sophox --param relid=6843452 -f mediawiki | |||
</source> | |||
== RelationStats == | |||
=== query === | |||
<source lang='sparql'> | |||
# Get statistics about predicates used in an OSM relation | |||
PREFIX osmrel: <https://www.openstreetmap.org/relation/> | |||
SELECT ?p (COUNT(?o) as ?count) | |||
WHERE { | |||
osmrel:6843452 ?p ?o . | |||
} | |||
GROUP BY ?p | |||
HAVING (?count > 1) | |||
ORDER BY DESC(?count) | |||
</source> | |||
[https://sophox.org?query=%23%20Get%20statistics%20about%20predicates%20used%20in%20an%20OSM%20relation%0APREFIX%20osmrel%3A%20%3Chttps%3A//www.openstreetmap.org/relation/%3E%0ASELECT%20%3Fp%20%28COUNT%28%3Fo%29%20as%20%3Fcount%29%0AWHERE%20%7B%0A%20%20osmrel%3A6843452%20%3Fp%20%3Fo%20.%0A%7D%0AGROUP%20BY%20%3Fp%0AHAVING%20%28%3Fcount%20%3E%201%29%0AORDER%20BY%20DESC%28%3Fcount%29%0A try it!] | |||
=== result === | |||
{| class="wikitable" style="text-align: left;" | |||
|+ <!-- caption --> | |||
|- | |||
! p !! align="right"| count | |||
|- | |||
| https://www.openstreetmap.org/meta/has || align="right"| 186 | |||
|} | |||
<source lang='bash' highlight='1'> | |||
sparqlquery -qp osmplanet.yaml -qn RelationNodes -en osm-sophox --param relid=6843452 -f mediawiki | |||
</source> | |||
== RelationNodes == | |||
=== query === | |||
<source lang='sparql'> | |||
# Get all nodes for an OSM relation | |||
PREFIX osmrel: <https://www.openstreetmap.org/relation/> | |||
SELECT * | |||
WHERE { | |||
osmrel:6843452 ?p ?o . | |||
FILTER(STRSTARTS(STR(?o), "https://www.openstreetmap.org/node/")) | |||
} | |||
</source> | |||
[https://sophox.org/#%23%20Get%20all%20nodes%20for%20an%20OSM%20relation%0APREFIX%20osmrel%3A%20%3Chttps%3A//www.openstreetmap.org/relation/%3E%0ASELECT%20%2A%0AWHERE%20%7B%0A%20%20osmrel%3A6843452%20%3Fp%20%3Fo%20.%0A%20%20FILTER%28STRSTARTS%28STR%28%3Fo%29%2C%20%22https%3A//www.openstreetmap.org/node/%22%29%29%0A%7D%0A try it!] | |||
=== result === | |||
{| class="wikitable" style="text-align: left;" | |||
|+ <!-- caption --> | |||
|- | |||
! p !! o | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/29567894 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/29569297 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/1697798338 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/1981635686 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/5239688223 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/5959602923 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/6083777817 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/6767679673 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/6767679678 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/6767679964 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/6767680441 | |||
|- | |||
| https://www.openstreetmap.org/meta/has || https://www.openstreetmap.org/node/6767844278 | |||
|} | |||
= QLever example queries = | |||
<source lang='bash' highighlight='1'> | |||
sparqlquery -qp osmplanet.yaml -en osm-qlever -p -qn RelationRoleHistogram -f mediawiki --param relid=10492086 | |||
</source> | |||
== RelationRoleHistogram == | |||
== | === query === | ||
<source lang='sparql'> | |||
{ | PREFIX osmrel: <https://www.openstreetmap.org/relation/> | ||
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#> | |||
SELECT ?role (COUNT(?member) as ?count) | |||
WHERE { | |||
osmrel:10492086 osmrel:member ?member . | |||
?member osm2rdfmember:role ?role . | |||
} | |||
GROUP BY ?role | |||
ORDER BY DESC(?count) | |||
</source> | |||
[https://qlever.cs.uni-freiburg.de/osm-planet?query=PREFIX%20osmrel%3A%20%3Chttps%3A//www.openstreetmap.org/relation/%3E%0APREFIX%20osm2rdfmember%3A%20%3Chttps%3A//osm2rdf.cs.uni-freiburg.de/rdf/member%23%3E%0ASELECT%20%3Frole%20%28COUNT%28%3Fmember%29%20as%20%3Fcount%29%0AWHERE%20%7B%0A%20%20osmrel%3A10492086%20osmrel%3Amember%20%3Fmember%20.%0A%20%20%3Fmember%20osm2rdfmember%3Arole%20%3Frole%20.%0A%7D%0AGROUP%20BY%20%3Frole%0AORDER%20BY%20DESC%28%3Fcount%29%0A try it!] | |||
=== result === | |||
{| class="wikitable" style="text-align: left;" | |||
|+ <!-- caption --> | |||
|- | |||
! role !! align="right"| count | |||
|- | |||
| member || align="right"| 624 | |||
|- | |||
| platform || align="right"| 31 | |||
|- | |||
| stop || align="right"| 26 | |||
|} | |||
Latest revision as of 20:06, 20 January 2025
Links
- https://wiki.openstreetmap.org/wiki/Sophox
- https://qlever.cs.uni-freiburg.de/osm
- https://wiki.bitplan.com/index.php?title=OSM_Planet
- https://wiki.openstreetmap.org/wiki/Sophox/Example_queries
- https://wiki.openstreetmap.org/wiki/OpenTripPlanner
OSM Planet SPARQL Queries with pylodstorage query tool
Configuration for pylodstorage sparqlquery tool
see https://pypi.org/project/pyLodStorage/
installation
pip install pylodstorage
The configuration files need to be in $HOME/.pylodstorage or you have to explicitly give the path with the -ep and -qp options
endpoints.yaml
osm-sophox:
endpoint: https://sophox.org/sparql
website: https://sophox.org
database: blazegraph
method: POST
lang: sparql
prefixes: |
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
PREFIX osmt: <https://wiki.openstreetmap.org/wiki/Key:>
PREFIX osmm: <https://www.openstreetmap.org/meta/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
osm-qlever:
endpoint: https://qlever.cs.uni-freiburg.de/api/osm-planet
website: https://qlever.cs.uni-freiburg.de/osm-planet
database: qlever
method: POST
lang: sparql
prefixes: |
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
PREFIX osmt: <https://wiki.openstreetmap.org/wiki/Key:>
PREFIX osmm: <https://www.openstreetmap.org/meta/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#>
PREFIX osmway: <https://www.openstreetmap.org/way/>
osmplanet.yaml (or queries.yaml as default)
# OSMPlanet Query Examples
# Wolfgang Fahl
# 2025-01-20
#
# SPARQL queries for exploring OpenStreetMap data via:
# - https://sophox.org/sparql (Sophox endpoint)
# - https://qlever.cs.uni-freiburg.de/osm (Qlever endpoint)
#
# See also:
# - https://www.openstreetmap.org/
# - https://wiki.bitplan.com/index.php?title=OSM_Planet
#
# Motivation: Explore OSM relations and their predicates/objects to analyze
# connectivity and relationships between OSM entities
'RelationStats':
param_list:
- name: relid
type: str
default_value: "6843452"
sparql: |
# Get statistics about predicates used in an OSM relation
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
SELECT ?p (COUNT(?o) as ?count)
WHERE {
osmrel:{{relid}} ?p ?o .
}
GROUP BY ?p
HAVING (?count > 1)
ORDER BY DESC(?count)
'RelationNodes':
# Get all nodes for a given OSM relation relid e.g. Renfe R16019
param_list:
- name: relid
type: str
default_value: "6843452"
sparql: |
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
SELECT ?p ?o (STR(?label) as ?plabel)
WHERE {
osmrel:{{relid}} ?p ?o .
FILTER(STRSTARTS(STR(?o), "https://www.openstreetmap.org/node/"))
}
'RelationNodesGeo':
# get geometry data for relation elements with a given role including lat/lon filtering
param_list:
- name: relid
type: str
default_value: "10492086"
- name: role
type: str
default_value: "stop"
- name: min_lat
type: float
default_value: 36.00
- name: max_lat
type: float
default_value: 44.00
- name: min_lon
type: float
default_value: -9.00
- name: max_lon
type: float
default_value: 4.00
sparql: |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#>
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT
?rel_name
?rel
?rel_pos
?member
?node
?node_name
?node_ref
?role
?lat
?lon
WHERE {
VALUES (?rel ?role ?minlat ?maxlat ?minlon ?maxlon) {
(osmrel:{{relid}} "{{role}}" {{min_lat}} {{max_lat}} {{min_lon}} {{max_lon}})
}
?rel osmkey:ref ?rel_name .
?rel osmrel:member ?member .
?member osm2rdfmember:pos ?rel_pos .
?member osm2rdfmember:role ?role .
?member osm2rdfmember:id ?node .
OPTIONAL { ?node osmkey:name ?node_name}.
OPTIONAL { ?node osmkey:ref ?node_ref}.
?node geo:hasGeometry/geo:asWKT ?loc .
BIND(geof:latitude(?loc) AS ?lat)
BIND(geof:longitude(?loc) AS ?lon)
FILTER (?lat > ?minlat && ?lat < ?maxlat && ?lon > ?minlon && ?lon < ?maxlon)
}
ORDER BY ?rel_pos
'RelationRoleHistogram':
# Get a histogram of roles for a given OSM relation
param_list:
- name: relid
type: str
default_value: "10492086"
sparql: |
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#>
SELECT ?role (COUNT(?member) as ?count)
WHERE {
osmrel:{{relid}} osmrel:member ?member .
?member osm2rdfmember:role ?role .
}
GROUP BY ?role
ORDER BY DESC(?count)
test
sparqlquery -en qlever-osm -qp osmplanet.yaml --list
RelationStats:RelationStats
RelationNodes:RelationNodes
RelationNodesGeo:RelationNodesGeo
RelationRoleHistogram:RelationRoleHistogram
Sophox Example Queries
RouteTypeHistogram
sparqlquery -qp osmplanet.yaml -en osm-sophox -p -qn RouteTypeHistogram --limit 10 --format mediawiki
query
SELECT
?route_type (COUNT(?route_type) AS ?count)
WHERE {
?route
osmt:type "route";
osmt:route ?route_type;
osmm:type "r";
osmt:ref ?ref;
}
GROUP BY ?route_type
ORDER BY DESC(?count)
result
| route_type | count |
|---|---|
| bus | 286484 |
| road | 242360 |
| hiking | 106522 |
| bicycle | 71364 |
| foot | 49011 |
| train | 13673 |
| mtb | 8649 |
| power | 5660 |
| railway | 5239 |
| tram | 4739 |
sparqlquery -qp osmplanet.yaml -qn RelationStats -en osm-sophox --param relid=6843452 -f mediawiki
RelationStats
query
# Get statistics about predicates used in an OSM relation
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
SELECT ?p (COUNT(?o) as ?count)
WHERE {
osmrel:6843452 ?p ?o .
}
GROUP BY ?p
HAVING (?count > 1)
ORDER BY DESC(?count)
result
| p | count |
|---|---|
| https://www.openstreetmap.org/meta/has | 186 |
sparqlquery -qp osmplanet.yaml -qn RelationNodes -en osm-sophox --param relid=6843452 -f mediawiki
RelationNodes
query
# Get all nodes for an OSM relation
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
SELECT *
WHERE {
osmrel:6843452 ?p ?o .
FILTER(STRSTARTS(STR(?o), "https://www.openstreetmap.org/node/"))
}
result
QLever example queries
sparqlquery -qp osmplanet.yaml -en osm-qlever -p -qn RelationRoleHistogram -f mediawiki --param relid=10492086
RelationRoleHistogram
query
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
PREFIX osm2rdfmember: <https://osm2rdf.cs.uni-freiburg.de/rdf/member#>
SELECT ?role (COUNT(?member) as ?count)
WHERE {
osmrel:10492086 osmrel:member ?member .
?member osm2rdfmember:role ?role .
}
GROUP BY ?role
ORDER BY DESC(?count)
result
| role | count |
|---|---|
| member | 624 |
| platform | 31 |
| stop | 26 |