Skip to main content
2 of 2
added 162 characters in body
Joost Döbken
  • 377
  • 2
  • 5
  • 15

Python shapely intersection with buffer in meter

Having a line and a polygon, I use shapely to determine the intersection between the two with a defined buffer. Both the line and the polygon are in WGS84 coordinates, while the buffer is in meter.

from shapely.geometry import LineString, Polygon
polygon = Polygon([
    (51.9981816, 4.3677729),
    (51.9983431, 4.3683897),
    (51.9980583, 4.3685846),
    (51.9977777, 4.3687773),
    (51.9976163, 4.3681605),
    (51.9978555, 4.3679964),
    (51.9981816, 4.3677729)
])
line = LineString([
    (51.9976836984107, 4.368050461186726),
    (51.99757198557364, 4.368489603711765),
    (51.9973971301288, 4.3684738261236475)
])

Finding the intersection is easy:

line.intersection(polygon)

Finding the intersection with a buffer in degrees (because coordinates of the objects are in degrees):

line.intersection(polygon.buffer(0.2))

But how to find the intersection with a buffer in meters? I understand that Shapely is not aware of any coordinate reference system; also no area metric CRS is known (OceanoGraphy is globally).

Joost Döbken
  • 377
  • 2
  • 5
  • 15