import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature
import geopandas as gpd
%matplotlib inline
fname = "/volumes/repos/Aqueduct30Docker/notebooks/testing/samplefiles/testShape.shp"
# Using Cartopy
fig = plt.figure(figsize=(20, 100))
shape_feature = ShapelyFeature(Reader(fname).geometries(),
ccrs.PlateCarree(), facecolor='blue',edgecolor='red')
ax = plt.axes(projection=ccrs.Robinson())
extents = [-20,20,30,40]
ax.add_feature(shape_feature)
ax.coastlines(resolution='50m')
ax.set_extent(extents, crs=None)
# Using Geopandas
gdf = gpd.read_file(fname)
gdf.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f3bba00fdd8>
gdf
PFAF_ID | geometry | |
---|---|---|
0 | 231401 | POLYGON ((-7.399999999999979 37.17500000000003... |
1 | 231500 | (POLYGON ((-8.734722222222196 38.5000000000000... |
# using a Combination of Cartopy and Geopandas?
fig = plt.figure(figsize=(20, 100))
gdf = gpd.read_file(fname)
gdf = gpd.read_file(fname)
# PSEUDOCODE
ax = plt.axes(projection=ccrs.Robinson())
ax.addFeature(gdf)
0 POLYGON ((-7.399999999999979 37.17500000000003... 1 (POLYGON ((-8.734722222222196 38.5000000000000... Name: geometry, dtype: object
"\nax = plt.axes(projection=ccrs.Robinson())\nextents = [-20,20,30,40]\nax.add_feature(shape_feature)\nax.coastlines(resolution='50m')\nax.set_extent(extents, crs=None)\n"
<matplotlib.figure.Figure at 0x7f3bbc26e780>