Problems Processing GeoTiff files

52 Views Asked by At

I am trying to generate a geoTiff file via the following code in python:

import osr
import sys
import numpy

file=sys.argv[1]




 ds = gdal.Open("/home/jason/new_wind_process/wx_process/"+file+".grib2")

 temp = ds.GetRasterBand(3).ReadAsArray()
 u = ds.GetRasterBand(4).ReadAsArray()
 v = ds.GetRasterBand(5).ReadAsArray()
 hs = ds.GetRasterBand(7).ReadAsArray()


 wnd = numpy.sqrt(u*u+v*v)

 driver = gdal.GetDriverByName('GTiff')
 outRaster = driver.Create("/home/jason/new_wind_process/wx_process/"+file+".tiff",ds.RasterXSize, ds.RasterYSize, 6, gdal.GDT_Float32)
 outRaster.SetGeoTransform(ds.GetGeoTransform())

 outband = outRaster.GetRasterBand(1)
 outband.WriteArray(wnd)
 outband.SetMetadata({'name': 'wnd'})

 outband = outRaster.GetRasterBand(2)
 outband.WriteArray(temp)
 outband.SetMetadata({'name': 'temp'})

 outband = outRaster.GetRasterBand(3)
 outband.WriteArray(u)
 outband.SetMetadata({'name': 'u'})

 outband = outRaster.GetRasterBand(4)
 outband.WriteArray(v)
 outband.SetMetadata({'name': 'v'})

 outband = outRaster.GetRasterBand(5)
 outband.WriteArray(hs)
 outband.SetMetadata({'name': 'hs'})

 outRasterSRS = osr.SpatialReference()
 outRasterSRS.ImportFromEPSG(4326)
 outRaster.SetProjection(outRasterSRS.ExportToWkt())
 outband.FlushCache()

Unforunately when trying to view this in leaflet I get the following errors:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'x')

which seems to indicate that the tiepoint is undefined.

The javascript code that generates the error is below:

const tiepoint = image.getTiePoints()[0];
const pixelScale = image.getFileDirectory().ModelPixelScale;
const geoTransform = [tiepoint.x, pixelScale[0], 0, tiepoint.y, 0, -1 *    pixelScale[1]];

How do I tweak the python code to resolve this issue?

0

There are 0 best solutions below