This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Thursday, October 6, 2016

Plotting the fire perimeter from a shape file

There is very useful documentation related to plotting shape files on a basemap here: http://basemaptutorial.readthedocs.io/en/latest/shapefile.html

I needed to plot fire perimeter, plotted on this map of Idaho and shaded in red, on a basemap.
This is how I did it...

from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
## My file 
# Plot Fire Perimeter                               
perimiter = '160806'
p4 = m.readshapefile('[PATH]/perim_'+perimiter,'perim',drawbounds=False)
                           
patches   = []
for info, shape in zip(m.perim_info, m.perim):
      if info['FIRENAME'] == 'PIONEER' and info['SHAPENUM']==1772:
             x, y = zip(*shape) 
              #print info
              #m.plot(x, y, marker=None,color='maroon',linewidth=2)
              patches.append(Polygon(np.array(shape), True) )
              ax.add_collection(PatchCollection(patches, facecolor= 'maroon', alpha=.65, edgecolor='k', linewidths=1.5, zorder=1))

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.