2
cs_buffer = cs.copy()
cs_buffer = cs_buffer.to_crs("epsg:25832")
cs_buffer.geometry = cs_buffer.geometry.buffer(40, single_sided=True)
cs_buffer = cs_buffer.to_crs("epsg:4326")

My code should do a single side buffer. The problem is, sometimes it makes the buffer on the wrong side. enter image description here

I think it is because of the wrong direction of the LINESTRING. As we can see the upper left one is correct. It catches the buildings. The right on is on the wrong side, it should get the upper buildings not the lower ones. Sometimes it is right sometimes it is not.

Is it possible to fix it?

Without Buffer it looks like this enter image description here

In this example it is also false. Left one is false, right one is correct. enter image description here

4
  • @BERA No, I just have the street data from OSM. Highways etc. These are my own roads.
    – coder338
    Commented Nov 30, 2022 at 9:20
  • But I dont know which buildings should be in. I only now that it should catch the right side. Like you see in the second picture there is clearly shown on which side it should stretch its buffer.
    – coder338
    Commented Nov 30, 2022 at 9:23
  • The result looks pretty right to me. The direction of the lines looks the same, not wrong. Commented Nov 30, 2022 at 9:27
  • Okey, maybe it is the same. But its the wrong direction in some cases. Is there a possibility where I get the building which are on the right side.?
    – coder338
    Commented Nov 30, 2022 at 9:34

1 Answer 1

1

You can decide where the one side buffer should appear, by adding a sign to the distance parameter, as in this brief example:

import geopandas
from shapely.geometry import LineString
import matplotlib.pyplot as plt

s = geopandas.GeoSeries(
    [  
        LineString([(1, 1), (1, 5), (5, 5)])        
    ]
)

fig, ax = plt.subplots()
s.plot(ax=ax, color='red', alpha=0.4)
#plot buffer of s, single side left(up) or right(down)
s.buffer(0.3,single_sided=True).plot(ax=ax, color='green', alpha=0.5)
s.buffer(-0.3,single_sided=True).plot(ax=ax, color='blue', alpha=0.5)
plt.show()

as mentioned in official docs https://shapely.readthedocs.io/en/latest/manual.html#object.buffer

1
  • Thanks for your answer, but That’s not the question. Problem is, that sometimes you need buffer at right and sometimes at left side. So hardcoding the side of the buffer won’t solve it…
    – coder338
    Commented Dec 2, 2022 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.