使用开放街道地图获取特定邮政编码的街道 [英] Getting Streets of a specific postcode using Open Street Maps

查看:232
本文介绍了使用开放街道地图获取特定邮政编码的街道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个使用Countrycode和Postcode作为输入的代码,而输出则是使用一些使用GSM的api在给定邮政编码中的街道.

我的策略如下:

  1. 我需要获取地区的关系ID.例如1991416是维也纳第三区-奥地利的关系ID.它由nominatim api提供: http://nominatim.openstreetmap.org/details.php? place_id = 158947085

  2. 将ID放在此api网址中: http://polygons.openstreetmap.fr/get_wkt.py?id=1991416&params=0

  3. 下载多边形后,我可以在立交桥api上的此查询中放置收集的多边形

    ( 道路 (多边形:多边形数据") [高速公路"〜"^(主要|次要|第三|住宅)$"] [名称"];

    ); 外出

这给了我所搜索地区的街道.这个解决方案的两个问题是 1.这需要花费相当长的时间,因为在资源上,每个请求询问三个不同的API并不容易, 2.我不知道如何从第一步自动收集关系ID.当我输入诸如http://nominatim.openstreetmap.org/search?format=json&country=austria&postalcode=1030的Nominatim查询时,我只是得到该区域中的各个点,但没有按顺序获得搜索区域的关系ID获得所需的多边形.

因此,我的问题是,是否有人可以告诉我如何获取Relation_Id以执行上述工作流程,或者是否存在另一种更好的解决此问题的方法.

谢谢您的帮助!

最好的问候 丹尼尔

解决方案

假设定义了一些相关标签以匹配所讨论的关系,则可以大大简化方法,直到进行一次Overpass API调用.特别是,您根本不必求助于poly,即无需将关系转换为经纬度对的列表.如今,可以使用区域的概念来查询由方式或关系定义的多边形中的某些对象.请查阅文档以获取有关区域的更多详细信息.

要获取关系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;
 

在天桥Turbo链接上尝试一下: http://overpass-turbo.eu/s/6uN

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

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

解决方案

You can simplify your approach quite a bit, down to a single Overpass API call, assuming you define some relevant tags to match the relation in question. In particular, you don't have to resort to using poly at all, i.e. there's no need to convert a relation to a list of lat/lon pairs. Nowadays the concept of an area can be used instead to query for certain objects in a polygon defined by a way or relation. Please check out the documentation for more details on areas.

To get the matching area for relation 1991416, I have used postal_code=1030 and boundary=administrative as filter criteria. Using that area you can then search for ways in this specific polygon:

//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;

Try it on overpass turbo link: http://overpass-turbo.eu/s/6uN

Note: not all ways/relations have a corresponding area, i.e. some area generation rules apply (see wiki page above). For your particular use case you should be ok, however.

这篇关于使用开放街道地图获取特定邮政编码的街道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆