I know the same question has been answered elsewhere; however, the solution did not work for me. I already have both of my objects as shapely geometry.polygon.Polygon objects. I have two objects that intersect clearly, but are returning False when I want to output whether they intersect (i.e., it should return True).
Coordinates of Poly1 = (-109.91824, 32.715309) (-109.97012, 32.70005) (-110.09524, 32.632911) (-110.24172, 32.605446) (-110.35159, 32.584083) (-110.47061, 32.571876) (-110.54995, 32.602394) (-110.55606, 32.666481) (-110.51028, 32.727516) (-110.4523, 32.782448) (-110.38516, 32.822121) (-110.26614, 32.840431) (-110.15017, 32.852638) (-110.05251, 32.849586) (-109.96401, 32.797706) (-109.91519, 32.758034) (-109.91824, 32.715309)
Coordinates of Poly2 = (-126.0, 43.0) (-103.0, 43.0) (-126.0, 26.0) (-103.0, 26.0) (-126.0, 43.0)
Notice that Poly2 is just a large rectangle. I essentially want to get every shapefile within this rectangle. It also might be helpful to note that Poly1 was read from a GIS shapefile. Poly2 was created by me using the following code:
p1 = geometry.Point(-126,43)
p2 = geometry.Point(-103,43)
p3 = geometry.Point(-126,26)
p4 = geometry.Point(-103,26)
pointList = [p1, p2, p3, p4, p1]
poly2 = geometry.Polygon(pointList)
Does anyone have any idea why this might be returning False when it should be returning true?
It is also important to note that poly1 is created as the jth row of a geopandas dataframe, but I have confirmed that the output of that is a geometry.polygon.Polygon object:
poly1 = gdf_i.geometry.iloc[j]
Lastly: For reference, that dark red shape right below Phoenix (overlayed on the orange shape) is Poly1. You can visually see that it definitely intersects with Poly2 (the bounds of the map).
Any help is appreciated. Thank you!
Edit: Code for intersection is as follows:
if poly2.intersects(poly1) == True:
gdf_j = gdf_i.iloc[j]