7

I often propose OSM as a resource on this site, but actually I don't know how to use it very well. (I'll post this first to OpenData but maybe it's more appropriate for GIS.)


If I have a single latitude and longitude point, how can I find the dimensions or geo-coordinates of the object?

Here's an example:

enter image description here

  • On OSM, it looks like this (link):

enter image description here

  • And I'm looking for the coordinates of this rectangle:

enter image description here

  • According to the color legend, it's either "Sports centre" or "Sports pitch" (probably the former).

enter image description here

  • On the Overpass Turbo (OSM API) I can find the object - 168927595

enter image description here

  • And the Nodes underneath are actually the corners.

enter image description here


BUT how can I do this all programatically, via a URL, webservice or API?

I have to do only a handful of queries spread over months, so I can use a public resource with limited quotas. My geography is only in Switzerland for the moment.


I've tried the Nominatim API

http://nominatim.openstreetmap.org/reverse?format=xml&lat=47.382844&lon=8.503754&zoom=18&addressdetails=0&polygon_geojson=1

results:

<result place_id="71071014" osm_type="way" osm_id="28733849" ref="Stadion Letzigrund" lat="47.38282055" lon="8.50373866657526" boundingbox="47.3817046,47.3838748,8.502166,8.5051997" geojson="{"type":"Polygon","coordinates":[[[8.502166,47.3824916],[8.5021808,47.3826066],[8.5022493,47.3827219],[8.5023643,47.382886],[8.5027706,47.3832445],[8.5031899,47.3835916],[8.5033192,47.3836894],[8.5034696,47.3837748],[8.5036004,47.383825],[8.5037349,47.3838587],[8.5038731,47.3838743],[8.5040127,47.3838748],[8.5041689,47.3838591],[8.5043265,47.3838209],[8.5045304,47.3837468],[8.504745,47.3836457],[8.5049314,47.3835164],[8.5050552,47.3833863],[8.505141,47.383244],[8.5051831,47.3831285],[8.5051997,47.3830107],[8.5051826,47.3828853],[8.5051352,47.3827558],[8.5050291,47.3826127],[8.5049168,47.3824909],[8.5042159,47.3819128],[8.5041256,47.381865],[8.5040485,47.3818273],[8.5039701,47.3817961],[8.5038053,47.3817439],[8.5035874,47.381712],[8.5033799,47.3817046],[8.5032385,47.3817138],[8.5030521,47.3817444],[8.5028884,47.3817959],[8.5027417,47.3818565],[8.5026008,47.3819327],[8.5024694,47.3820137],[8.5023528,47.3821055],[8.5022551,47.3822116],[8.5022036,47.3822879],[8.5021698,47.3823797],[8.502166,47.3824916]]]}">
Stadion Letzigrund, Herdernstrasse, Erismannhof, Hard, Aussersihl, Zurich, Bezirk Zürich, Zurich, 8004, Switzerland
</result>

But the GeoJSON results don't give the corner points of the rectanlge (viewer)

enter image description here

  • 1
    In the most generic sense, you're saying: given a point X, find all polygons where X is an interior point. Am I understanding correctly? – Barry Carter Nov 14 '16 at 2:07
  • Yeah, that's what I mean. – philshem Nov 14 '16 at 7:00
5

The problem is that OSM has many nodes and ways on the map, and many of them overlap. I don't know if there is any way to filter data with Nominativ, but you can filter data with Overpass.

First step is to determine what data you want. In example above it seems that you want soccer field. OSM doesn't have any metadata standard, so it depends of every contributor what metadata is written to each feature. You can see the most common tags that are used on taginfo website.

Second step is to write an Overpass query with bounding box location and key-value pairs of tags for data you wish to query, for example:

<osm-script output="json">
<query type="way">
  <bbox-query e="8.504" n="47.383" s="47.382" w="8.503"/>
  <has-kv k="leisure" v="pitch"/>
  <has-kv k="sport" v="soccer"/>
  <has-kv k="surface" v="grass"/>

</query>

<print/>
</osm-script>

You can write these kind of queries and test them at Overpass query form. When you're satisfied with result, you can convert it to to compact Overpass QL at the same website. You'll get something like:

[out:json];way(47.382,8.503,47.383,8.504)["leisure"="pitch"]["sport"="soccer"]["surface"="grass"];out;

URL link for that query would be:

http://www.overpass-api.de/api/interpreter?data=[out:json];way(47.382,8.503,47.383,8.504)["leisure"="pitch"]["sport"="soccer"]["surface"="grass"];out;

Third step is to save ID of feature (or features) in variable, and then you can use gimmeOSM (github.com/ustroetz/gimmeOSM) to get that feature as GeoJSON file, e.g.:

http://ustroetz.github.io/gimmeOSM/?wayID=168927595

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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