2

The title question is overly simplistic, but would accomplish what I am looking for. I have generated a clipped *.tif raster using gdal.Warp and a georeferenced satellite image:

OutTile = gdal.Warp(newRasterLocation, rasterSourceFile, cutlineDSName=shapefileSourceFile, cropToCutline=True, dstNodata = 0)

When I open this raster in a simple image viewer, I get something like this (case A): Case A - Raster Without Transparency

When I import this same raster into QGIS as a new layer, I see many regions where what I imagine would be centered around the darker spots, but not pure black values (or any one single color, case B): Case B - Raster With Transparency

If I uncheck the No Data Value indicator in the Transparency menu, the previously Case B image (with transparency holes) reverts to the Case A image.

What does the No Data Value check box control? I am thinking this is related to the dstNodata setting in the generation, but why would this affect more than one color? And why would toggling the No Data Value check box have any affect, if this was a property of the generated image?

(the image is a tree zoomed in, the dark spots are shadows. I am interested in this exclusively graphically, and don't plan on doing anything with the raster data other than showing the image).

1

You have set the nodata value / dstNodata to be 0. However, it seems like the value 0 has data. So that is why the shadow areas are treated as nodata. So I suggest you to change the nodata value to something like -9999 when running gdal.Warp.

2
  • 1
    That's what I was just about to say. The NoData value in the GeoTIFF header isn't the same type as the pixel so it can be set out of range but that will leave you with dark edges where the warping has no information for, if this is a problem set dstnodata to 255 as it's unlikely that you'd legitimately find these values. Another problem occurs with bilinear or cubic resampling where the peaks/dips of the warping algorithm go out of range with light to dark or dark to light cells are adjacent, try the resampling method Lanczos or average if you're still having problems. Sep 2 '20 at 3:19
  • Oh, I never thought of the 255 value! There could be cases but we can also choose 5000 or something more. When I get the blank frame, I clip it using inverse buffer.
    – wondim
    Sep 2 '20 at 3:29

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.