问题
I have two geoseries in the same crs. I want to extract from the geoseries_1 all the polygons touching any polygon of geoseries_2. In the documentation it says that geoseries are tested element-wise, so I do:
geoseries_1.touches(geoseries_2)
but the output is
0 False
1 False
2 False
...
569 False
597 False
598 False
Length: 599, dtype: bool
but I know some of the polygons of geoseries_1 are actually touching some polygons in geoseries_2 and if I do for example:
geoseries_1.touches(geoseries_2.geometry.iloc[0])), the result is:
0 True
1 True
2 False
...
569 False
597 True
598 False
Length: 599, dtype: bool
Is this the expected output? Am I misinterpreting the documentation? Thanks in advance!
回答1:
Yes, this is the expected (but sometimes surprising) behaviour: if you pass another GeoSeries as argument, the 'touches' operation is done element-wise (so first of geoseries_1 with first of geoseries_2, second of geoseries_1 with second of geoseries_2, ...).
So it does not the "for all elements in geoseries_1, check each element of geoseries_1" behaviour. That is more like a spatial join. But, unfortunately, GeoPandas does not support the 'touches' spatial relationships in its sjoin function
So what is the solution? This depends on the desired output: do you want to repeat the rows that have multiple matches? Or do you just want to have the list of touching polygons?
BTW: I recently opened an issue on github to propose disabling this automatic alignment (so at least the above would given an error if geoseries_1 and geoseries_2 don't have the same length and index): https://github.com/geopandas/geopandas/issues/750
来源:https://stackoverflow.com/questions/52050498/geopandas-touches-method-on-geoseries-does-not-work-as-i-expect