Guest User

Untitled

a guest
Oct 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import sys, os
  2.  
  3. import rasterio
  4.  
  5. import geopandas as gpd
  6. africoverFile = r""
  7. inFolder = ""
  8.  
  9. allFiles = []
  10. for root, dirs, files in os.walk(inFolder):
  11. for f in files:
  12. if f[-3:] == "shp":
  13. allTifs.append(os.path.join(root, f))
  14.  
  15. for shp in allFiles:
  16. try:
  17. clipRaster(gpd.read_file(shp), rasterio.open(africoverFile), shp.replace(".shp", "_AFRICOVER.tif"))
  18. res = zonalStatistics(shp, africoverFile, rastType='C', unqVals=[0,1,2,3,4,5,6,7,8,9,10])
  19. final = gpd.DataFrame(res, columns = ["lc_%s" % x for x in [0,1,2,3,4,5,6,7,8,9,10]])
  20. final.to_csv(shp.replace(".shp", "_AFRICA_Zonal.csv"))
  21. except:
  22. print("something failed with %s" % shp)
Add Comment
Please, Sign In to add comment