2

I'm working on a map render application and I would need to have the relation ID of OpenStreetMap from the Wikidata ID in order to download the GeoJSON file.

I have made some search and found a good way, but not perfect:

  1. Get Wikidata ID (eg:Q183)
  2. Query the Wikidata API with the ID(eg:https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q183)
  3. Get the relation ID from the field P402 : (eg:entities[Q183].claims.P402[0].mainsnak.datavalue.value)
  4. Query the OpenStreetMap Polygon API to get the JSON File (eg:http://polygons.openstreetmap.fr/get_geojson.py?id=51477)

It works great, but for a lot of cities the Wikidata API (step 3) doesn't return the Relation ID, but on the OpenStreetMap page of the city the Wikidata ID is present, so there is the link.

I would like to know if there is a way to get the Relation ID from the Wikidata ID on the OpenStreetMap API?

1 Answer 1

3

You can use Overpass API to fetch relation ids based on a wikidata ID:

rel[wikidata="Q183"];out ids;

This query returns:

<relation id="51477"/>
<relation id="62781"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.