I am correcting and cropping GeoTIFF DEM data using GDAL 2.4.0 to obtain the image raster. After doing my manipulations, I have the raster I want (checked by plotting with plt.imshow()), but while exporting/saving to a GeoTIFF the last hundred or so rows are cut off. Here is the exporting section of my script, let me know if you have any ideas as to why this is happening.

# Export and Save
print("Exporting file...")
crop_tiff = driver.Create(filename, ds_array.shape[1], ds_array.shape[0], 1, gdal.GDT_Float32) #Create new GeoTiff
crop_tiff.GetRasterBand(1).WriteArray(ds_array) #Write data
crop_tiff.FlushCache() #Flush and save.
print("Saving complete.")

My (correct) raster: Raster with correct bottom rows

The exported geoTIFF with error: Bad geoTIFF (notice the wonky rows at the bottom)

1 Answer 1


I ended up figuring this out! Apparently GDAL's FlushCache() method isn't always sufficient on it's own for saving, so all I needed to do was add

crop_tiff = None

at the end to properly clear the memory, and all was fixed. Frustrating, but simple!

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.