What is the difference between Polygon.contains and Polygon.within?

Sounak picture Sounak · May 23, 2015 · Viewed 8.8k times · Source

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?

Answer

chepner picture chepner · May 23, 2015

They are inverse relationships: A contains B, and B is within A.

   >>> A.contains(B)
   True
   >>> B.within(A)
   True

   +----------------------------------+
   |                                  |
   |         +----------+             |
   |         |          |             |
   |         |          |             |
   |         |          |             |
   |         |          |             |
   |         |          |             |
   |         |    B     |             |
   |         |          |             |
   |         +----------+             |
   |                                  |
   |                                  |
   |   A                              |
   |                                  |
   +----------------------------------+