Reputation: 1385
I'm identifying if a point locates within a polygon. I have a dataframe contains the points and another dataframe contains the polygons, so I want to spatial join them like:
gpd.sjoin(df_points, df_polygons, how = 'left')
I know the default is predicate=intersects
, but how do intersects
and within
differ? Which one should I use for my purpose?
Thanks
Upvotes: 6
Views: 18102
Reputation: 490
In short, within
requires that all of a geometry's points to be within the interior of the spatially joined geometry (and none on the exterior). Whereas intersects
allows some of a geometry's points to be on the exterior of a spatially joined geometry so long at least one of its points touches or is within the second geometry.
Here are some more formal definitions:
intersects: An object is said to intersect other if its boundary and interior intersects in any way with those of the other.
within: An object is said to be within other if at least one of its points is located in the interior and no points are located in the exterior of the other. If either object is empty, this operation returns False. This is the inverse of contains() in the sense that the expression a.within(b) == b.contains(a) always evaluates to True.
contains: An object is said to contain other if at least one point of other lies in the interior and no points of other lie in the exterior of the object. (Therefore, any given polygon does not contain its own boundary – there is not any point that lies in the interior.) If either object is empty, this operation returns False. This is the inverse of within() in the sense that the expression a.contains(b) == b.within(a) always evaluates to True.
Upvotes: 3
Reputation: 12439
The PostGIS Tutorial has some very good graphics that explain the different Spatial Joins.
Upvotes: 5