def function(args): A = args[0] func=np.abs path = args[1] B=GIS.MapAlgebra(A,func) GIS.SaveRaster(B,path)
def function(args): # argument a list of two components # first argument is the raster object [gdal object] A = args[0] # second argument is the path to save the resulted raster path = args[1] func = np.abs # first function B = raster.MapAlgebra(A, func) raster.SaveRaster(B, path)
#%% #files_list=os.listdir(folder_path) folder_path = evap_out_path new_folder_path="03Weather_Data/new/4km_f/new_evap/" #B=gdal.Open(folder_path+files_list[0]) #args=[B,func,new_folder_path+files_list[0]] #GIS.FolderCalculator(folder_path,new_folder_path,function) #%% soil raster dem_path="01GIS/inputs/4000/acc4000.tif" soil_path="01GIS/soil_type/TOLIMA_SUELOS_VF/soil_raster.tif" DEM=gdal.Open(dem_path) dem_A=DEM.ReadAsArray() # dst dst=gdal.Open(soil_path) dst_A=dst.ReadAsArray() # align dst_Aligned=GIS.MatchRasterAlignment(DEM,dst) dst_Aligned_A=dst_Aligned.ReadAsArray() #noval_Aligned=np.float32(dst_Aligned.GetRasterBand(1).GetNoDataValue()) # match dst_Aligned_M=GIS.MatchNoDataValue(DEM,dst_Aligned) dst_Aligned_M_A=dst_Aligned_M.ReadAsArray() GIS.SaveRaster(dst_Aligned_M,"00inputs/GIS/4000/soil_typeِِA.tif")
new_folder_path = "data/meteodata_prepared/new_evap/" # raster.FolderCalculator(folder_path,new_folder_path,function) """ in order to run the model all inputs have to have the same number of rows and columns for this purpose MatchRasterAlignment function was made to resample, change the coordinate system of the second raster and give it the same alignment like a source raster (DEM raster) """ soil_path = "Data/GIS/soil/4000/soil_raster.tif" DEM = gdal.Open(dem_path) dem_A = DEM.ReadAsArray() soil = gdal.Open(soil_path) soil_A = soil.ReadAsArray() # align aligned_soil = raster.MatchRasterAlignment(DEM, soil) # to check alignment of DEM raster compared to aligned_soil_A raster aligned_soil_A = aligned_soil.ReadAsArray() # nodatavalue is still different and some cells are no data value in the soil type raster but it is not in the dem raster # to match use Match MatchNoDataValue # match dst_Aligned_M = raster.MatchNoDataValue(DEM, aligned_soil) dst_Aligned_M_A = dst_Aligned_M.ReadAsArray() # save the new raster raster.SaveRaster(dst_Aligned_M, "Data/GIS/soil/4000/soil_type.tif") #raster.SaveRaster(dst_Aligned_M,"00inputs/GIS/4000/soil_typeِِA.tif")
import os os.chdir("F:/01Algorithms/HAPI/Examples/GIS") #%library import numpy as np import gdal import datetime as dt #import pandas as pd import Hapi.raster as GIS #import matplotlib.pyplot as plt #%% inputs RasterAPath = "Inputs/NewDEM.tif" RasterBpath = "Inputs/SWIM_sub_4647.tif" #%% """ Read the Input rasters """ # the source raster is of the ASCII format src = gdal.Open(RasterAPath) #src_Array = src.ReadAsArray() # read destination array dst = gdal.Open(RasterBpath) #Dst_Array = dst.ReadAsArray() NewRasterB = GIS.MatchRasterAlignment(src, dst) GIS.SaveRaster(NewRasterB, "Inputs/NewSWIMSubs.tif")