简体   繁体   中英

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. 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?

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.

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 . 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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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