14

Let's say we have the following point and polygon:

poly = Polygon([(0, 0), (2,8), (14, 10), (6,1)])
point = Point(4,4)

Because point lies within poly, the distance from the first to the latter will be zero (poly.distance(point) will return 0.0).

Is there a way to instead calculate the distance to the nearest edge?

Note: Effectively the same question as this, but desire a solution in Python, ideally with Shapely.

kuanb
  • 585
  • 2
  • 7
  • 18

1 Answers1

20

Compare the point to the polygon's exterior ring:

poly.exterior.distance(point)
sgillies
  • 9,056
  • 1
  • 33
  • 41