@@ -31,11 +31,23 @@ def sjoin(left_df, right_df, op='intersects', how='inner',
31
31
rsuffix : string, default 'right'
32
32
Suffix to apply to overlapping column names (right GeoDataFrame).
33
33
"""
34
+ original_op = op
35
+ original_how = how
34
36
allowed_hows = ('left' , 'right' , 'inner' )
35
37
if how not in allowed_hows :
36
38
raise ValueError ("How keyword should be one of %s, got %s"
37
39
% (allowed_hows , how ))
38
40
41
+ if op == "within" :
42
+ # within implemented as the inverse of contains; swap names
43
+ # This is done for efficiency reasons
44
+ op = 'contains'
45
+ left_df , right_df = right_df , left_df
46
+ if how == 'left' :
47
+ how = 'right'
48
+ elif how == 'right' :
49
+ how = 'left'
50
+
39
51
if left_df .crs != right_df .crs :
40
52
print ("Warning: CRS does not match" )
41
53
@@ -62,6 +74,11 @@ def sjoin(left_df, right_df, op='intersects', how='inner',
62
74
left = left_df .take (left_indices )
63
75
right = right_df .take (right_indices )
64
76
77
+ if original_op == 'within' : # switch back
78
+ left , right = right , left
79
+ n_left , n_right = n_right , n_left
80
+ how = original_how
81
+
65
82
if how in ('inner' , 'left' ):
66
83
del right [right ._geometry_column_name ]
67
84
index = left .index
0 commit comments