Python shapely: .equals function does not always work:
<p>I am having a few issues with the shapely library.
Now the equals function seem not to always work:</p>

<pre><code>poly1 =  Polygon(([220.0, 400, 500], [220.0, 20, 500], [220.0, 20, 0], [220.0, 400, 0], [220.0, 400, 500]))
poly2 =  Polygon(([220.0, 20, 500], [220.0, 400, 500], [220.0, 400, 0], [220.0, 20, 0], [220.0, 20, 500]))

print (poly1.equals(poly2))
</code></pre>

<p>Results with a false.
Any idea  why?</p>

<p>As @ewcz says in the comments, this is because Shapely only really works with 2D geometry in the XY plane.  It is ignoring the Z coordinate here.  These are not valid Polygons when projected into the XY plane so Shapely is not prepared to agree that they are equal.  It works fine if you remove the (unnecessary) x coordinate:</p>

<pre><code>from shapely.geometry import Polygon

poly1 =  Polygon(([220.0, 400, 500], [220.0, 20, 500], [220.0, 20, 0], [220.0, 400, 0], [220.0, 400, 500]))
poly2 =  Polygon(([220.0, 20, 500], [220.0, 400, 500], [220.0, 400, 0], [220.0, 20, 0], [220.0, 20, 500]))

print (poly1.equals(poly2)) # False

print poly1.is_valid  # False
print poly2.is_valid  # False

poly1 =  Polygon(([400, 500], [20, 500], [20, 0], [400, 0], [400, 500]))
poly2 =  Polygon(([20, 500], [400, 500], [400, 0], [20, 0], [20, 500]))

print (poly1.equals(poly2)) # True

print poly1.is_valid  # True
print poly2.is_valid  # True

poly1 =  Polygon(([220.0, 400], [220.0, 20], [220.0, 20], [220.0, 400], [220.0, 400]))
poly2 =  Polygon(([220.0, 20], [220.0, 400], [220.0, 400], [220.0, 20], [220.0, 20]))

print (poly1.equals(poly2)) # False

print poly1.is_valid  # False
print poly2.is_valid  # False
</code></pre>

python shapely