2

Is it possible to set a range of values to nodata in a file? How?

I have some elevation models with incorrect values, down in the -15,000s. I could just clip the rasters along that edge, or apply some raster calculation to transform them to nodata, but that's a fair bit of monkeying around. It'd be nicer to just say "everything less than -100 is nodata" and not duplicate the 99.9% of the cells that are just fine to fix the bad ones.

In reading the GDAL Virtual Format Tutorial I see a ComplexSource option to add "a custom lookup table to transform the source values to the destination. ... following form: <LUT>[src value 1]:[dest value 1],[src value 2]:[dest value 2],...</LUT>

but when I try that it transforms all values, not just the ones within the range.

Min/max from source: Computed Min/Max=-16111.000,2618.000
VRT Lookup transform: <LUT>-32767:-10,-1000:-1</LUT>
Out min/max: Computed Min/Max=-5.000,-1.000

Am I doing it wrong, or is what I'm attempting simply not supported? (by any VRT construct, not necessarily just LUT). Is there some other method of setting a range to nodata that doesn't require duplicating files to get there?

Source data:http://www.viewfinderpanoramas.org/dem3/P07.zip (34MB, home page), any tile ending in W142.

1 Answer 1

2

In your LUT, create a range where everything less than -100 (i.e. -32768 to -101) is given a single value to set as NoData (i.e. -32768). All values in between will get assigned that single value. Then set valid min and max values equal to themselves and all values in between will get assigned the same value as each originally was. And if that makes no sense at all, as I'm having trouble articulating what I mean, see below...

<LUT>-32768:-32768,-101:-32768,-100:-100, 5000:5000</LUT>
     | values < -101 = -32768 |  values unchanged |

The vrt below worked for me:

<VRTDataset rasterXSize="1201" rasterYSize="1201">
  <SRS>GEOGCS[&quot;WGS 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNIT[&quot;degree&quot;,0.0174532925199433,AUTHORITY[&quot;EPSG&quot;,&quot;9108&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]</SRS>
  <GeoTransform> -1.4200041666666667e+02,  8.3333333333333339e-04,  0.0000000000000000e+00,  6.1000416666666666e+01,  0.0000000000000000e+00, -8.3333333333333339e-04</GeoTransform>
  <VRTRasterBand dataType="Int16" band="1">
    <NoDataValue>-3.27680000000000E+04</NoDataValue>
    <ComplexSource>
      <SourceFilename relativeToVRT="1">N60W142.hgt</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="1201" RasterYSize="1201" DataType="Int16" BlockXSize="1201" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="1201" ySize="1201" />
      <DstRect xOff="0" yOff="0" xSize="1201" ySize="1201" />
      <LUT>-32768:-32768,-101:-32768,-100:-100,5000:5000</LUT>
      <NODATA>-32768</NODATA>
    </ComplexSource>
  </VRTRasterBand>
</VRTDataset>
2
  • ...but has some limitations in ArcMap (10.2.1). The vrt will display and symbolize okay, but conversion and exports will scale all values, not just the lower range; e.g. input pixels of 252 and 1894 will turn into -2 and 5015. So do conversions with gdal_translate instead. Commented Mar 13, 2014 at 18:46
  • @matt possibly an issue with the older version of gdal that arcgis ships with.
    – user2856
    Commented Mar 14, 2014 at 8:47

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.