[Solved] parallel_offset changes number of point in LineString(Shapely)

Shiv Krishna Jaiswal Asks: parallel_offset changes number of point in LineString(Shapely)

Code:
import matplotlib.pyplot as plt
import pandas as pd
from shapely.geometry import LineString
from shapely.geometry.base import JOIN_STYLE

path = [
    dict(x=0, y=0),
    dict(x=1, y=0),
    dict(x=2, y=0),
    dict(x=2, y=4),
    dict(x=2, y=6),
    dict(x=2, y=8),
]

path = pd.DataFrame(path)

a = LineString(path[['x', 'y']].to_numpy())
b = a.parallel_offset(1, side='right', join_style=JOIN_STYLE.mitre)

plt.plot(path.x, path.y, '*-', label='old')

x = b.xy[0]
y = b.xy[1]
plt.plot(x, y, '*-', label='new')

plt.axis('square')
plt.legend()
plt.show()

print(len(path),len(x))

We find that number of points in x is not same number of points in path. Is there a way to shift line segments parallel to itself while preserving the number of points on connected line-segment.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.