Created
October 28, 2015 17:09
-
-
Save alexrutherford/072ea05d98843789ccda to your computer and use it in GitHub Desktop.
Plot MultiPolygon adapted from http://stackoverflow.com/questions/15968762/shapefile-and-matplotlib-plot-polygon-collection-of-shapefile-coordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import shapefile | |
| sf = shapefile.Reader("data/test.shp") | |
| fig=plt.figure() | |
| ax=fig.add_subplot(111) | |
| for nshp in xrange(len(shapes)): | |
| ptchs = [] | |
| pts = np.array(shapes[nshp].points) | |
| prt = shapes[nshp].parts | |
| par = list(prt) + [pts.shape[0]] | |
| for pij in xrange(len(prt)): | |
| ptchs.append(Polygon(pts[par[pij]:par[pij+1]])) | |
| plt.plot(pts[par[pij:0],par[pij+1:1]]) | |
| ax.add_collection(PatchCollection(ptchs,edgecolor='white', linewidths=0.5)) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment