Ejemplo n.º 1
0
Dst_Array = dst.ReadAsArray()
print("Shape of distnation raster Before matching = " + str(Dst_Array.shape))

### Match the alignment of both rasters
NewRasterB = Raster.MatchRasterAlignment(src, dst)

NewRasterB_array = NewRasterB.ReadAsArray()
print("Shape of distnation  raster after matching = " +
      str(NewRasterB_array.shape))

message = "Error the shape of the result raster does not match the source raster"
assert NewRasterB_array.shape[0] == src_Array.shape[
    0] and NewRasterB_array.shape[1] == src_Array.shape[1], message

### Match the NODataValue

NewRasterB_ND = Raster.MatchNoDataValue(src, NewRasterB)

NoDataValue = NewRasterB_ND.GetRasterBand(1).GetNoDataValue()

assert src.GetRasterBand(
    1).GetNoDataValue() == NoDataValue, "NoData Value does not match"

# NewRasterB_ND_array =NewRasterB_ND.ReadAsArray()

# f = NewRasterB_ND_array[NewRasterB_ND_array == NoDataValue]
# g = src_Array[src_Array == NoDataValue]

#%%
Raster.SaveRaster(NewRasterB_ND, SaveTo)
Ejemplo n.º 2
0
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")