{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import folium\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(\"./buildings_annarbor_coordinates.csv\") #reading the csv form the second notebook, with coordinates." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
indexIndexNumberStreet NameDetailsRegioncitystateAddressLatitudeLongitudeZipcodeCountryLink_AddressLink_Coordinates
001109East Ann StreetHoban BlockDAnn ArborMichigan109 East Ann Street, Ann Arbor, Michigan42.282549-83.74792848104United Stateshttps://www.google.com/maps?q=109%20East%20Ann...https://maps.google.com/?q=42.282549,-83.747928
111110East Ann StreetHoban BlockDAnn ArborMichigan110 East Ann Street, Ann Arbor, Michigan42.282346-83.74834348104United Stateshttps://www.google.com/maps?q=110%20East%20Ann...https://maps.google.com/?q=42.2823463,-83.7483426
221111East Ann StreetHoban BlockDAnn ArborMichigan111 East Ann Street, Ann Arbor, Michigan42.282541-83.74785048104United Stateshttps://www.google.com/maps?q=111%20East%20Ann...https://maps.google.com/?q=42.28254099999999,-...
331112East Ann StreetHoban BlockDAnn ArborMichigan112 East Ann Street, Ann Arbor, Michigan42.282345-83.74831648104United Stateshttps://www.google.com/maps?q=112%20East%20Ann...https://maps.google.com/?q=42.2823455,-83.7483163
441113East Ann StreetHoban BlockDAnn ArborMichigan113 East Ann Street, Ann Arbor, Michigan42.282516-83.74776148104United Stateshttps://www.google.com/maps?q=113%20East%20Ann...https://maps.google.com/?q=42.2825159,-83.7477...
\n", "
" ], "text/plain": [ " index Index Number Street Name Details Region city \\\n", "0 0 1 109 East Ann Street Hoban Block D Ann Arbor \n", "1 1 1 110 East Ann Street Hoban Block D Ann Arbor \n", "2 2 1 111 East Ann Street Hoban Block D Ann Arbor \n", "3 3 1 112 East Ann Street Hoban Block D Ann Arbor \n", "4 4 1 113 East Ann Street Hoban Block D Ann Arbor \n", "\n", " state Address Latitude Longitude \\\n", "0 Michigan 109 East Ann Street, Ann Arbor, Michigan 42.282549 -83.747928 \n", "1 Michigan 110 East Ann Street, Ann Arbor, Michigan 42.282346 -83.748343 \n", "2 Michigan 111 East Ann Street, Ann Arbor, Michigan 42.282541 -83.747850 \n", "3 Michigan 112 East Ann Street, Ann Arbor, Michigan 42.282345 -83.748316 \n", "4 Michigan 113 East Ann Street, Ann Arbor, Michigan 42.282516 -83.747761 \n", "\n", " Zipcode Country Link_Address \\\n", "0 48104 United States https://www.google.com/maps?q=109%20East%20Ann... \n", "1 48104 United States https://www.google.com/maps?q=110%20East%20Ann... \n", "2 48104 United States https://www.google.com/maps?q=111%20East%20Ann... \n", "3 48104 United States https://www.google.com/maps?q=112%20East%20Ann... \n", "4 48104 United States https://www.google.com/maps?q=113%20East%20Ann... \n", "\n", " Link_Coordinates \n", "0 https://maps.google.com/?q=42.282549,-83.747928 \n", "1 https://maps.google.com/?q=42.2823463,-83.7483426 \n", "2 https://maps.google.com/?q=42.28254099999999,-... \n", "3 https://maps.google.com/?q=42.2823455,-83.7483163 \n", "4 https://maps.google.com/?q=42.2825159,-83.7477... " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head(5)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "# Initialize map, from folium.\n", "m = folium.Map(location=[df['Latitude'][0], df['Longitude'][0]], zoom_start=12)\n", "\n", "\n", "# Add ESRI Satellite basemap\n", "esri_satellite = folium.TileLayer(\n", " tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',\n", " attr='Esri',\n", " name='Esri Satellite',\n", " overlay=False,\n", " control=True\n", ").add_to(m)\n", "\n", "# Add Google Hybrid basemap\n", "google_hybrid = folium.TileLayer(\n", " tiles='https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',\n", " attr='Google',\n", " name='Google Hybrid',\n", " overlay=False,\n", " control=True\n", ").add_to(m)\n", "\n", "#add Google maps\n", "google_maps = folium.TileLayer(\n", " tiles='https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',\n", " attr='Google',\n", " name='Google Maps',\n", " overlay=False,\n", " control=True\n", ").add_to(m)\n", "\n", "# Define color mapping for regions\n", "color_dict = {\n", " 'D': 'red',\n", " 'E': 'blue',\n", " 'N': 'green',\n", " 'W': 'orange'\n", "}\n", "\n", "# Create a FeatureGroup for each region\n", "feature_groups = {region: folium.FeatureGroup(name=f'Region {region}') for region in color_dict.keys()}\n", "\n", "\n", "# Add markers to the corresponding FeatureGroup\n", "for i, row in df.iterrows():\n", " popup_text = f\"\"\"\n", "
\n", " Address: {row['Address']}
\n", " Details: {row['Details']}
\n", " Direction: Open in Maps\n", "
\n", " \"\"\"\n", " marker_color = color_dict.get(row['Region'], 'black') # Default to black if Region is not in color_dict\n", " folium.Marker(\n", " location=[row['Latitude'], row['Longitude']],\n", " popup=popup_text,\n", " icon=folium.Icon(color=marker_color, icon=\"star\", prefix='fa')#, icon_size=(20, 15)\n", " ).add_to(feature_groups[row['Region']])\n", "# Create a legend HTML\n", "legend_html = '''\n", "
  Legend
\n", "     Region D (Downtown)
\n", "     Region E (East)
\n", "     Region N (North)
\n", "     Region W (West)
\n", "
\n", " '''\n", "\n", "# Add legend to map\n", "m.get_root().html.add_child(folium.Element(legend_html))\n", "\n", "\n", "\n", "# Add all FeatureGroups to the map\n", "for fg in feature_groups.values():\n", " fg.add_to(m)\n", "\n", "\n", "# Add LayerControl to the map\n", "folium.LayerControl().add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "m.save(\"buildings_ann_Arbor.html\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 2 }