Sunday 24 June 2018

polygon - Select OSM admin boundary which links with pelias geocoder result


We use pelias geocoder environment in our project. There is a case "selection a polygon, which links with pelias result." For example we choose "Muenich" in search field -> on client we see this:


polygon


How to realise it? Geocoder answers have only bbox and node coordinate (if i use &source=osm too), how to links them with osm admin boundary?



Answer



Pelias does not currently support directly returning polygon or polyline data. However, you can use a workaround until it does.


A search or autocomplete request to pelias that returns Munich will have a feature in the response that looks something like this (with some data removed for conciseness):


"properties": {
"id": "101748479",
"gid": "whosonfirst:locality:101748479",

"layer": "locality",
"source": "whosonfirst",
"name": "Munich",
"locality": "Munich",
"locality_gid": "whosonfirst:locality:101748479",
"country_a": "DEU"
"label": "Munich, Germany"
},

The id here is a stable identifier within the Who's on First (WOF) gazetteer. Knowing this identifier, you can fetch the original data from the WOF source on GitHub.



WOF stores data in separate repositories based on the two digit ISO-3166-1 alpha-2 country code. Pelias returns the 3 digit alpha-3 code, which can be converted to the two digit. In this case the data is stored in the whosonfirst-data/whosonfirst-data-admin-de repository.


Using the WOF ID, you can determine the file which contains the GeoJSON geometry for Munich. WOF documents are stored in a nested subdirectory structure with each set of 3 numbers corresponding to a directory level.


You can construct the URL to the Munich GeoJSON file on github.com:



https://github.com/whosonfirst-data/whosonfirst-data-admin-de/blob/master/data/101/748/479/101748479.geojson



or the raw file which is useful for download:



https://raw.githubusercontent.com/whosonfirst-data/whosonfirst-data-admin-de/master/data/101/748/479/101748479.geojson




WOF record for Munich on GitHub


Note: if you're doing this for many records, you might want to mirror this data yourself and possibly simplify the geometry to reduce the data size.


In the future, Pelias will support returning polygons from WOF directly, and may even support returning OSM geometries via the Pelias spatial service, which is currently in early alpha.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...