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