0

I am interested in finding out duplicate shapely polygons having different points but covering the same area. For example, let assume I have 2 polygons:

poly1 = POLYGON((4 1, 30 1, 45 1, 45 6, 12 6, 4 1))

poly2 = POLYGON((4 1, 45 1, 45 6, 12 6, 4 1))

These 2 polygons are representing the same area on the plane but are considered different when I do some opertions on them, like these 2 polygons (individually) intersecting with a 3rd polygon.

3
  • Could you add a screenshot showing the polygons? So you want to find polygons which in any way overlap? This is not geopandas right? Have you tried intersects method? – BERA Dec 8 '20 at 17:47
  • 1
    @BERA thank you for your reply and interest. This code is a part of the task that I am working on. Sceenshot of it pretty cluttered. Yes I want to find out polygons which are the same but are being referred with different points. (I hope I am clear here). Nope, I did not use geopandas, I used only Shapely polygon. I want this check to be done beforehand I do intersects, as I am going to perform intersects with other polygons after this check. – Sash7 Dec 10 '20 at 9:26
  • 1
    Ok! Intersects (true or false return) is not the same as intersection (the geometry of the intersecting polygons), you know that right? Your code snippet is so short it is difficult to understand exactly what you are trying to do – BERA Dec 10 '20 at 9:36
3

You can use the equals method of your geometries (which will test if the objects coincide, without taking care of the coordinates order):

from shapely import wkt

poly1 = wkt.loads('POLYGON((4 1, 30 1, 45 1, 45 6, 12 6, 4 1))')
poly2 = wkt.loads('POLYGON((4 1, 45 1, 45 6, 12 6, 4 1))')

poly1.equals(poly2) # True
poly1.equals_exact(poly2, 0) # False, because coords aren't in the same order

Note that there is also a almost_equals method if you need it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.