计算iPhone应用程序的KML多边形的最近点 [英] Calculate nearest point of KML polygon for iPhone app

查看:74
本文介绍了计算iPhone应用程序的KML多边形的最近点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列自然保护区,需要使用KML数据中包含的坐标在地图上绘制为多边形叠加图.我在Apple网站上找到了一个教程,用于在地图实例上显示KML叠加层.

I have a series of nature reserves that need to be plotted, as polygon overlays, on a map using the coordinates contained within KML data. I’ve found a tutorial on the Apple website for displaying KML overlays on map instances.

问题在于保护区的大小差异很大-从一个小池塘到几百公里不等.结果,我无法使用中心点的坐标来找到最近的储量.相反,我需要计算储备多边形的最近点才能找到最近的点.使用KML中的数据-我将如何尝试实现这一目标?

The problem is that the reserves vary in size greatly - from a small pond right up to several hundred kilometers in size. As a result I can’t use the coordinates of the center point to find the nearest reserves. Instead I need to calculate the nearest point of the reserves polygon to find the nearest one. With the data in KML - how would I go about trying to achieve this?

我只设法找到另一个人问这个,没有人回答:(

I've only managed to find one other person ask this and no one had replied :(

推荐答案

嗯,根据您的需要,有几种不同的解决方案.所需的精度越高,所需的工作就越多.我喜欢Phil的meanRadius参数概念.这将使您大致了解哪个多边形最接近,并且非常容易计算.如果多边形为圆形",则此想法最有效.如果多边形的形状非常不规则,则这种想法会失去准确性.

Well, there are a couple different solutions depending on your needs. The higher the accuracy required, the more work required. I like Phil's meanRadius parameter idea. That would give you a rough idea of which polygon is closest and would be pretty easy to calculate. This idea works best if the polygons are "circlish". If the polygon are very irregular in shape, this idea loses it's accuracy.

从数学的角度来看,这是您想要做的.遍历所有多边形的所有点.计算从这些点到当前坐标的距离.然后,只需跟踪哪个是最近的即可.最后一个皱纹.想象一下两个点构成一个很长的线段.您位于距直线中点一米的位置.好了,到这两个点的距离非常大,而实际上您距离多边形非常近.您将需要计算从坐标到每个可能的线段的距离,可以按照以下概述的各种方式进行操作:

From a math standpoint, here is what you want to do. Loop through all points of all polygons. Calculate the distance from those points to your current coordinate. Then just keep track of which one is closest. There is one final wrinkle. Imagine a two points making a line segment that is very long. You are located one meter away from the midpoint of the line. Well, the distance to these two points is very large, while, in fact you are very close to the polygon. You will need to calculate the distance from your coordinate to every possible line segment which you can do in a variety of manners which are outlined here:

http://www.worsleyschool.net/science/files/linepoint/distance.html

最后,您需要问自己,我在多边形中吗?如果您距多边形上的点10米远,但实际上位于多边形内,则需要考虑这一点.最好的方法是使用射线投射算法:

Finally, you need to ask yourself, am I in any polygons? If you're 10 meters away from a point on a polygon, but are, in fact, inside the polygon, obviously, you need to consider that. The best way to do that is to use a ray casting algorithm:

http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm

这篇关于计算iPhone应用程序的KML多边形的最近点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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