Snappy, gdal and numpy

Hello!

I’m trying to read a geotiff with gdal and write as BEAM-DIMAP.

Here’s the code:

import gdal
import numpy as np
import snappy

ls8 = 'LC08_L1TP_189034_20170910_20170927_01_T1_B1.TIF'
ds=gdal.Open(ls8)
nda=ds.ReadAsArray()

width = nda.shape[0]
height = nda.shape[1]

product = snappy.Product('titleI', 'title', width, height)
band = product.addBand('ndvi', snappy.ProductData.TYPE_UINT16)

writer = snappy.ProductIO.getProductWriter('BEAM-DIMAP')
product.setProductWriter(writer)
product.writeHeader('snappy_output.dim')
band.writePixels(0, 0, width, height, nda)

I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: no matching Java method overloads found

Any clue?

The problem was

band.writePixels(0, 0, width, height, nda)

and the solution is:

band.writePixels(0, 0, ds.RasterXSize, ds.RasterYSize, nda)

4 Likes