[GIS] How to find a location is inside a country

latitude longitudenode-jsreverse-geocoding

Given a Country Code and a Lat Lng pair, I want to find whether it is inside that country or not? What is the way to do it? Is there an algorithmic way to do this? I can accept certain amount of error.

I am node.js to implement this. Currently I do API call for Google to find the Country of the point. https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse But that doesn't full fill my performance requirement.

Best Answer

Since you are using Node.js, you can use the Node.js module for GDAL. Get country outlines (e.g. GSHHS data set from here). Then simply script a point in a polygon algorithm using GDAL (several approaches are possible but a simple one is to test for an intersect between your point and the appropriate country polygon).

Related Question