[988] Checking intersection between two Geodataframes
Certainly! To check if the polygons in the left GeoDataFrame intersect with the polygons in the right GeoDataFrame and create a new column with “yes” or “no” based on the result, you can use the intersection method from GeoPandas. Here’s how you can do it:
Python
import geopandas as gpd
# Assuming you have two GeoDataFrames: left_gdf and right_gdf
# left_gdf and right_gdf should be defined with their respective geometries
# Check for intersection between polygons in left_gdf and right_gdf
# and create a new column 'Intersection' with 'yes' or 'no'
left_gdf['Intersection'] = left_gdf['geometry'].apply(
lambda x: 'yes' if right_gdf['geometry'].intersects(x).any() else 'no'
)
# Print the updated left_gdf with the 'Intersection' column
print(left_gdf)
In the resulting GeoDataFrame, the ‘Intersection’ column will contain either “yes” or “no” based on whether the polygons intersect or not. Feel free to adapt this code to your specific use case! 🌐🗺️
浙公网安备 33010602011771号