Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 630
Alex Avatar asked Nov 13 '22 09:11

Alex


1 Answers

Since a sphere is a locally diffeomorphic to the plane, you can use any algorithm that works on the cartesian plane, e.g. 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.

like image 99
bmm6o Avatar answered Nov 15 '22 06:11

bmm6o