I'm trying to find where multiple lines intersect a polygon for two different geodataframes:
from shapely.geometry import Polygon, LineString
import geopandas as gpd
polygon = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
line1 = LineString([(0.5, 0.5), (0.7, 0.7)])
line2 = LineString([(0.9, 0.9), (0.2, 0.6)])
poly_gdf = gpd.GeoDataFrame(geometry=[polygon])
line_gdf = gpd.GeoDataFrame(geometry=[line1, line2])
This is what the above geodataframes look like (one has a polygon and the other has two lines). It looks to me as if both lines intersect the polygon:
However, the intersect output is very confusing:
print(line_gdf.intersects(poly_gdf))
0 True
1 False
print(line1.intersects(polygon))
print(line2.intersects(polygon))
True
True
Why does the geopandas
intersect
method give a different output to the standard shapely
one?
I am using Python 3.5.3 and Geopandas 0.2.1 all on Anaconda.
print(line.intersects(polygon))
you're access a variable that isn't defined as far as I can see. You've definedline1
andline2
earlier in the code. I don't know why that would return True. – Paul Jul 10 '17 at 15:52print(line.intersects(polygon))
was a typo. I have updated the question to refer toline1
which is what I originally meant. – bgordon Jul 11 '17 at 17:18line_gdf.info
confirms that you only have a single geometry column. I'm stumped. I'll follow up if I find anything. – Paul Jul 11 '17 at 17:50