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.

1 Answer 1


I copy/paste your code in Problem-GIST and printed a 'help' of lr.parallel_offset object at Python Console of QGIS:

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:

enter image description here

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:

enter image description here

Then, 'parallel_offset' method in module shapely.geometry.linestring works if it is used adequate parameters number.

  • Thanks for your effort. In fact not the missing parameters where the reason for my problem. But the geometry defect near the cutout causes problems when using the same offset thickness as cutout depth. The first time I recognized the geometry defect was in your answer.
    – haelo
    Jul 27, 2017 at 8:58

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.