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?
Perform line intersection tests for each pair of lines, one from each polygon. If no pairs of lines intersect and one of the line end-points of polygon A is inside polygon B, then A is entirely inside B.
How to check if a point is inside a polygon in Python. To perform a Point in Polygon (PIP) query in Python, we can resort to the Shapely library's functions . within(), to check if a point is within a polygon, or . contains(), to check if a polygon contains a point.
Geometry types A geometry type that represents a single coordinate with x,y and possibly z values. LineString ([coordinates]) A geometry type composed of one or more line segments. LinearRing ([coordinates]) A geometry type composed of one or more line segments that forms a closed loop.
unary_union[source] Returns a geometry containing the union of all geometries in the GeoSeries .
They are inverse relationships: A
contains B
, and B
is within A
.
>>> A.contains(B)
True
>>> B.within(A)
True
+----------------------------------+
| |
| +----------+ |
| | | |
| | | |
| | | |
| | | |
| | | |
| | B | |
| | | |
| +----------+ |
| |
| |
| A |
| |
+----------------------------------+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With