OSM Planet

From BITPlan Wiki
Revision as of 13:11, 20 January 2025 by Wf (talk | contribs) (→‎endpoints.yaml)
Jump to navigation Jump to search

Links

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)

RelationStats:
  endpoint: osm-qlever
  param_list:
    - name: relid
      type: str
      default_value: "6843452"
  sparql: |
    # Get statistics about predicates used in an OSM relation 
    SELECT ?p (COUNT(?o) as ?count)
    WHERE {
      osmrel:{{relid}} ?p ?o .
    }
    GROUP BY ?p
    HAVING (?count > 1)
    ORDER BY DESC(?count)

Example queries

Sophox Queries

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)

try it!

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/"))
}

try it!

result

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