Beispiel #1
0
    uy = UY + R * refgeo[5]
    ly = uy + refgeo[5]
    r_start = int(round((uy - geo[3]) / geo[5]))
    r_end = int(round((ly - geo[3]) / geo[5]))

    for C in range(NX):
        lx = LX + C * refgeo[1]
        rx = lx + refgeo[1]
        c_start = int(round((lx - geo[0]) / geo[1]))
        c_end = int(round((rx - geo[0]) / geo[1]))

        win = arr[r_start:r_end, c_start:c_end]
        countArray[R, C] = float(win.count()) / ((r_end - r_start) *
                                                 (c_end - c_start))
        if win.count() != 0:
            valueDic = ta.calcStat(win, metric, NoData)  # call the function
            for m in metric:
                arrayDic[m][R, C] = valueDic[m]

# set new geo
newGeo = (LX, refgeo[1], 0.0, UY, 0.0, refgeo[5])

# export arrays
driver = gdal.GetDriverByName('GTiff')

for m in metric:
    outFile = driver.Create(path + 'TextMetric_1km/' + f + '_' + m + '.tif',
                            NX, NY, 1, gdal.GDT_Float32)

    outFile.SetGeoTransform(newGeo)  # set the datum
    outFile.SetProjection(proj)  # set the projection
Beispiel #2
0
arr = b.ReadAsArray()
#arr = b.ReadAsArray(xoff=Xoff, yoff=Yoff, win_ysize=extent) # test subset

# extract information
geo = g.GetGeoTransform()  # get the datum
proj = g.GetProjection()  # get the projection
#shape = arr.shape        # get the image dimensions - format (row, col)
NoData = b.GetNoDataValue()  # get the NoData value
xsize = b.XSize
ysize = b.YSize

#geo = (geo[0]+Xoff*geo[1], geo[1], geo[2], geo[3]+Yoff*geo[5], geo[4], geo[5])  # adjust for the test subset
#xsize = extent
#ysize = extent

arr = ta.reScale(arr, MaxMin, level, NoData)

# define the extent of the grid
LX = (math.ceil((geo[0] - refgeo[0]) / refgeo[1])) * refgeo[1] + refgeo[0]
NX = int(((math.floor(
    ((geo[0] + geo[1] * xsize) - refgeo[0]) / refgeo[1])) - (math.ceil(
        (geo[0] - refgeo[0]) / refgeo[1]))))

UY = (math.ceil((geo[3] - refgeo[3]) / refgeo[5])) * refgeo[5] + refgeo[3]
NY = int(((math.floor(
    ((geo[3] + geo[5] * ysize) - refgeo[3]) / refgeo[5])) - (math.ceil(
        (geo[3] - refgeo[3]) / refgeo[5]))))

# create new arrays
arrayDic = {}
for m in metric: