绘制 OpenStreetMap 关系不会生成连续线

Plotting OpenStreetMap relations does not generate continous lines(绘制 OpenStreetMap 关系不会生成连续线)
本文介绍了绘制 OpenStreetMap 关系不会生成连续线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

全部,

我一直致力于编制全球所有 MTB 路线的索引.我是 Python 人,所以对于涉及的所有步骤,我都尝试使用 Python 模块.

我能够像这样从 OSM overpass API 获取关系:

from OSMPythonTools.overpass import Overpass天桥=天桥()def fetch_relation_coords(关系):rel = overpass.query('rel(%s); (._;>); out;' % 关系)返回 relrel = fetch_relation_coords(6750628")

我选择这个特定的关系 (6750628),因为它是导致不连续(或其他错误)图的几个关系之一.

我处理rel"对象来获取这样的 pandas.DataFrame:

elements = pd.DataFrame(rel.toJSON()['elements'])

元素"看起来像这样:

Elements pandas.DataFrame 包含关系"类型的行.(在这种情况下为 1),有几种方式"类型.和许多类型的节点".我的理解是我会使用关系".行,成员"列提取方式的顺序(指向节点),并使用该顺序以正确的顺序制作节点的纬度和经度列表(供以后在传单中使用),即顺序这会导致地图上的连续路径.

然而,事实并非如此.对于这种特殊的关系,我最终得到了以下情节:

如果我们将其与

在数据库中,我宁愿对节点进行排序,因为我可以使用它们即时制作 GPX 文件.但我想我确实用这种方法回答了我自己的问题,感谢@scai 将我引向这个方向.

All,

I have been working on an index of all MTB trails worldwide. I'm a Python person so for all steps involved I try to use Python modules.

I was able to grab relations from the OSM overpass API like this:

from OSMPythonTools.overpass import Overpass
overpass = Overpass()

def fetch_relation_coords(relation): 
    rel = overpass.query('rel(%s); (._;>;); out;' % relation)
    return rel

rel = fetch_relation_coords("6750628")

I'm choosing this particular relation (6750628) because it is one of several that is resulting in discontinuous (or otherwise erroneous) plots.

I process the "rel" object to get a pandas.DataFrame like this:

elements = pd.DataFrame(rel.toJSON()['elements'])

"elements" looks like this:

The Elements pandas.DataFrame contains rows of the types "relation" (1 in this case), several of the type "way" and many of the type "node". It was my understanding that I would use the "relation" row, "members" column to extract the order of the ways (which point to the nodes), and use that order to make a list of the latitudes and longitudes of the nodes (for later use in leaflet), in the correct order, that is, the order that leads to continuous path on a map.

However, that is not the case. For this particular relation, I end up with the following plot:

If we compare that with the way the relation is displayed on openstreetmap.org itself, we see that it goes wrong (focus on the middle, eastern part of the trail). I have many examples of this happening, although there are also a lot of relations that do display correctly.

So I was wondering, what am I missing? Are there nodes with tags that need to be ignored? I already tried several things, including leaving out nodes with any tags, this does not help. Somewhere my processing is wrong but I don't understand where.

解决方案

If I opt to just plot the different way on top of each other, I indeed get a continuous plot (index contains the indexes for all nodes per way):

In the Database I would have preferred to have the nodes sorted anyway because I could use them to make a GPX file on the fly. But I guess I did answer my own question with this approach, thank you @scai for tipping me into this direction.

这篇关于绘制 OpenStreetMap 关系不会生成连续线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multiprocessing on Windows breaks(Windows 上的多处理中断)
How to use a generator as an iterable with Multiprocessing map function(如何将生成器用作具有多处理映射功能的可迭代对象)
read multiple files using multiprocessing(使用多处理读取多个文件)
Why does importing module in #39;__main__#39; not allow multiprocessig to use module?(为什么在__main__中导入模块不允许multiprocessig使用模块?)
Trouble using a lock with multiprocessing.Pool: pickling error(使用带有 multiprocessing.Pool 的锁时遇到问题:酸洗错误)
Python sharing a dictionary between parallel processes(Python 在并行进程之间共享字典)