Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 429
Sounak Avatar asked May 23 '15 20:05

Sounak


People also ask

How do you determine if one polygon is entirely within another polygon?

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 do you check if a point is within a polygon Python?

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.

What is LineString in Python?

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.

What is Unary_union?

unary_union[source] Returns a geometry containing the union of all geometries in the GeoSeries .


1 Answers

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

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

   +----------------------------------+
   |                                  |
   |         +----------+             |
   |         |          |             |
   |         |          |             |
   |         |          |             |
   |         |          |             |
   |         |          |             |
   |         |    B     |             |
   |         |          |             |
   |         +----------+             |
   |                                  |
   |                                  |
   |   A                              |
   |                                  |
   +----------------------------------+
like image 144
chepner Avatar answered Oct 24 '22 09:10

chepner