0

This is the code I have

fname = r"C:\Users\Kevin Abbot\Documents\W&OD Trail.shp"
shape_feature = ShapelyFeature(Reader(fname).geometries(),
                                ccrs.PlateCarree(), edgecolor='black')
ax.add_feature(shape_feature,zorder=10)

When I plot the map it shows nothing

Here is the code for the plot (note a lot of things are commented out

fig = plt.figure(figsize=(24,20),facecolor='white')

ax = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree())
#ax.set_extent([leftlon, rightlon, botlat, toplat]) ## Important
#ax.coastlines(zorder=0, facecolor='grey')
#ax.add_feature(cfeature.OCEAN,zorder=3, facecolor='teal')
#ax.add_feature(cfeature.LAKES,zorder=3, facecolor='teal')
#ax.add_feature(cfeature.COASTLINE,zorder=0, facecolor='grey')
#ax.add_feature(cfeature.STATES,zorder=0, facecolor='grey')
#ax.add_feature(cfeature.STATES,zorder=10, edgecolor='midnightblue')
fname = r"C:\Users\Kevin Abbot\Documents\W&OD Trail.shp"
shape_feature = ShapelyFeature(Reader(fname).geometries(),
                                ccrs.PlateCarree(), facecolor='black')
ax.add_feature(shape_feature,zorder=10)

####FrzRain#
"""
plt.tricontourf(c['lon'], c['lat'], c['index'],levels = 30, transform=ccrs.PlateCarree(),cmap='brg_r', zorder=2)
cbar = plt.colorbar(extend='neither', spacing='proportional',
                orientation='horizontal', shrink=1, format="%.0f")
cbar.set_label(r"Cycling Conditions", size=30)
cbar.set_ticks([0,15,22,30,38,50,60])
cbar.set_ticklabels(["Ideal Conditions","Slightly Unpleasent","Uncomfortable","Rough","Nearly Unridable","Unridable","Dangerous"])
cbar.ax.tick_params(labelsize=14)
"""
plt.savefig(r"FDMVARIF.png", dpi=300)
plt.show()

I manually add the same shapefile to arcgis pro and it loads in fine.. I don't know why it wont load in python. It is just a trail path so just a jagged line.

2
  • Try using geopandas which simplifies reading in the files and has a plotting function. geopandas.org/en/stable/docs/user_guide/mapping.html
    – Shawn
    Jun 23 at 19:00
  • Does your code produce an error? Side note: when you code it's best not to use spaces in your file names/paths. Use underscores or dashes (I've been told underscores are best, since dashes can be read as 'minus').
    – Binx
    Jun 23 at 19:29

1 Answer 1

0
import geopandas as gpd

fname = r"C:\Users\Kevin Abbot\Documents\W&OD Trail.shp"

shapefile = gpd.read_file(fname)

shapefile.plot(color="blue", figsize=(5,5))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.