Prepare to calculate distances
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.
The art
data has been pre-loaded for you, along with urban_poly_3857
and center_point
, the center point of the Urban Residents neighborhood. A geometry column called geometry
that uses degrees has already been created in the art
DataFrame.
This exercise is part of the course
Visualizing Geospatial Data in Python
Exercise instructions
- Create a GeoDataFrame called
art_dist_meters
, using theart
DataFrame and the geometry column fromart
. Setcrs = 'epsg:4326'
since the geometry is in decimal degrees. Print the first two rows. - Now explicitly set the coordinate reference system to
EPSG:3857
forart_dist_meters
by usingto_crs()
. Print the first two rows again. - Add a column called
center
toart_dist_meters
, setting it equal tocenter_point
for every row .
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import packages
from shapely.geometry import Point
import geopandas as gpd
import pandas as pd
# Create art_dist_meters using art and the geometry from art
art_dist_meters = gpd.GeoDataFrame(art, geometry = ____.____, ____ = '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.____(____ = 3857)
print(art_dist_meters.head(2))
# Add a column to art_meters, center
art_dist_meters['____'] = center_point