Writing out a product as GeoTIFF-BigTIFF


#1

Hi,

I’ve had success using the example files to open/read data from S2 tile products then manipulate the data in python but now I am trying to write the data (+ metadata/geocoding) to GeoTIFF-BigTIFF I am getting an unattribute java nullpointerexception.

In brief my band/pixel writing code looks like this:

write out the band rasters to new products

        blended_tile_1 = Product(tile1_name + '_blended', 'reflectance',
                                 tile_width, tile_height)
        blendedTile_band = blended_tile_1.addBand(band_names[8],
                                                  ProductData.TYPE_FLOAT32)
        prodWriter = ProductIO.getProductWriter('GeoTIFF-BigTIFF')
        ProductUtils.copyGeoCoding(p1, blended_tile_1)
        blended_tile_1.setProductWriter(prodWriter)

Snappy_ndvi export failure
#2

??? why did that post?

   >     r8a = np.zeros(tile_width, dtype=np.float32)
        for y in range(tile_height):
            r8a = rad8a_1.readPixels(0, y, tile_width, 1, r8a)
            blendedTile_band.writePixels(0, y, tile_width, 1, r8a)

So for test purposes I am just transferring data from my input to a new output file and band. From the NDVI example I noticed I am missing a writeHeader call but this seemed to be specific to DIMAP.
Any ideas what I shold do / the problem with writing to GeoTIFF?


#3

Try using:

ProductIO.writeProduct(<Your product>, <Output path>, "GeoTIFF-BigTIFF")

#4

No, the writeHeader is also needed for GeoTiff. If I remember correctly. At least before writing the band data.
If you just want to copy bands, it is best practice to use ProductUtils.copyBand(…)
And than use ProductIO.writeProduct(…), what @Ciaran_Evans suggested.
If you want to compute something you might consider to implement an operator.
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/42041346/How+to+write+a+processor+in+Python


#5

Thanks for the advice and adding writeHeader did create a file stub but did not solve the problem. I am still getting a nullpointerexception when I attempt to wrote pixels to the band added to the product.

I actually need to modify the band data before writing out so copyBand and ProductIO.writeProduct(…) won’t work if I have not created my new band data in the product. I am finding the API confusing as there seem to be several different ways to write / set information. For instance in my example I thought I constructed a product with the name 'tile1_name + ‘_blended’ but the file created took the name from
blended_tile_1.writeHeader(‘snappy_test_output.tif’)


#6

Hi Marco,
OK the writeHeader is creating a file and I tried it also with BEAM-DIMAP and the header looked good. The behaviour is not linked to the GeoTIFF export as I get the same failure with DIMAP. I get an unattribute java nullpointerexception on the first attempt to ‘setPixels’

        > prodWriter = ProductIO.getProductWriter('BEAM-DIMAP')  #'GeoTIFF-BigTIFF')
        ProductUtils.copyGeoCoding(p1, blended_tile_1)
        blended_tile_1.setProductWriter(prodWriter)
        blended_tile_1.writeHeader('snappy_test_output.dim')    #tif')
        r8a = np.zeros(tile_width, dtype=np.float32)
        for y in range(tile_height):
            r8a = rad8a_1.readPixels(0, y, tile_width, 1, r8a)
            blendedTile_band.setPixels(0, y, tile_width, 1, r8a)

I have check all of the relevant variables (the ra8 array, the band object, tile_width) and all are valid, not null so i don’t know where the nullpointerexception is coming from. I’ve tried to follow the examples from other Forum messages about exporting using snappy and seem to be following the same API usage. I only copy an input band for test purposes, my goal is to write out altered pixel values.