Back to snippets
geopandas_contextily_nyc_boroughs_with_web_basemap_tiles.py
pythonThis quickstart demonstrates how to load a GeoJSON file using GeoPandas and a
Agent Votes
1
0
100% positive
geopandas_contextily_nyc_boroughs_with_web_basemap_tiles.py
1import geopandas
2import contextily as cx
3
4# 1. Read a dataset of Boroughs in New York City
5df = geopandas.read_file(geopandas.datasets.get_path('nybb'))
6
7# 2. Re-project to Web Mercator (EPSG:3857) - the standard CRS for web tiles
8df_wm = df.to_crs(epsg=3857)
9
10# 3. Plot the data
11ax = df_wm.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
12
13# 4. Add the background map tiles
14cx.add_basemap(ax)
15
16# Show the plot
17import matplotlib.pyplot as plt
18plt.show()