Struggles with transparency

Added by John 7 months ago

Aloha.
I'm continuing to wok on an animation and have the following problem.

1. I'm converting a geotiff to have a transparent background value using gdalbuildvrt to set 0.0 to be transparent. This works.
2. When I use grdimage to overlay it, I get a background similar to the original image presumably because 0.0 is not the -Q NaN value.
3. Then I used gdal_translate to set the 0.0 to NaN and it produces nan instead of NaN
4.grdimage doesn't seem to pay attention to nan.

So., is there any workaround for this? I suppose I could find the code that looks for NaN and add an OR to include nan.

J.


Replies (7)

RE: Struggles with transparency - Added by Paul 7 months ago

What's the difference between nan and NaN in a binary file? There is only one. So I don't know what gdal_translate does. If by grdimage you mean grdimage -D<yourgeotiff> then there is no -Q being applied to an image. If you eman your geotiff serves as the input grid to grdimage then I dont know what GDAL reads and passes back to GMT in terms of its nan value.

RE: Struggles with transparency - Added by John 7 months ago

I guess I don't know. I'm depending on gdal to interpret this value and share it with GMT. Based on your response, I guess there is uncertainty. I don't know what's going on other than what gdalinfo says and what the GMT doc says. If I can isolate the GMT code that interprets the NaN value then perhaps I can be more constructive.

RE: Struggles with transparency - Added by Joaquim 7 months ago

From memory, GDAL doesn't use NaN by default to represent nodata, but it can. Anyway, what ever value is used to represent nodata GMT should be able to recognize it. Unless that value is not registered if file's metadata.
You can test it by doing a grd2xyz -sr and see if anything comes out. You can also use -d to set the nodata in GMT.

RE: Struggles with transparency - Added by John 7 months ago

Well, still stuck. gdal_translate apparently only changes the metadata value and does not alter the data. gdalwarp help says it will change it but doesn't change it from 0 to NaN using

gdalwarp -srcnodata 0 -dstnodata NaN x.tif x-trans.tif

It stays nodata=0. I don't know if this is a bug or if I am misunderstanding something. Frustratingly, Qgis does treat 0 as nodata and produces the desired transparency when I load the x-trans.tif in.

So, I need some way to get grdimage to treat 0 as NaN or to somehow set 0 to be replaced by NaN so grdimage will mask out the 0 pixels.

Regarding Paul's comment, I am not using grdimage -D so I expect -Q to be applied by grdimage.

Further thoughts are welcome.

RE: Struggles with transparency - Added by John 7 months ago

Success! grdclip does it.

gmt grdclip x.tif -Gx-clip.tif -Sb1/NaN

I'm giving up data in the 0-1 range but the result is what I'm trying for.

RE: Struggles with transparency - Added by Joaquim 7 months ago

GMT should recognize the nodata set by GDAL. If it doesn't than it's a bug that must be fixed. Can you make us available an example case?
Also noticed that -d is not available in grdimage so you can't try the -d<nodata> that should get you the same effect.

RE: Struggles with transparency - Added by Paul 7 months ago

The -d is for table data; see gridfile+n<nanvalue> for grids and presumably images (not sure).

(1-7/7)