import osmnx as ox import folium from folium import GeoJson from folium.plugins import…
- User
import osmnx as ox import folium from folium import GeoJson from folium.plugins import MousePosition import geopandas as gpd
def download_building_footprints(place_name): """ Downloads building footprints for a specified place using OSMnx.
codeArgs: place_name (str): The name of the place (e.g., "Przysucha, Poland"). Returns: GeoDataFrame: A GeoDataFrame containing building footprints. """ print(f"Downloading building footprints for {place_name}...") tags = {'building': True} buildings = ox.geometries.geometries_from_place(place_name, tags=tags) # Ensure geometries are polygons (buildings) buildings = buildings[buildings.geometry.type.isin(['Polygon', 'MultiPolygon'])] print(f"Number of buildings downloaded: {len(buildings)}") return buildingsdef create_dark_mode_map(buildings_gdf, output_html='przysucha_buildings_dark_mode.html'): """ Creates a dark-mode-friendly interactive map with building footprints.
codeArgs: buildings_gdf (GeoDataFrame): GeoDataFrame containing building footprints. output_html (str): Filename for the output HTML map. """ # Get the centroid of the buildings to center the map centroid = buildings_gdf.geometry.unary_union.centroid m = folium.Map(location=[centroid.y, centroid.x], zoom_start=15, tiles='CartoDB Dark_Matter', # Dark tileset attr='CartoDB') # Function to style the buildings def style_function(feature): return { 'fillColor': '#1f78b4', 'color': '#ffffff', 'weight': 0.5, 'fillOpacity': 0.7, } # Convert GeoDataFrame to GeoJSON and add to the map folium.GeoJson( buildings_gdf, name='Buildings', style_function=style_function, tooltip=folium.GeoJsonTooltip(fields=[], aliases=[], labels=False) ).add_to(m) # Add Mouse Position plugin formatter = "function(num) {return L.Util.formatNum(num, 5);};" MousePosition( position='topright', separator=' | ', prefix='Coordinates:', lat_formatter=formatter, lng_formatter=formatter, ).add_to(m) # Add layer control folium.LayerControl().add_to(m) # Save the map to an HTML file m.save(output_html) print(f"Map has been saved to {output_html}") - Assistant