2

I want to write a code that has the Countrycode and Postcode as an input and the ouput are the streets that are in the given postcode using some apis that use GSM.

My tactic is as follows:

  1. I need to get the relation Id of the district. For Example 1991416 is the relation id for the third district in Vienna - Austria. It's provided by the nominatim api: http://nominatim.openstreetmap.org/details.php?place_id=158947085

  2. Put the id in this api url: http://polygons.openstreetmap.fr/get_wkt.py?id=1991416&params=0

  3. After downloading the polygon I can put the gathered polygon in this query on the overpass api

    ( way (poly: "polygone data") ["highway"~"^(primary|secondary|tertiary|residential)$"] ["name"];

    ); out geom;

And this gives me the streets of the searched district. My two problems with this solution are 1. that it takes quite a time, because asking three different APIs per request isn't that easy on ressources and 2. I don't know how to gather the relation Id from step one automatically. When I enter a Nominatim query like http:// nominatim.openstreetmap.org/search?format=json&country=austria&postalcode=1030 I just get various point in the district, but not the relation id of the searched district in order to get the desired polygone.

So my questions are if someone can tell my how I can get the relation_Id in order to do the mentioned workflow or if there is another, maybe better way to work this issue out.

Thank you for your help!

Best Regards Daniel

4

1 回答 1

3

假设您定义了一些相关标签以匹配相关关系,您可以将您的方法大大简化,简化为单个 Overpass API 调用。特别是,您根本不必求助于 using poly,即无需将关系转换为 lat/lon 对列表。如今,可以使用区域的概念来查询由方式或关系定义的多边形中的某些对象。请查看文档以获取有关区域的更多详细信息

为了获得关系 1991416 的匹配区域,我使用了 postal_code=1030 和 boundary=administrative 作为过滤条件。然后,您可以使用该区域在此特定多边形中搜索方式:

//uncomment the following line, if you need csv output
//[out:csv(::id, ::type, name)];

//adjust area to your needs, filter critera are the same as for relations
area[postal_code=1030][boundary=administrative]->.a;

// Alternative:  {{geocodeArea:name}} -> see
// http://wiki.openstreetmap.org/wiki/Overpass_turbo/Extended_Overpass_Queries

way(area.a)["highway"~"^(primary|secondary|tertiary|residential)$"]["name"];
(._;>;);out meta;

// just for checking if we're looking at the right area
rel(pivot.a);out geom;

试试立交桥涡轮链接: http: //overpass-turbo.eu/s/6uN

注意:并非所有方式/关系都有相应的区域,即适用某些区域生成规则(参见上面的 wiki 页面)。但是,对于您的特定用例,您应该没问题。

于 2014-12-12T17:34:46.073 回答