First you will learn to get information about the geometries in your data with three different GeoSeries attributes and methods. Then you will learn to create a street map layer using folium. This is the Summary of lecture "Visualizing Geospatial Data in Python", via datacamp.
Note : Folium map doesn't embed this page correctly. So use nbviewer for interactive map link
import pandas as pd
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
from IPython.display import HTML, IFrame
plt.rcParams['figure.figsize'] = (10, 5)
How big is the Urban Residents neighborhood?
# Read in the neighborhoods geojson file
neighborhoods = gpd.read_file('./dataset/neighborhoods.geojson')
# Get just the Urban Residents neighborhood polygon and save it as urban_polygon
urban_polygon = neighborhoods.loc[neighborhoods.name == "Urban Residents"]
# Print the head of the urban polygon
print(urban_polygon.head())
# Create a copy of the urban_polygon using EPSG:3857 and print the head
urban_poly_3857 = urban_polygon.to_crs(epsg=3857)
print(urban_poly_3857.head())
# Print the area of urban_poly_3857 in kilometers squared
area = urban_poly_3857.geometry.area / 10**6
print('The area of the Urban Residents neighborhood is ', area.values, ' km squared')
name geometry 41 Urban Residents MULTIPOLYGON (((-86.78122 36.16457, -86.78205 ... name geometry 41 Urban Residents MULTIPOLYGON (((-9660441.281 4323289.005, -966... The area of the Urban Residents neighborhood is [1.12898961] km squared
The Urban Residents neighborhood is around 1.13 square km. That seems manageable for walking to see the public art!
Now you'll find the center point of the urban_poly_3857
and plot it over the polygon.
# Create downtown_cernter from urban_poly_3857
downtown_center = urban_poly_3857.geometry.centroid
# Print the type of downtown_center
print(type(downtown_center))
# Plot the urban_poly_3857 as ax and add the center point
ax = urban_poly_3857.plot(color='lightgreen', figsize=(7, 7));
downtown_center.plot(ax=ax, color='black');
plt.xticks(rotation=45);
<class 'geopandas.geoseries.GeoSeries'>
You can see the centroid of the Urban Residents neighborhood. Notice that latitude and longitude are in meters instead of degrees. In the next exercise you will calculate the distance in meters of each artwork from the centroid of the Urban Residents neighborhood.
In this exercise you will prepare a GeoDataFrame called art_dist_meters
with the locations of downtown art converted to meters using EPSG:3857. You will use art_dist_meters
in the next exercise to calculate the distance of each artwork from the center of the Urban Residents neighborhood in meters.
from shapely.geometry import Point
art = gpd.read_file('./dataset/public_art.csv')
art['geometry'] = art.apply(lambda x: Point(float(x.Longitude), float(x.Latitude)), axis=1)
center_point = art.geometry.centroid
from shapely.geometry import Point
# Create art_dist_meters using art and the geometry from art
art_dist_meters = gpd.GeoDataFrame(art, geometry=art.geometry)
art_dist_meters.crs='epsg:4326'
print(art_dist_meters.head(2))
# Set the crs of art_dist_meters to use EPSG:3857
art_dist_meters.geometry = art_dist_meters.geometry.to_crs(epsg=3857)
print(art_dist_meters.head(2))
# Add a column to art_meters, center
art_dist_meters['center'] = center_point
Title Last Name First Name \ 0 [Cross Country Runners] Frost Miley 1 [Fourth and Commerce Sculpture] Walker Lin Location Medium Type Description Latitude \ 0 4001 Harding Rd., Nashville TN Bronze Sculpture 36.12856 1 333 Commerce Street, Nashville TN Sculpture 36.16234 Longitude Mapped Location geometry 0 -86.8366 (36.12856, -86.8366) POINT (-86.83660 36.12856) 1 -86.77774 (36.16234, -86.77774) POINT (-86.77774 36.16234) Title Last Name First Name \ 0 [Cross Country Runners] Frost Miley 1 [Fourth and Commerce Sculpture] Walker Lin Location Medium Type Description Latitude \ 0 4001 Harding Rd., Nashville TN Bronze Sculpture 36.12856 1 333 Commerce Street, Nashville TN Sculpture 36.16234 Longitude Mapped Location geometry 0 -86.8366 (36.12856, -86.8366) POINT (-9666606.094 4318325.479) 1 -86.77774 (36.16234, -86.77774) POINT (-9660053.829 4322982.159)
art_dist_meters['center']
0 POINT (-86.83660 36.12856) 1 POINT (-86.77774 36.16234) 2 POINT (-86.78817 36.15790) 3 POINT (-86.79975 36.16202) 4 POINT (-86.78205 36.16215) ... 127 POINT (-86.82221 36.16510) 128 POINT (-86.73445 36.09082) 129 POINT (-86.66777 36.13469) 130 POINT (-86.78382 36.16527) 131 POINT (-86.79900 36.15896) Name: center, Length: 132, dtype: geometry
The art_dist_meters Data Frame has the location of each artwork and the center point of the Urban Residents neighborhood -- both using meters for distance.
Now that you have the center point and the art locations in the units we need to calculate distances in meters, it's time to perform that step.
import pprint
# Build a dictionary of titles and distances for Urban Residents art
art_distances = {}
for row in art_dist_meters.iterrows():
vals = row[1]
key = vals['Title']
ctr = vals['center']
art_distances[key] = vals['geometry'].distance(other=ctr)
# Pretty print the art_distances
pprint.pprint(art_distances)
{'12th & Porter Mural': 10583948.500651475, 'A Splash of Color': 10585357.160178259, 'A Story of Nashville': 10583565.969078569, 'Aerial Innovations Mural': 10579929.255218184, 'Airport Sun Project': 10570311.412935875, 'Andrew Jackson': 10583951.468665037, 'Angel': 10588435.041707946, 'Anticipation': 10583698.952539692, 'April Baby': 10586916.00892881, 'Arial Triangle [from the Gravity Series]': 10583398.52483797, 'Ariel': 10585905.336208293, 'Athena Parthenos': 10586065.827814262, 'Benedictio': 10577769.979416678, 'Bicycle Bus-Green Fleet': 10582635.68286198, 'Blowing Bubbles': 10588435.041707946, 'Breaking Bread': 10582634.392548595, 'Building a Positive Community': 10582136.29114304, 'Can-Do': 10582120.049094511, 'Chet Atkins': 10583602.67968694, "Children's Chairs For The Seasons": 10583565.969078569, 'Confederate Memorial': 10577769.979416678, 'Confederate Private Monument': 10585868.029575413, 'Confluence': 10585513.082652403, 'Cool Fences': 10579074.346806614, 'Dancing on Air': 10570372.644642536, 'Demonbreun Hill Mural': 10583908.579902012, 'Dragon Wall Mural': 10584123.478874767, 'Eastside Mural': 10581245.290643545, 'Ed and Bernice Johnson and Mary': 10583193.594816655, 'Edward Ward Carmack': 10583921.539018078, 'Flights of Fantasy': 10570344.379658109, 'Foliated Scroll': 10583565.969078569, 'Founding Fathers Cenotaph': 10584221.716760146, 'Founding of Nashville': 10583078.144842813, 'Furman Monument': 10577769.979416678, 'Gold Star Monument to World War I Veterans': 10586021.858499767, 'Gone Fishing': 10583591.376403218, 'Happy Times at The Arcade': 10583544.984285295, 'Headstones': 10581464.612607874, 'Hillsboro Village Mural': 10583854.405716073, 'History in Stained Glass': 10584221.716760146, 'I BELIEVE IN NASHVILLE 12 South': 10582156.834978476, 'I BELIEVE IN NASHVILLE East Nashville': 10580136.449174412, 'I BELIEVE IN NASHVILLE North Nashville': 10585239.187925545, 'In Concert': 10572751.806064371, 'Industry - The TVA Group': 10584680.719262363, 'Industry, Agriculture, Commerce, Statesmanship': 10583520.14461468, 'Isabella': 10583485.955582885, 'Isabelle and Calvin': 10584967.506033441, 'John L. Nolen Monument': 10577769.979416678, 'John W. Thomas': 10586021.858499767, 'Johnny Cash Mural': 10582628.289268441, 'La Storia della Terra': 10583565.969078569, 'Lane Motor Museum': 10577496.17633061, 'Les Paul Guitar Mural': 10582854.565917103, 'Library Doors': 10583565.969078569, 'Lightning Wire Fountain': 10583073.144394962, 'M&M Furniture-Riverside Village': 10580110.247643126, 'Major General William Bate Monument': 10577769.979416678, 'Maybelle Carter': 10582681.28994042, 'Migration': 10578647.940171225, 'Music City Center - Art Collection': 10582899.568035366, 'Nashville, A History through Maps and Aerial Views': 10583565.969078569, 'Oh, Roy': 10583134.666506412, 'Orpheus and Eurydice': 10582814.322708014, 'Our Past, Your Future': 10581513.854999846, 'Owen Bradley': 10583977.664424112, 'Paint Waterfalls': 10586050.17255176, 'Parthenon East Pediment': 10586039.029226098, 'Parthenon West Pediment': 10586086.185064087, 'Phillips Monument': 10577769.979416678, 'Phillips Toy Mart': 10589122.922370559, 'Phoenix': 10583193.594816655, 'Piecing It All Together': 10583583.83412909, 'Pioneer Family - The Mountain Group': 10583940.557855405, 'Polarbears with Snowballs': 10582948.623516602, 'President Andrew Johnson': 10583888.306385722, 'Raccoons and the Magic Horseshoes': 10588449.304129982, 'Rolf and Daughters Mural': 10585530.548435524, 'Rolling Hills': 10567500.082015224, 'Rose on 65th Street': 10583485.955582885, 'Roy Orbison Tribute Statue': 10583983.27808947, 'Safe Haven Family Shelter Mural': 10580722.202142382, 'Sam Davis': 10587219.534638887, 'Sam Davis of Tennessee': 10583957.687431902, 'Samaritan': 10588435.041707946, 'Sea Serpent': 10584599.331890862, 'Sergeant Alvin C. York': 10583831.406240454, 'Servant or Master': 10583295.262231264, 'Sir Draco Star (a.k.a Eli)': 10581769.904107656, 'Soldier and Farmer - The Equestrian Group': 10583980.483601985, 'Something in the Air': 10583345.067374147, 'St. George and the Maiden': 10588435.041707946, 'St. Vincent de Paul': 10585450.35995012, 'Statue of Dr. W. E. B. Dubois': 10586151.741414448, 'Stay Tuned': 10582208.784466524, 'Teacher and Student': 10587219.534638887, "Tennessee Confederate Women's Memorial": 10583808.163062796, 'Tennessee Falls': 10583749.204294588, 'Tennessee Korean War Memorial': 10583763.398102595, "Tennessee Vietnam Veteran's Memorial": 10583793.462008132, 'Tennessee WWII Memorial': 10584791.513626093, 'The Birth of Apollo': 10582837.385831947, 'The Flutist': 10582802.090989307, 'The Peace Monument': 10581938.152564157, 'The Prince': 10583565.969078569, 'The Readers': 10583393.872061776, 'The Recording Angel': 10582755.631360933, 'The Three Graces': 10584019.73571512, 'The Waterfall Mural': 10581643.66630736, 'Thomas Gleen Ryman': 10583110.04814488, 'Threshold': 10582893.378709938, 'Timeless': 10582989.494809307, 'Timothy Demonbreun': 10583247.956294278, 'Tomatoes': 10579771.420321863, 'Tommy Owen': 10587219.534638887, 'Two Musicians': 10581245.290643545, 'Untitled': 10589663.659840992, 'Vanderbilt University - Public Collection': 10584709.70990316, 'Various': 10582656.32923829, 'Victory': 10583866.220337586, 'Voices Gathering': 10583459.815030094, 'Volume': 10581771.247803846, 'Warner Monument': 10577769.979416678, 'Waveform: Pan American Blues': 10570399.600396495, 'We Are Our Stories': 10587812.786960982, 'Welcome to Flatrock': 10574716.19476862, 'Wind Reeds': 10570407.991440946, 'Women Suffrage Memorial': 10583921.539018078, 'Youth Opportunity Center-STARS Nashville - Peace Jam mural': 10585108.655408468, '[Cross Country Runners]': 10587219.534638887, '[Fourth and Commerce Sculpture]': 10583138.736775193}
In order to construct a folium map of the Urban Residents neighborhood, you need to build a coordinate pair location that is formatted for folium.
urban_polygon.crs = 'epsg:4326'
urban_polygon.crs
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
# Print the head of the urban_polygon
print(urban_polygon.head())
# Create urban_center from the urban_polygon center
urban_center = urban_polygon.to_crs(epsg=4326).centroid
# Print urban_center
print(urban_center)
# Create array for folium called urban_location
urban_location = [urban_center.y, urban_center.x]
# Print urban_location
print(urban_location)
name geometry 41 Urban Residents MULTIPOLYGON (((-86.78122 36.16457, -86.78205 ... 41 POINT (-86.77756 36.16128) dtype: geometry [41 36.161278 dtype: float64, 41 -86.777565 dtype: float64]
C:\Users\kcsgo\anaconda3\lib\site-packages\ipykernel_launcher.py:5: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """
Folium locations are arrays with latitude first. You just created a folium location from the center of the Urban Residents neighborhood.
In this exercise you will create a street map of downtown Nashville using folium.
import folium
# Construct a folium map with urban_location
downtown_map = folium.Map(location=urban_location, zoom_start=15, width=500, height=500)
# Display the map
downtown_map.save('./html/downtown_map.html')
#hide_input
IFrame(src='/chans_jupyter/assets/attach/downtown_map.html', width=500, height=500)
Folium locations are arrays with latitude first. You just created a folium location from the center of the Urban Residents neighborhood.
This time you will create the folium map of downtown and add the Urban Residents neighborhood area from urban_polygon.
urban_polygon['center'] = urban_polygon.loc[:, 'geometry'].centroid
C:\Users\kcsgo\anaconda3\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel. C:\Users\kcsgo\anaconda3\lib\site-packages\geopandas\geodataframe.py:831: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super(GeoDataFrame, self).__setitem__(key, value)
# Create array for called folium_loc from the urban_polygon center point
point = urban_polygon.center
folium_loc = [point.values.y, point.values.x]
# Construct a map from folium_loc: downtown_map
downtown_map = folium.Map(location = folium_loc, zoom_start = 15, width=500, height=500)
# Draw our neighborhood: Urban Residents
folium.GeoJson(urban_polygon.geometry).add_to(downtown_map)
downtown_map.save('html/downtown_map2.html')
#hide_input
IFrame(src='/chans_jupyter/assets/attach/downtown_map2.html', width=500, height=500)
Now that you have added the polygon for the Urban Residents neighborhood to your folium street map, it's time to add the locations of the art within the neighborhood. You can do that by creating folium markers. Each marker needs a location assigned. Use iterrows()
to loop through the data to grab the values you need.
# Create a GeoDataFrame from art and verify the type
art_geo = gpd.GeoDataFrame(art, crs=neighborhoods.crs, geometry=art.geometry)
# Spartially join neighborhoods with art_geo
neighborhood_art = gpd.sjoin(art_geo, neighborhoods, op='within')
# Create urban_art from neighborhood_art where the neighborhood name is Urban Residents
urban_art = neighborhood_art.loc[neighborhood_art.name == 'Urban Residents']
# Iterate through the urban_art and print each part of tuple returned
for row in urban_art.iterrows():
print('first part: ', row[0])
print('second part: ', row[1])
# Create a location and marker with each iteration for the downtown_map
for row in urban_art.iterrows():
row_values = row[1]
location = [row_values['Latitude'], row_values['Longitude']]
marker = folium.Marker(location=location)
marker.add_to(downtown_map)
downtown_map.save('html/downtown_map3.html')
first part: 1 second part: Title [Fourth and Commerce Sculpture] Last Name Walker First Name Lin Location 333 Commerce Street, Nashville TN Medium Type Sculpture Description Latitude 36.16234 Longitude -86.77774 Mapped Location (36.16234, -86.77774) geometry POINT (-86.77773999999999 36.16234) center POINT (-86.77773999999999 36.16234) index_right 41 name Urban Residents Name: 1, dtype: object first part: 4 second part: Title A Story of Nashville Last Name Ridley First Name Greg Location 615 Church Street, Nashville TN Medium Hammered copper repousse Type Frieze Description Inside the Grand Reading Room, this is a serie... Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 4, dtype: object first part: 21 second part: Title Chet Atkins Last Name Faxon First Name Russell Location Corner of Fifth Avenue North and Union Street,... Medium Bronze stool and guitar on a granite plynth Type Sculpture Description A sculpture of a young Chet Atkins seated on a... Latitude 36.16466 Longitude -86.78102 Mapped Location (36.16466, -86.78102) geometry POINT (-86.78102 36.16466) center POINT (-86.78102 36.16466) index_right 41 name Urban Residents Name: 21, dtype: object first part: 22 second part: Title Children's Chairs For The Seasons Last Name McGraw First Name Deloss Location 615 Church Street, Nashville TN Medium Mixed Media - wood and paint Type Furniture Description chairs depicting the four seasons Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 22, dtype: object first part: 34 second part: Title Foliated Scroll Last Name Bloomer First Name Kent Location 615 Church Street, Nashville TN Medium Aluminum Type Frieze Description a contemporary adaptation of a classical folia... Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 34, dtype: object first part: 39 second part: Title Gone Fishing Last Name Cooper First Name Michael Location Church Street Park Medium Acrylic on Brick Type Mural Description Just having some fun with Trompe L'oeil balconies Latitude 36.16298 Longitude -86.78184 Mapped Location (36.16298, -86.78184) geometry POINT (-86.78184 36.16298) center POINT (-86.78184 36.16298) index_right 41 name Urban Residents Name: 39, dtype: object first part: 40 second part: Title Happy Times at The Arcade Last Name Cooper First Name Michael Location In the Alley between 4th and 5th off of Union Medium Silicate paint on brick and concrete block Type Mural Description Trompe L'oeil artwork celebrating The Arcade Latitude 36.1647 Longitude -86.78043 Mapped Location (36.1647, -86.78043) geometry POINT (-86.78043 36.1647) center POINT (-86.78043 36.1647) index_right 41 name Urban Residents Name: 40, dtype: object first part: 54 second part: Title Johnny Cash Mural Last Name Bryan Deese, Audie Adams, Ryan Shrader First Name Location 300 4th Avenue Medium Latex paint and spray paint Type Mural Description Classic street art by Thoughts Manifested crew... Latitude 36.158301 Longitude -86.774955 Mapped Location (36.158301, -86.774955) geometry POINT (-86.77495500000001 36.158301) center POINT (-86.77495500000001 36.158301) index_right 41 name Urban Residents Name: 54, dtype: object first part: 55 second part: Title La Storia della Terra Last Name The Kubach - Wilmsen Team First Name The Kubach - Wilmsen Team Location Church St & 7th Ave N Nashville TN Medium Stone Type Sculpture Description A 20 foot tower of stone books. There are 26 b... Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 55, dtype: object first part: 57 second part: Title Les Paul Guitar Mural Last Name Hughes First Name Milree Location 100 Broadway, Nashville TN 37201 Medium Painting Type Mural Description Latitude 36.1624 Longitude -86.77491 Mapped Location (36.1624, -86.77491) geometry POINT (-86.77491000000001 36.1624) center POINT (-86.77491000000001 36.1624) index_right 41 name Urban Residents Name: 57, dtype: object first part: 59 second part: Title Library Doors Last Name LeQuire First Name Alan Location 615 Church Street, Nashville TN Medium Bronze Type Bronzes Description images of local people as well as Tennessee an... Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 59, dtype: object first part: 60 second part: Title Lightning Wire Fountain Last Name Walker First Name Lin Location 333 Commerce Street, Nashville TN Medium Type Sculpture/Fountain Description Latitude 36.16233 Longitude -86.7771 Mapped Location (36.16233, -86.7771) geometry POINT (-86.7771 36.16233) center POINT (-86.7771 36.16233) index_right 41 name Urban Residents Name: 60, dtype: object first part: 66 second part: Title Nashville, A History through Maps and Aerial V... Last Name Haas First Name Richard Location 615 Church Street, Nashville TN Medium Oil on Canvas Type Mural Description Eight scenes showing the development of Nashvi... Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 66, dtype: object first part: 67 second part: Title Oh, Roy Last Name Faxon First Name Russell Location 116 5th Ave N, Nashville TN Medium Bronze Type Sculpture Description Minnie Pearl and Roy Acuff seated on a bench i... Latitude 36.16151 Longitude -86.77816 Mapped Location (36.16151, -86.77816) geometry POINT (-86.77816 36.16151) center POINT (-86.77816 36.16151) index_right 41 name Urban Residents Name: 67, dtype: object first part: 68 second part: Title Orpheus and Eurydice Last Name Kaskey First Name Ray Location 1 Symphony Place, Nashville TN Medium Limestone Type Sculpture Description Relief sculpture above main entrance of Scherm... Latitude 36.16017 Longitude -86.77575 Mapped Location (36.16017, -86.77575) geometry POINT (-86.77575 36.16017) center POINT (-86.77575 36.16017) index_right 41 name Urban Residents Name: 68, dtype: object first part: 75 second part: Title Piecing It All Together Last Name Cooper First Name Michael Location 600 Church Street, Nashville TN Medium Painting on Stone Type Mural Description Latitude 36.16281 Longitude -86.78186 Mapped Location (36.16281, -86.78186) geometry POINT (-86.78185999999999 36.16281) center POINT (-86.78185999999999 36.16281) index_right 41 name Urban Residents Name: 75, dtype: object first part: 104 second part: Title The Birth of Apollo Last Name Eskridge First Name Casey Location 1 Symphony Place, Nashville TN Medium Bronze sculpture as centerpiece of fountain Type Sculpture Description Two figures topping a fountain, one with a lyr... Latitude 36.15993 Longitude -86.77611 Mapped Location (36.15993, -86.77611) geometry POINT (-86.77611 36.15993) center POINT (-86.77611 36.15993) index_right 41 name Urban Residents Name: 104, dtype: object first part: 105 second part: Title The Flutist Last Name Varo First Name Marton Location 1 Symphony Place, Nashville TN Medium Marble Type Sculpture Description Statue commemorating Kenneth D Schermerhorn, M... Latitude 36.15961 Longitude -86.77594 Mapped Location (36.15961, -86.77594) geometry POINT (-86.77594000000001 36.15961) center POINT (-86.77594000000001 36.15961) index_right 41 name Urban Residents Name: 105, dtype: object first part: 107 second part: Title The Prince Last Name Outlaw First Name Adrienne Location 615 Church Street, Nashville TN Medium Mixed Media Use of heavy guage aluminum wire a... Type Mobile Description The Little Prince\nOutlaw hung a whimsical mob... Latitude 36.16215 Longitude -86.78205 Mapped Location (36.16215, -86.78205) geometry POINT (-86.78205 36.16215) center POINT (-86.78205 36.16215) index_right 41 name Urban Residents Name: 107, dtype: object first part: 109 second part: Title The Recording Angel Last Name Flack First Name Audrey Location 1 Symphony Place, Nashville TN Medium Bronze Type Sculpture Description Bronze angel holding a fountain pen and tablet Latitude 36.1592 Longitude -86.77571 Mapped Location (36.1592, -86.77571) geometry POINT (-86.77571 36.1592) center POINT (-86.77571 36.1592) index_right 41 name Urban Residents Name: 109, dtype: object first part: 112 second part: Title Thomas Gleen Ryman Last Name Shields First Name Steve Location 116 5th Ave N, Nashville TN Medium Bronze sculpture with brick base Type Sculpture Description Full-length standing figure of Ryman, holding ... Latitude 36.16156 Longitude -86.77789 Mapped Location (36.16156, -86.77789) geometry POINT (-86.77789 36.16156) center POINT (-86.77789 36.16156) index_right 41 name Urban Residents Name: 112, dtype: object first part: 114 second part: Title Timeless Last Name Sorci First Name Joe Location 3rd Avenue North between Commerce and Broadway Medium Steel and Civil War cannonballs Type Sculpture Description Two nearly interlinked hemicycles with cannonb... Latitude 36.16227 Longitude -86.77631 Mapped Location (36.16227, -86.77631) geometry POINT (-86.77631 36.16227) center POINT (-86.77631 36.16227) index_right 41 name Urban Residents Name: 114, dtype: object
#hide_input
IFrame(src='/chans_jupyter/assets/attach/downtown_map3.html', width=500, height=500)
You have created a folium map of downtown Nashville, a polygon showing the Urban Residents neighborhood, and markers to show the location of the artworks. All that's left is to create some popups for the markers!
You will be building popups for the downtown art using the title
and desc
columns from the urban_art
DataFrame. Here, you will inspect those columns to identify and clean up any problematic values.
# Print the urban_art titles
print(urban_art.Title)
# Print the urban_art description
print(urban_art.Description)
# Replace Nan and ' values in description
urban_art.Description.fillna('', inplace=True)
urban_art.Description.str.replace("'", "`")
# Print the urban_art descriptions again
print(urban_art.Description)
1 [Fourth and Commerce Sculpture] 4 A Story of Nashville 21 Chet Atkins 22 Children's Chairs For The Seasons 34 Foliated Scroll 39 Gone Fishing 40 Happy Times at The Arcade 54 Johnny Cash Mural 55 La Storia della Terra 57 Les Paul Guitar Mural 59 Library Doors 60 Lightning Wire Fountain 66 Nashville, A History through Maps and Aerial V... 67 Oh, Roy 68 Orpheus and Eurydice 75 Piecing It All Together 104 The Birth of Apollo 105 The Flutist 107 The Prince 109 The Recording Angel 112 Thomas Gleen Ryman 114 Timeless Name: Title, dtype: object 1 4 Inside the Grand Reading Room, this is a serie... 21 A sculpture of a young Chet Atkins seated on a... 22 chairs depicting the four seasons 34 a contemporary adaptation of a classical folia... 39 Just having some fun with Trompe L'oeil balconies 40 Trompe L'oeil artwork celebrating The Arcade 54 Classic street art by Thoughts Manifested crew... 55 A 20 foot tower of stone books. There are 26 b... 57 59 images of local people as well as Tennessee an... 60 66 Eight scenes showing the development of Nashvi... 67 Minnie Pearl and Roy Acuff seated on a bench i... 68 Relief sculpture above main entrance of Scherm... 75 104 Two figures topping a fountain, one with a lyr... 105 Statue commemorating Kenneth D Schermerhorn, M... 107 The Little Prince\nOutlaw hung a whimsical mob... 109 Bronze angel holding a fountain pen and tablet 112 Full-length standing figure of Ryman, holding ... 114 Two nearly interlinked hemicycles with cannonb... Name: Description, dtype: object 1 4 Inside the Grand Reading Room, this is a serie... 21 A sculpture of a young Chet Atkins seated on a... 22 chairs depicting the four seasons 34 a contemporary adaptation of a classical folia... 39 Just having some fun with Trompe L'oeil balconies 40 Trompe L'oeil artwork celebrating The Arcade 54 Classic street art by Thoughts Manifested crew... 55 A 20 foot tower of stone books. There are 26 b... 57 59 images of local people as well as Tennessee an... 60 66 Eight scenes showing the development of Nashvi... 67 Minnie Pearl and Roy Acuff seated on a bench i... 68 Relief sculpture above main entrance of Scherm... 75 104 Two figures topping a fountain, one with a lyr... 105 Statue commemorating Kenneth D Schermerhorn, M... 107 The Little Prince\nOutlaw hung a whimsical mob... 109 Bronze angel holding a fountain pen and tablet 112 Full-length standing figure of Ryman, holding ... 114 Two nearly interlinked hemicycles with cannonb... Name: Description, dtype: object
C:\Users\kcsgo\anaconda3\lib\site-packages\pandas\core\generic.py:6245: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self._update_inplace(new_data)
Now you will assign a popup to each marker to give information about the artwork at each location. In particular you will assign the art title and description to the popup for each marker. You will do so by creating the map object downtown_map, then add the popups, and finally use the display function to show your map.
One warning before you start: you'll need to ensure that all instances of single quotes (') are removed from the pop-up message, otherwise your plot will not render!
downtown_map = folium.Map(location=urban_location, zoom_start=15, width=500, height=500)
folium.GeoJson(urban_polygon.geometry).add_to(downtown_map)
# Create popups inside the loop you built to create the markers
for row in urban_art.iterrows():
row_values = row[1]
location = [row_values['Latitude'], row_values['Longitude']]
popup = (str(row_values['Title']) + ': ' + str(row_values['Description'])[:20])
marker = folium.Marker(location = location, popup=popup)
marker.add_to(downtown_map)
downtown_map.save('./html/downtown_map4.html')
#hide_input
IFrame(src='/chans_jupyter/assets/attach/downtown_map4.html', width=500, height=500)