I am attempting to iterate through dissolved_result and overlay them using how='intersection' to create a single output file that represents all of the input dissolved_results. I am struggling with how best to do that, this is what I have so far and the error I get.
All inputs are polygons/multipolygons.
Edit: added some links to snaps to show what I'm trying to do. I have these three shapes, I want to intersect them all at the end of this function.(One of them appears to have no features, they're just not visible at this scale.)
def usable(gdf, feature_gdf, zoom_level, shuffle_tiles=False):
feature_gdf = gpd.read_file(inshp)
feature_gdf = feature_gdf.to_crs(epsg=5070)
intermediate_result = gpd.GeoDataFrame()
for index, row in gdf.iterrows():
geometry = row['geometry']
tiles = list_tiles(geometry, zoom=zoom_level, shuf=shuffle_tiles)
for tile in tiles:
tile_bounds = mercantile.bounds(*tile)
tile_box = gpd.GeoSeries([box(*tile_bounds)], crs=gdf.crs)
tile_box = tile_box.to_crs(epsg=5070)
if feature_gdf.intersects(tile_box.unary_union).any():
intersected_features = feature_gdf[feature_gdf.intersects(tile_box.unary_union)]
buffered_features = intersected_features.copy()
buffered_features['geometry'] = buffered_features.buffer(buffer_distance)
tile_minus_buffered = tile_box.difference(buffered_features.unary_union)
tile_buffer = gpd.GeoDataFrame(geometry=tile_minus_buffered, crs=tile_box.crs)
intermediate_result = pd.concat([intermediate_result, tile_buffer], ignore_index=True)
else:
tile_gdf = gpd.GeoDataFrame(geometry=tile_box, crs=tile_box.crs)
intermediate_result = pd.concat([intermediate_result, tile_gdf], ignore_index=True)
# save_file(intermediate_result, 'result')
dissolved_result = intermediate_result.dissolve()
final_result = gpd.GeoDataFrame()
for index, row in dissolved_result.iterrows():
result = gpd.GeoDataFrame(geometry=[row['geometry']], crs=dissolved_result.crs)
final_result = gpd.overlay(final_result, result, how='intersection')
print(final_result.head())
Error (from final for-loop):
AttributeError: The CRS attribute of a GeoDataFrame without an active geometry column is not defined. Use GeoDataFrame.set_geometry to set the active geometry column.



