2

I am trying to use GDAL (2.0.0) Python API in Blender, but I am having some difficulties. I am trying to save geotiffs for :
- a 2D numpy array storing 32bits floats
- a 3 channels rgb numpy array of bytes [0-255].
When I do so in Python, I get two tiffs (a grayscale one that I can open in ImageJ, an RGB one I can open with anything) correctly geo-reference

The problem is that they have black strips in them, and it seems they are not at the same place everytime. In the console, I have several errors of the type:

ERROR 1: TIFFFillStrip:/home/.../test.tif: Invalid strip byte count 0, strip 269
...

The thing is that if I am using the code below to save the grayscale array, I get a correct image (not georeferenced), so I know the data array is correct

arr_2D_uint8 = arr_2D.astype(gdalnumeric.uint8)
gdalnumeric.SaveArray(arr_2D_uint8, filepath, format="GTiff")

Here is the code I use for the grayscale, which is similar for the rgb image:

srs = osr.SpatialReference()
srs.ImportFromEPSG(epsg_code)
driver = gdal.GetDriverByName('GTiff')
ds = driver.Create(filepath, Nx, Ny, 1, gdal.GDT_Float32) 
ds.GetRasterBand(1).WriteArray(arr_2D.astype(gdalnumeric.float32))
ds.SetGeoTransform( (NW_x, lx, rx, NW_y, ry, -ly) ) # define GeoTransform tuple : top left x, w-e pixel resolution, rotation, top left y, rotation, n-s pixel resolution
ds.SetProjection(srs.ExportToWkt())
ds = None

And here is an example image : Black strips in Gdal Python generated Geotiff

EDIT : Is anyone having the same issue ? I am now having the exact same problem but this time, trying to load a Geotiff. I am thinking this may come from a size limitation problem, since the geotiff I am trying to load is 3600 by 3000 pixels wide.

Do you think this may be causing the issue ? Else, does anyone have an explanation ? Do not hesitate if you need further descriptions.

  • Is there a specific reason you are using the deprecated gdalnumeric? – Kersten Jul 10 '15 at 10:42
  • @Kersten Not at all, I didn't know it was deprecated. Still, the problem happens when I use the other portion of code, ds = driver.Create(...) and ds.GetRasterBand(1).Write(...) . Using gdalnumeric, I can save the array as an image which contains no black strips. – Jonathan Chemla Jul 15 '15 at 7:08
  • It's interesting that the trouble begins exactly 1/2 way down the image ..that must be some kind of clue. Unfortunately I don't know what to recommend, however. – elrobis Aug 5 '15 at 15:35
  • Finally found out the problem only occurs on one of two machines. Answer given after. – Jonathan Chemla Sep 7 '15 at 9:38
0

I've finally found out the problem only occurs on one of two machines I can run it on. On a windows computer, the geotiff are well written to, with no black strips. On the Ubuntu computer, the problem persists.

In both cases, I am running the Python GDal geotiff generation from within a Blender script. I may have not correctly installed the GDAL Python wrappers in the Ubuntu case (in the Blender scripts folder), or maybe installed two versions of gdal which are concurrent.

Thanks for your help,

Jonathan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.