The Docstring says:
Polygon.contains
Returns True if the geometry contains the other, else False
Polygon.within
Returns True if geometry is within the other, else False
How are they different?
The Docstring says:
Polygon.contains
Returns True if the geometry contains the other, else False
Polygon.within
Returns True if geometry is within the other, else False
How are they different?
They are inverse relationships: A
contains B
, and B
is within A
.
>>> A.contains(B)
True
>>> B.within(A)
True
+----------------------------------+
| |
| +----------+ |
| | | |
| | | |
| | | |
| | | |
| | | |
| | B | |
| | | |
| +----------+ |
| |
| |
| A |
| |
+----------------------------------+
a = Polygon([(0, 0), (100, 0), (100, 100), (0, 100)])
b = Polygon([(0, 0), (50, 0), (50, 50), (0, 50)])
print(a.within(b), b.within(a))
print(a.contains(b), b.contains(a))
Output
False True
True False
To the point:
contains is opposite condition of within
+----------------------------------+
| |
| +----------+ |
| | | |
| | | |
| | | |
| | | |
| | | |
| | B | |
| | | |
| +----------+ |
| |
| |
| A |
| |
+----------------------------------+
In above case: