[gdal-dev] Cannot call InvGeoTransform due to too many values to unpack

Jacky Nguyen jackynguyen.km at gmail.com
Tue Jul 31 22:02:34 PDT 2018


I am learning Geo development. I am following the example from the book
'Geospatial Python Development'

I am stuck with the tutorial where it does the InvGeoTransform the raster
data (obtain the l10g here https://www.ngdc.noaa.gov/mgg/topo/gltiles.html
and the header file l10g.hdr from here
https://www.ngdc.noaa.gov/mgg/topo/elev/esri/hdr/)

The error that I received is: too many values to unpack at the line where
it does the InvGeoTransform()


The python code in the book is:

import sys, struct
from osgeo import gdal
from osgeo import gdalconst

minLat  = -48
maxLat  = -33
minLong = 165
maxLong = 179

dataset = gdal.Open("l10g")
band = dataset.GetRasterBand(1)

t = dataset.GetGeoTransform()
success,tInverse = gdal.InvGeoTransform(t)
if not success:
    print("Failed!")
    sys.exit(1)

x1,y1 = gdal.ApplyGeoTransform(tInverse, minLong, minLat)
x2,y2 = gdal.ApplyGeoTransform(tInverse, maxLong, maxLat)

minX = int(min(x1, x2))
maxX = int(max(x1, x2))
minY = int(min(y1, y2))
maxY = int(max(y1, y2))

width = (maxX - minX) + 1
fmt = "<" + ("h" * width)

histogram = {} # Maps elevation to number of occurrences.

for y in range(minY, maxY+1):
    scanline = band.ReadRaster(minX, y, width, 1,
                               width, 1,
                               gdalconst.GDT_Int16)
    values = struct.unpack(fmt, scanline)

    for value in values:
        try:
            histogram[value] += 1
        except KeyError:
            histogram[value] = 1

for height in sorted(histogram.keys()):
    print(height, histogram[height])


* when I do: gdalinfo l10g, i got this info:
Driver: EHdr/ESRI .hdr Labelled
Files: l10g
       l10g.hdr
Size is 10800, 6000
Coordinate System is `'
Origin = (90.000000000000497,-0.000000000000500)
Pixel Size = (0.008333333333000,-0.008333333333000)
Corner Coordinates:
Upper Left  (  90.0000000,  -0.0000000)
Lower Left  (  90.0000000, -50.0000000)
Upper Right ( 180.0000000,  -0.0000000)
Lower Right ( 180.0000000, -50.0000000)
Center      ( 135.0000000, -25.0000000)
Band 1 Block=10800x1 Type=Int16, ColorInterp=Undefined
  NoData Value=-500

* And my gdalinfo --version shows: GDAL 2.3.0dev, released 2017/99/99

Can anyone show me what the issue is?

Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180801/d0fb4876/attachment.html>


More information about the gdal-dev mailing list