Skip to content

Shapely error #3

Description

@mssmison

I'm running into this error:

ERROR:shapely.geos:TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point 96 320 at 96 320 Error: The operation 'GEOSDifference_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x00000268A8F91DF0>

Activity

  1. abey79 commented on Apr 15, 2021

    @abey79
    Member

    Hello, could you provide the exact command used as well as the image in question?

  2. mssmison commented on Apr 16, 2021

    @mssmison
    Author

    Hi,
    You bet!

    vpype hatched --levels 64 128 192 -s 0.5 -p 4 starwars.jpg layout a4 show

    starwars

  3. mssmison commented on Apr 22, 2021

    @mssmison
    Author
  4. abey79 commented on Apr 28, 2021

    @abey79
    Member

    Sorry for the response time.

    This plug-in is indeed not very robust and this crash happens when the computed "zone" are geometrically too complex. It wouldn't be very difficult to improve but this is unfortunately rather low in my priority list.

    The easiest way to deal with these errors is to use the --blur parameter, e.g.:

    vpype hatched --levels 64 128 200  -b 20 -p 4 -d starwars.jpg
    

    image

    Changing the levels can also help since the zone geometry is largely affected by them. Note that I use the -d parameter so hatched displays a "debug" view of the zones.

  5. mssmison commented on Apr 28, 2021

    @mssmison
    Author
  6. mariana-s-fernandes commented on Feb 18, 2022

    @mariana-s-fernandes
    Contributor

    Hi @abey79 I don't mind taking this one next. But I have no idea on the process to fix it. If you give me some lights I can pick this up and try to fix it

  7. abey79 commented on Feb 19, 2022

    @abey79
    Member

    @mariana-s-fernandes Honestly, I don't recall what I had in mind when I wrote the comment above. Basically these errors arise when the shape of the various zones become too complex and somehow result in some invalid Shapely polygon. Smoothing the input image helps by simplifying the zones and reducing the risk of them becoming invalid for Shapely.

    Properly handling this probably entails:

    1. Properly detecting the situation (e.g. checking for .valid at various steps, possibly identifying the nature of invalidity).
    2. Fixing the shape. This is much tricker and I don't think there is any single good way of doing it. Maybe doing a tiny bit of double buffer (with positive then negative offset)? Maybe delete some probably-useless, tiny polygons from the input?
  8. mariana-s-fernandes commented on Feb 19, 2022

    @mariana-s-fernandes
    Contributor

    I have run the code above using the new hatched version (with the shapely updates) and I don't get the error. But I will test with other examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions