I have a big project depending on Shapely. When updating shapely from 1.7.1 to 1.8, I have an issue with parallel_offset . For some geometries, when expecting a LineString to be offset as a LineString, it creates a MultiLineString. I have not been able to identify why it works with some geometries and not with others; some geometries that are very similar don't show the same results. This causes many problems downstream in my code.
Digging in the Shapely source code, I feel like this might be an issue with GEOS. I haven't worked out if the versions of GEOS packaged with shapely are different between versions of Shapely.
Any insight on my problem would be much appreciated. I want to updated Shapely on this project, first from 1.7.1 to 1.8 to then transition to 2.0.
Below is a minimal reproduction of the problem:
import numpy as np
from shapely.geometry import LinearRing, LineString, MultiLineString
import matplotlib.pyplot as plt
from shapely import __version__
print(__version__)
pts = np.asarray([[809.29025038, -1.22445615],
[796.0907264, -1.6687565],
[783.00450305, -2.3655554],
[770.01539453, -3.28167197],
[757.11530794, -4.39201819],
[744.31233618, -5.66988749],
[731.59838634, -7.09504763],
[718.95727263, -8.64726633],
[706.39708795, -10.3095485],
[693.90973938, -12.06489905],
[681.48713404, -13.89146715],
[669.12927192, -15.77468556],
[656.82806011, -17.69674991],
[644.58349862, -19.64228367],
[632.37940165, -21.59348246],
[620.22386209, -23.53416048],
[608.10878704, -25.44651334],
[596.0260836, -27.31597382],
[583.97575177, -29.12554682],
[571.94969865, -30.8622837],
[559.93983134, -32.51323581],
[559.93983134, 32.51323581],
[571.94969865, 30.8622837],
[583.97575177, 29.12554682],
[596.0260836, 27.31597382],
[608.10878704, 25.44651334],
[620.22386209, 23.53416048],
[632.37940165, 21.59348246],
[644.58349862, 19.64228367],
[656.82806011, 17.69674991],
[669.12927192, 15.77468556],
[681.48713404, 13.89146715],
[693.90973938, 12.06489905],
[706.39708795, 10.3095485],
[718.95727263, 8.64726633],
[731.59838634, 7.09504763],
[744.31233618, 5.66988749],
[757.11530794, 4.39201819],
[770.01539453, 3.28167197],
[783.00450305, 2.3655554],
[796.0907264, 1.6687565],
[809.29025038, 1.22445615],
[809.29025038, -1.22445615]])
line = LineString(pts)
plt.plot(*line.xy, '+-', color='blue')
inside = line.parallel_offset(distance=2.6, side="right", resolution=0, join_style=3)
print(f"Inside offset is type {type(inside)}")
if isinstance(inside, LineString):
plt.plot(*inside.xy, '+-', color='orange')
elif isinstance(inside, MultiLineString):
plt.plot(*inside[0].xy, '+-', color='orange')
plt.plot(*inside[1].xy, '+-', color='green')
plt.show()
This is the expected output (with shapely=1.7.1):
1.7.1
Inside offset is type <class 'shapely.geometry.linestring.LineString'
This is the output with 1.8.5:
1.8.5
Inside offset is type <class 'shapely.geometry.multilinestring.MultiLineString'>

