-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let multi-layer geotiff files be cut via gdal_translate #5819
Conversation
While GMT can handle the cutting of images (including those straddling periodic boundaries) it cannot (yet) natively cut subsections out of multilayer data geotiff files. This PR allows such usage via grdcut by passing the baton to gdal_translate for getting subsections of such data files.
You need to use some create options otherwise the GeoTIFF files are uncompressed and huge. For floats maybe save in netCDF. See this function for the defaults I use in Julia https://github.com/GenericMappingTools/GMT.jl/blob/master/src/gdal_tools.jl#L214 |
OK, since this is geotiff's only I added compression. |
Right but notice that noting stops calling the output file lixo.nc and it become a geotiff disguised of netcdf. |
That is true. But not different from surface data -Goutput.txt or -Gshit.jpg, no? You get what you deserve. Yet, I can certainly add a check that the output file has to have .tif or tiff as well in this case. Note that if someone used +b to specify band 8 only of that geotiff then grdcut will obtain a grid instead of write a grid. |
The latest commits adds more checks and documentation:
Example commands that work for me to illustrate the usage: Grab layers 6,7,9 from a geotiff and write a subset to another geotiff: Select a single band from a geotiff and write a subset as a grid Select a single band from a geotiff and write a subset as another single-band geotiff |
Just to clarify one point. Modern GDALs pick the file format based on file extensions, so if extracting a float from one of those bands it would not be unreasonable to select a |
Right. But if you select a single float band and do not give a .tif extension, then we read in the layer as a grid and now the subset is written via gmt_nc.c and compression/tiling as per GMT settings. Are you concerned that someone might select 5 bands and give an output file as out.nc and if so we should pass a different driver etc. There is no netCDF inside a geotiff, right? I think writing multibands requires .tiff, no? |
And update the docs to say so, and make the wesn_new check more robust for longitudes.
Not concerned but having that possibility would be more generic. Multibands can be in netcdf too. For example this reads a multiband UInt16 in GeoTIFF, computes the radiance at the Top of Atmosphere (floats) and save it as a floats multiband in netcdf.
|
OK, so this is all via gdal_translate with the different (netCDF) driver? |
Not the |
I tested it and it works will. So I can do this: If extension is .nc or .grd (any others) then we switch to the netCDF driver and it will write that multi-layer netcdf. |
For the netcdf you need to set the compression level and better to set also the
or use |
Thanks, done. |
Let me know if there are other concerns with this branch, @joa-quim and @meghanrjones. It seems pretty stable to me now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good to me. It would be good to get Joaquim's approval too on this one.
Can't test it right now. In a middle of a long Julia notebook and testing requires kill everything in order to recompile GMT. |
It works but we have a problem with +b. It starts counting at 1 (like everybody should).
|
Remember to add 1 to band before passing to gdal_translate...
Yikes, OK fixed. |
This is the only place we call gdal_translate with band info so forgot. Elsewhere we know the drill, @joa-quim. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the +b is fixed it should be ready
While GMT can handle the cutting of images (including those straddling periodic boundaries) it cannot (yet) natively cut subsections out of multilayer data geotiff files. This PR allows such usage via grdcut by passing the baton to gdal_translate for getting subsections of such data files. The assumption is that such files are not global periodic files so this sophistication may not be needed in GMT. I updated the grdcut docs to list this capability as well.
I made a few other changes for the future:
No changes to gmt_gdalwrite.c at this time since no multi-layer float images will be sent to it.