将多个编码多段线合并成一个编码多段线 [英] Merging multiple encoded polylines into one encoded polyline

查看:161
本文介绍了将多个编码多段线合并成一个编码多段线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将新的编码多段线与现有多段线合并,而不对整个多段线进行解码和重新编码。新的编码多段线将被上传到一个(linux)服务器,在那里我想将它附加到现有的折线上。



问题是,你不能只捣碎他们在一起。以下是一些可用的示例数据。我的希望是在PHP或shell脚本中找到/创建解决方案,但问题是,我没有足够的技术理解来解释编码的折线算法。

  41.386692,-73.475912 
41.424822,-73.375027
41.428292,-73.311173
41.426183, -73.254577
41.470168,-73.218532
41.498865,-73.155278
(是的,6分很容易,但它会更像7,000个坐标对)




  • 编码的前3个坐标对: yir {Fnwm_MimFquRuTanK

  • Last 3: s`z {Fbpb〜L {qGg`FkrDkjK

  • 全部6 : yir {Fnwm_MimFquRuTanKdLw`J {qGg`FkrDkjK



交互式折线编码器实用程序

编码的折线算法格式(你可以通过交互式编码器获得)
折线编码器


编辑:



我也有编码多段线的原始数据两端。所以我也可以分别保存第一个和最后一个坐标对。



有帮助的阅读:



一篇关于编码折线如何工作的更多细节的博文。您可以在这里阅读:什么是编码折线?

解决方案

好的,我想我已经明白了。非常感谢 Andrew Leach 解释算法在纯英文中的效果。



问题:将新的编码多段线与现有的编码多段线合并


$ b 解决方案:保留现有多段线的最后一个坐标对,对该对进行编码并保存以备后用,在此新编码开始时用现有多段线的坐标对所有新坐标进行编码。找到最后一个坐标对的字符串,并将其从新的编码折线中移除,并将新的编码折线粘贴到现有折线的背面上。

知道:编码所做的是计算偏移量(距离x,y的距离)并将该值转换为ASCII。问题是第一个坐标是从0,0开始计算的,所以如果你只是把两个编码的多段线组合在一起,你添加新的一个将不会从现有的偏移量,而是从0,0偏移,导致一个大的跳跃折线。我们需要做的是找出编码多段线中的哪些字符是从0,0的偏移量并将其删除。然后,您可以将新行添加到旧行中,并将其正确地偏移。



点击下面的链接查看全部内容,并且有很好的评论。另外,请让我知道,如果你看到任何地方的效率可以提高!



PasteBin:解决方案的PHP实现


I'm trying to merge a new encoded polyline with an existing polyline without decoding and reencoding the whole polyline. The new encoded polyline will be uploaded to a (linux) server where I would like to append it to the existing polyline.

The problem is, you can't just mash them together. Below is some sample data to play with. My hope is to find/create a solution in either PHP or a shell script but the problem is, I have no where near enough technical understanding to interpret the encoded polyline algorithm.

41.386692,-73.475912
41.424822,-73.375027
41.428292,-73.311173
41.426183,-73.254577
41.470168,-73.218532
41.498865,-73.155278
(Yes, 6 points are easy, but it's going to be more like 7,000 coordinate pairs)

  • First 3 Coordinate Pairs Encoded: yir{Fnwm_MimFquRuTanK
  • Last 3: s`z{Fbpb~L{qGg`FkrDkjK
  • All 6: yir{Fnwm_MimFquRuTanKdLw`J{qGg`FkrDkjK

Interactive Polyline Encoder Utility
Encoded Polyline Algorithm Format (you can get to this via Interactive Encoder)
Polyline Encoder

Edit:

I also have the original data that encoded the polylines on both ends. So I can also save the first and last coordinate pair separately.

Helpful Reads:

I ended up writing a blog post that has a lot more detail about how encoded polylines work. You can read it here: What is an Encoded Polyline?

解决方案

Ok, so I think I figured it out. Many thanks to Andrew Leach for explaining how the algorithm actually works in plain english.

Problem: Merging a new encoded polyline with an existing encoded polyline

Solution: keep last coord pair from existing polyline, encode just that pair and save it for later, encode all new coords with coord from existing polyline at the beginning of this new encoding. find the string of the last coordinate pair, and remove it from the new encoded polyline and stick the new encoded polyline onto the back of the existing polyline

Things to know: What the encoding does is calculate the offset (distance from x,y) and converts that value to ASCII. The problem is the first coordinate is calculated from 0,0 so if you were just to put two encoded polylines together, where you added the new one wouldn't be offset from the existing, but offset from 0,0 causing a large jump in the polyline. What we need to do is find out which characters in the encoded polyline are the offset from 0,0 and remove them. Then you can append the new line to the old line, and it will be offset properly.

Click the link below to see it all written up and with good comments. Also, please let me know if you see anywhere the efficiency can be improved!

PasteBin: PHP implementation of solution

这篇关于将多个编码多段线合并成一个编码多段线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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