简体   繁体   English

检测是否基于纬度/经度的多边形点

[英]Detect if point in Latitude/Longitude based Polygon

I'd like to detect, on the server side using C# only, whether a Latitude/Longitude based coordinate is within an area (polygon) made up of Latitude/Longitude based points. 我想在服务器端仅使用C#检测基于纬度/经度的坐标是否在由基于纬度/经度的点组成的区域(多边形)内。 I believe the right way to do this is raycasting, but maybe there is already a C# implementation out there as it's not trivial? 我认为这样做的正确方法是光线投射,但也许已经有一个C#实现,因为它不是微不足道的?

Also, I understand that SQL Server has some geometry function such as STIntersects but in order to use that I need both SQL Server 2008 running and every check would involve a database connection which is undesirable. 此外,我知道SQL Server有一些几何功能,如STIntersects但为了使用它,我需要运行SQL Server 2008,每次检查都涉及数据库连接,这是不可取的。

Since a sphere is a locally diffeomorphic to the plane, you can use any algorithm that works on the cartesian plane, eg this SO question . 由于球体是平面的局部微分形态,因此您可以使用任何在笛卡尔平面上工作的算法,例如此SO问题 You'll only have to do work translating coordinates if your polygon includes a pole. 如果多边形包含一个极点,您只需要完成平移坐标的工作。 Depending on your use case, maybe you can reject those inputs. 根据您的使用情况,您可以拒绝这些输入。

I putzed around on the internet for a bit and found this link . 我在互联网上闲逛了一下,发现了这个链接

The example is written in C, but looks like it could very easily be adapted to work with C# and Long/Lat coordinates. 该示例用C语言编写,但看起来很容易适应C#和Long / Lat坐标。 You would need to keep in mind the crossover lines though (NS/EW), and add code to compensate where necessary, either that or make a decimal conversion of the LatLong values before running the function (West and South are represented with values < 0). 您需要记住交叉线(NS / EW),并添加代码以在必要时进行补偿,或者在运行函数之前对LatLong值进行十进制转换(West和South用值<0表示) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM