Check if coordinate (lat/lng) is located close to the boarder of predefined country

Viewed 27

Given a pair of latitude and longitude values (coordinate), a country name (e.g. United States) and a radius (e.g. 10 km), I would like to check if the coordinate is located close to the border of the country (i.e. if (parts of) the border is located within the predefined radius).

My current approach is just an approximation and needs to call costly geocoding APIs: Using the radius, I'm "sketching" an artificial circle around the coordinate (not a full circle, but e.g. 16 points arranged in a circle) and check for each of the points via Geocoding API, if it is located in the predefined country.

Is there a smarter way to do this in Python?

1 Answers

Create a 10km buffer around the country border and then check if the point is within that polygon.

Any GIS tool or package will provide you with tools to do this. I would recommend PostGIS as it is robust and fast.

Related