I'm trying to use shapely as simple cad kernel and have a problem with parallel_offset's robustness: Problem-GIST
When offsetting the geometry, it depends on the offset distance whether the transformation fails and I can not recognize any pattern.
I'm trying to use shapely as simple cad kernel and have a problem with parallel_offset's robustness: Problem-GIST
When offsetting the geometry, it depends on the offset distance whether the transformation fails and I can not recognize any pattern.
I copy/paste your code in Problem-GIST and printed a 'help' of lr.parallel_offset object at Python Console of QGIS:
>>>help(lr.parallel_offset)
Help on method parallel_offset in module shapely.geometry.linestring:
parallel_offset(self, distance, side, resolution=16, join_style=1, mitre_limit=5.0) method of shapely.geometry.polygon.LinearRing instance
Returns a LineString or MultiLineString geometry at a distance from
the object on its right or its left side.
Distance must be a positive float value. The side parameter may be
'left' or 'right'. The resolution of the buffer around each vertex of
the object increases by increasing the resolution keyword parameter or
third positional parameter.
The join style is for outside corners between line segments. Accepted
values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
JOIN_STYLE.bevel (3).
The mitre ratio limit is used for very sharp corners. It is the ratio
of the distance from the corner to the end of the mitred offset corner.
When two line segments meet at a sharp angle, a miter join will extend
far beyond the original geometry. To prevent unreasonable geometry, the
mitre limit allows controlling the maximum length of the join corner.
Corners with a ratio which exceed the limit will be beveled.
By using QuickWKT plugin of QGIS, I visualized your lr.wkt object:
As it can be observed at help text above, you were using a wrong number of parameters. So, with next two examples, it can be obtained results without any errors.
>>>z = lr.parallel_offset(0.005,'left', 0, 3, 1)
>>>print z.wkt
LINESTRING (0.05488261328927022 0.0009060448224045175, 0.05518144177521111 0.002717311359638088 ...
>>>z = lr.parallel_offset(0.005,'right', 0, 3, 1)
>>>print z.wkt
MULTILINESTRING ((0.06506147557456732 0.0007262150320763161, 0.06636616796948354 -8.829632181206102e-05,...
By using QuickWKT plugin again, results can be visualized with original layer:
Then, 'parallel_offset' method in module shapely.geometry.linestring works if it is used adequate parameters number.