I want to measure the distance of a point(lat,long) to a the border of a Polygon. So I have created the polygon with the coordinates.

from shapely.geometry import Polygon, Point
Polygon(zip(lon_list, lat_list))

This gives me some value but no idea what it actually tells me (meters??). Any advice on how to get this. Any advice on how to calculate the distance from a point to the border of a polygon in Python properly? Or getting the closest point of the border from the starting point would also be more than enough.

  • 2
    You have properly computed the distance from the point to the polygon's border. The unit of the result is the same as the unit of the your coordinates (it calculates the distance in a cartesian plane). So in your case in degrees. If you want the result in meters, you first need to reproject your data to a different coordinate reference system. – joris Oct 14 at 16:02
  • The projection is for sure an issue. but I can calc proper distances with haversine. bigger problem is, how to get the closest point on the border line? I can go through all the points of the polygon but how to find the coordinate... – flowoo Oct 15 at 11:44
  • Shapely can do that for you shapely.readthedocs.io/en/stable/manual.html#object.project – martinfleis Oct 15 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.