Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using gdal_grid for spatial interpolation I have run across a problem: the nodata argument is ignored. The only solution I have found for this is to then use gdal_translate but it is rather cumbersome (see below). My bash scripting skills are very, very minimal. Can anyone suggest an improvement, like passing the outputted file directly to the next tool?

gdal_grid -zfield "D2012" \
-a invdist:power=2.0:smoothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=-9999 \
-txe 647822 651672 -tye 7535500 7537800 -outsize 77 46 \
-of GTiff -ot Float64 -l probe2004_2012 probe2004_2012.shp ./Output/temp.tiff
gdal_translate -stats -a_nodata -9999 -a_srs EPSG:3006 ./Output/temp.tiff ./Output/2012_IDW_2_50.tiff
rm ./Output/temp.tiff
share|improve this question
1  
The problem still exists(5th Dec 2013, gdal 1.10.1), nodata values are set to -9999 but the metadata for the file doesn't reflect this so that the -9999 values are treated as data. –  mercergeoinfo Dec 5 '13 at 10:16
    
They might be thinking of this as a default value to store in the array, while identifying that value as flag for nodata value is a separate function. That said, one would think that this might work: ######################## gdal_grid -co PROFILE=GDALGeoTIFF -co TIFFTAG_GDAL_NODATA=-9999 .... ############# but with gdal 11.1 it fails with "Warning 6: Driver GTiff does not support TIFFTAG_GDAL_NODATA creation option" –  Dave X Aug 4 at 19:27

2 Answers 2

As in your comment, the nodata=9999 values are used by the algorithm to set the values at the pixels, but the output file's nodata attribute is not set to identify these pixels as no-data pixels.

I posted a bug report at http://trac.osgeo.org/gdal/ticket/5605 and it looks like rouault fixed it with http://trac.osgeo.org/gdal/changeset/27565. Until you have an updated gdal_grid executable, you can use the workaround:

gdal_translate -a_nodata -9999 temp.tiff final.tiff 
share|improve this answer

I use a short Python function that sets the nodata value of an existing grid and so far this works well for me. I use it from within Python scripts but it could of course be wrapped into a stand-alone utility that accepts command-line arguments.

def setNodata(fPath, nodata):
  dataSet = gdal.Open(fPath, gdal.GA_Update)
  band = dataSet.GetRasterBand(1)
  band.SetNoDataValue(float(nodata))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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