Wednesday 31 July 2019

ValueError: array larger than output file, or offset off edge Python GDAL


I have been working on this iterator that would count instances where data conformed to a set of conditions over a number of rasters. I had people help me with other aspects of this script (Counting events from a GRIB raster), but now I have hit an error where the return is "ValueError: array larger than output file, or offset off edge", Which I can't seem to be able to work arround. The code is provided bellow. It requires the user to input the path to folder and provide a name for the output GeoTIFF raster. Files read are GRIB.


import gdal
import numpy
import osr
import os

del_mapa = str(input('Vpiši pot do datotek v obliki "C:\\Mapa1\\Mapa2\\...\\Zadnja mapa": '))
os.chdir(del_mapa)


pix_vel = 1000
#Defines pixel size
ime_rez = str(input("Poimenuj datoteko z rezultati: ") + ".tif")
#User can provide a name for the output picture
format = "GTiff"
driver = gdal.GetDriverByName(format)

vir_mere = gdal.Open('inca_20140101-0100.grb')
trans = vir_mere.GetGeoTransform()

geotrans0 = trans[0]
geotrans1 = trans[1]
geotrans3 = trans[3]
geotrans5 = trans[5]
#Extracts transformation data from one of the GRIBs
dst_ds = driver.Create(ime_rez, 401, 301, 1, gdal.GDT_CInt32)
dst_ds.SetGeoTransform([geotrans0, geotrans1, 0, geotrans3, 0, geotrans5])
#and pastes it directly into the newly created GeoTIFF
projInfo = vir_mere.GetProjection()
srs = osr.SpatialReference()

srs.ImportFromWkt(vir_mere.GetProjectionRef())

dst_ds.SetProjection(srs.ExportToWkt())

raster = numpy.zeros((401, 301), dtype=numpy.uint8)
dst_ds.GetRasterBand(1).WriteArray(raster)

def krog(baza,novi):
x = 0
while x < 25:

baza = gdal.Open(ime_rez)
if x < 10:
novi = gdal.Open('inca_20140101-%s00.grb') % ('0' + str(x))
#This should open the next file in line
if novi > 15 and novi < 25:
baza = baza + 1
else:
baza = baza + 0

elif x > 10:

# novi = gdal.Open('inca_20140101-%s00.grb') % (str(x))
if novi > 15 and novi < 25:
baza = baza + 1
else:
baza = baza + 0
x += 1
dst_ds.GetRasterBand(1).WriteArray(baza)
dst_ds = None


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...