import matplotlib.pyplot as plt
import geopandas
from cartopy import crs as ccrs
path = geopandas.datasets.get_path('naturalearth_lowres')
df = geopandas.read_file(path)
df['gdp_pp'] = df['gdp_md_est'] / df['pop_est']
crs = ccrs.AzimuthalEquidistant()
# This can be converted into a `proj4` string/dict compatible with GeoPandas
crs_proj4 = crs.proj4_init
df_ae = df.to_crs(crs_proj4)
df_ae.plot("gdp_pp", legend=True)
<AxesSubplot:>
fig, ax = plt.subplots(subplot_kw={'projection': crs})
ax.add_geometries(df_ae['geometry'], crs=crs)
<cartopy.mpl.feature_artist.FeatureArtist at 0x16d394d60>
crs_epsg = ccrs.epsg('3857')
df_epsg = df.to_crs(epsg='3857')
# Generate a figure with two axes, one for CartoPy, one for GeoPandas
fig, axs = plt.subplots(1, 2, subplot_kw={'projection': crs_epsg}, figsize=(10, 5))
# Make the CartoPy plot
axs[0].add_geometries(df_epsg['geometry'], crs=crs_epsg, facecolor='white', edgecolor='black')
# Make the GeoPandas plot
df_epsg.plot(ax=axs[1], color='white', edgecolor='black')
<GeoAxesSubplot:>
# perform a CRS projection in CartoPy, and then convert it back into a GeoPandas object
new_geometries = [crs_new.project_geometry(ii, src_crs=crs) for ii in df_ae['geometry'].values]
df_aea = geopandas.GeoDataFrame(df['gdp_pp'], geometry=new_geometries, crs=crs.proj4_init)
df_aea.plot()
<AxesSubplot:>
from shapely.geometry import Point
from geopandas import datasets, GeoDataFrame, read_file
from geopandas.tools import overlay
# NYC Boros
zippath = datasets.get_path('nybb')
polydf = read_file(zippath)
# Generate some circles
b = [int(x) for x in polydf.total_bounds]
N = 10
polydf2 = GeoDataFrame([
{'geometry': Point(x, y).buffer(10000), 'value1': x + y, 'value2': x - y}
for x, y in zip(range(b[0], b[2], int((b[2] - b[0]) / N)),
range(b[1], b[3], int((b[3] - b[1]) / N)))])
ax = polydf.plot()
polydf2.plot(ax=ax, cmap='tab20b')
<AxesSubplot:>
from geopandas.tools import overlay
newdf = overlay(polydf, polydf2, how="intersection")
newdf.plot(cmap='tab20b')
<ipython-input-55-baddc206fd3b>:2: UserWarning: CRS mismatch between the CRS of left geometries and the CRS of right geometries. Use `to_crs()` to reproject one of the input geometries to match the CRS of the other. Left CRS: EPSG:2263 Right CRS: None newdf = overlay(polydf, polydf2, how="intersection")
<AxesSubplot:>
newdf = overlay(polydf, polydf2, how="union")
newdf.plot(cmap='tab20b')
<ipython-input-56-fea2c1cf9500>:1: UserWarning: CRS mismatch between the CRS of left geometries and the CRS of right geometries. Use `to_crs()` to reproject one of the input geometries to match the CRS of the other. Left CRS: EPSG:2263 Right CRS: None newdf = overlay(polydf, polydf2, how="union")
<AxesSubplot:>
newdf = overlay(polydf, polydf2, how="identity")
newdf.plot(cmap='tab20b')
<ipython-input-57-68bb59f9203a>:1: UserWarning: CRS mismatch between the CRS of left geometries and the CRS of right geometries. Use `to_crs()` to reproject one of the input geometries to match the CRS of the other. Left CRS: EPSG:2263 Right CRS: None newdf = overlay(polydf, polydf2, how="identity")
<AxesSubplot:>
newdf = overlay(polydf, polydf2, how="symmetric_difference")
newdf.plot(cmap='tab20b')
<ipython-input-58-4b35a07ff172>:1: UserWarning: CRS mismatch between the CRS of left geometries and the CRS of right geometries. Use `to_crs()` to reproject one of the input geometries to match the CRS of the other. Left CRS: EPSG:2263 Right CRS: None newdf = overlay(polydf, polydf2, how="symmetric_difference")
<AxesSubplot:>
newdf = overlay(polydf, polydf2, how="difference")
newdf.plot(cmap='tab20b')
<ipython-input-59-7cf3797f3667>:1: UserWarning: CRS mismatch between the CRS of left geometries and the CRS of right geometries. Use `to_crs()` to reproject one of the input geometries to match the CRS of the other. Left CRS: EPSG:2263 Right CRS: None newdf = overlay(polydf, polydf2, how="difference")
<AxesSubplot:>
df = geopandas.read_file(geopandas.datasets.get_path('nybb'))
df = df.to_crs(epsg=3857)
import contextily as ctx
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
ctx.add_basemap(ax, zoom=12) # ontrol the detail of the map tiles using the optional zoom keyword
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
ctx.add_basemap(ax, url=ctx.providers.Stamen.TonerLite)
<ipython-input-68-64eb8a05729c>:2: FutureWarning: The "url" option is deprecated. Please use the "source" argument instead. ctx.add_basemap(ax, url=ctx.providers.Stamen.TonerLite)
import folium
map = folium.Map(location = [37.540726, -77.436050], tiles = "Stamen Terrain", zoom_start = 11)
map
map = folium.Map(location = [37.540726, -77.436050], tiles='OpenStreetMap' , zoom_start = 9)
map