如何检查位置是否在Silverlight Bing Maps控件中的MapPolygon中?

如何检查位置是否在Silverlight Bing Maps控件中的MapPolygon中?,第1张

概述我有一个MapPolygon,它覆盖了Silverlight Bing Maps控件上的某个区域, 我想知道一个特定的位置是否位于这个MapPolygon中. 我尝试了以下代码,它不会返回我想要的结果,因为它只检查测试位置是否是MapPolygon的顶点之一,并且不检查此位置是否包含在此MapPolygon中. polygon.Locations.Contains(new Location(thi 我有一个Mappolygon,它覆盖了Silverlight Bing Maps控件上的某个区域,
我想知道一个特定的位置是否位于这个Mappolygon中.

我尝试了以下代码,它不会返回我想要的结果,因为它只检查测试位置是否是Mappolygon的顶点之一,并且不检查此位置是否包含在此Mappolygon中.

polygon.Locations.Contains(new Location(this.Site.Latitude,this.Site.Longitude,this.Site.Altitude));

是否也可以确定两个Mappolygons是否相互交叉?

解决方法 polygon.Locations是定义多边形的点列表.

您必须创建一个方法来查找您的点是否在多边形内.

使用这样的东西(如果编译则不测试):

static bool PointInpolygon(LocationCollection polyPoints,Location point){    if (polyPoints.Length < 3)    {        return false;    }    bool insIDe = false;    Location p1,p2;    //iterate each sIDe of the polygon    Location oldPoint = polyPoints[polyPoints.Count - 1];    foreach(Location newPoint in polyPoints)    {        //order points so p1.lat <= p2.lat;        if (newPoint.Latitude > oldPoint.Latitude)        {            p1 = oldPoint;            p2 = newPoint;        }        else        {            p1 = newPoint;            p2 = oldPoint;        }        //test if the line is crossed and if so invert the insIDe flag.        if ((newPoint.Latitude < point.Latitude) == (point.Latitude <= oldPoint.Latitude)            && (point.Longitude - p1.Longitude) * (p2.Latitude - p1.Latitude)             < (p2.Longitude - p1.Longitude) * (point.Latitude - p1.Latitude))        {            insIDe = !insIDe;        }        oldPoint = newPoint;    }    return insIDe;}

并称之为:

if (PointInpolygon(polygon.Locations,new Location(this.Site.Latitude,this.Site.Altitude))){    //do something }
总结

以上是内存溢出为你收集整理的如何检查位置是否在Silverlight Bing Maps控件中的MapPolygon中?全部内容,希望文章能够帮你解决如何检查位置是否在Silverlight Bing Maps控件中的MapPolygon中?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004851.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存