I heard about a new (to me) tool for viewing shapefiles on this site. It required the installation of basemap
which is a part of matplotlib
, but the installation turned out to be a little tricky. I found a solution at the blog, I Lessen Data, which pointed me to another interesting post on mapping, So You’d Like to Make a Map Using Python.
Installing Basemap
Your gut reaction is to use sudo pip install basemap
, but that doesn’t quite work. You have to call,
pip install basemap --allow-external basemap --allow-unverified basemap
An Example
I downloaded this zip-file containing soil data, and then executed the following code,
from mpl_toolkits.basemap import Basemap mp = Basemap(llcrnrlat=25, urcrnrlat=37, llcrnrlon=-107, urcrnrlon=-93, resolution='c') mp.drawmapboundary() mp.readshapefile(shapefile='~/Downloads/gsmsoil_tx/spatial/gsmsoilmu_a_tx',name='tc') ; savefig( "tx_soil_map.png", dpi=200 )
Or we can look at a smaller region by editing the llcrnrlat
etc. arguments. These stand for upper and lower, and right and left corner, latitudes and longitudes.
mp = Basemap(llcrnrlat=30, urcrnrlat=32, llcrnrlon=-103, urcrnrlon=-101, resolution='c') mp.drawmapboundary() mp.readshapefile(shapefile='~/Downloads/gsmsoil_tx/spatial/gsmsoilmu_a_tx',name='tc') ; savefig( "permian_soil_map.png", dpi=200 )
One thought on “Viewing Shapefiles Using Basemap in Python”
Comments are closed.