1

I am trying to re-project a NetCDF file to a uniform grid EPSG: 4326 and convert it to a TIFF file. However, after the GDAL re-projection the values in the file change, i.e. the values are not retained after the re-projection takes place. The commands that I am using are:

gdal_translate HDF5:"LC08_L1TP_029037_20190611_20190611_01_RT_L2GEN_2.nc"://geophysical_data/Rrs_443 -a_nodata -32767 output.tif
gdalwarp -t_srs EPSG:4326 -srcnodata -32767 output.tif reprojected.tif

The links to the files are:

  1. NetCDF file: https://drive.google.com/open?id=1XKNOqf_-MIcgR-f_qBWP-92ZNP3pEsgj

  2. output.tif file: https://drive.google.com/open?id=1nMcMIRiOVyiwjc8tHegzRyHxn2K9762o

  3. reprojected.tif file: https://drive.google.com/open?id=1Uh_UfWkeiEDuwKvDp4qCTjyBh_Bra6cZ

5
  • 1
    When you reproject, you resample your data. So the values will not be the same at all locations. If you don't provide a resampling option (which you are not), gdalwarp uses 'nearest_neighbor' by default. This may be a poor choice depending on your application (for continuous data, it's almost always better to use bilinear, cubic, or similar interpolators).
    – Jon
    Commented Jun 18, 2019 at 18:57
  • Thanks Jon for the reply. I tried both the commands, bilinear and cubic resampling methods however, the values are not retained and change after the the conversion is done. gdal_translate HDF5:"LC08_L1TP_029037_20190611_20190611_01_RT_L2GEN_2.nc"://geophysical_data/Rrs_443 -r bilinear -a_nodata -32767 bilinear.tif. The link to bilinear.tif is: (drive.google.com/open?id=1V0yQu6LuAz8lLubKSWokRANs-ZCdQdOP)
    – npal
    Commented Jun 18, 2019 at 19:49
  • and the other command was: gdal_translate HDF5:"LC08_L1TP_029037_20190611_20190611_01_RT_L2GEN_2.nc"://geophysical_data/Rrs_443 -r cubic -a_nodata -32767 output1.tif and the link to output1.tif is: (drive.google.com/open?id=1LrUrUJ5lfHfqH1GpV46BrReCRwpNFfqM)
    – npal
    Commented Jun 18, 2019 at 19:49
  • 2
    You're missing the point: when you reproject, you resample your data! Reprojection does not simply deform the raster grid. It draws an entirely new grid (that is not aligned with the original). In order to fill in each new grid cell with the appropriate value, some kind of averaging (or interpolation) must be done using the overlapping old grid cells.
    – Jon
    Commented Jun 18, 2019 at 22:44
  • 1
    Jon I do not understand what you are trying to say. can you illustrate with an example?
    – npal
    Commented Jun 19, 2019 at 14:16

1 Answer 1

3

A raster is a set of cells that form a grid; each cell has a value. When you reproject a raster, you are re-drawing the grid to be aligned with a new projection. So, in the below figure, your original raster grid is shown in blue, and the reprojected grid is shown in red.

Right away you can see a problem--the grids do not align. So, for example, in the zoomed in portion, you can see that the black cell (which is part of the reprojected grid) actually overlaps five of the original grid cells (with values of 4, 0, 1, 2, and 1). So the question is: what value do we assign the cell with the question mark (?)?

That is where resampling comes into play. You must choose a method for combining the five contributing pixels to assing the value to ?. Default is "nearest neighbor", so the algorithm will assign the ? the value of the nearest blue cell (2 in this case). Or you could choose "average", which will simply average all the contributing blue cells to assign ?. Or linear interpolation, or any of the many options gdal_translate provides.

The bottom line is that (and someone feel free to correct me here) it is impossible to have a reprojected image that has the same values as the original in each location (otherwise it would not be a reprojection). You must resample your data to the new grid.

enter image description here

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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