0

I have 8 rasters (GeoTIFF; LANDFIRE layers) that I need to stack into a multiband raster for use with downstream analyses (i.e., within FlamMap). I have a workflow using Python and ArcPy and would like to continue to do so for this task. I need to repeat that task for many locations, hence the desire to find a more automated solution.

All of the TIFFs have the 'correct' values before I stack them with arcpy.CompositeBands_management, but after compositing some of the nodata values change for the bands. But this only matters for one of the bands. This band is the only one that has categorical data, which it reports as text and a numerical code. This band reports nodata as 255, but in order for the downstream analyses to work this needs to be remain nodata or be reported as 99.

When I use the stack function from the raster package, the resultant stacked raster works and nodata remains nodata.

I'd prefer to keep everything within Python and ArcPy if possible. I've tried removing the other attribute information from this categorical TIFF, leaving just count and value. This did not work. Any ideas on why compositing changes nodata values or how to fix it?

1 Answer 1

1

You can speficy enviroment settings using arcpy. Specifically, there is a NoData setting. Adapted from the documentation:

Tools that honor the NoData environment will only process rasters in which the NoData value is valid.

Use this environment when the NoData value from your input must be transferred to your output raster. This setting allows you to specify the value you use as the NoData value in your output.

  • When using the ArcGIS Spatial Analyst extension, NONE is the preferred mapping method to use. This produces the same behavior as previous versions of ArcGIS.
  • PROMOTION is the safest mapping method, since the NoData value will never be lost. However, promoting the pixel depth of your raster will create an output that is twice as large in size.

The following NoData mapping techniques are used:

  • None—There will not be any NoData value rules in place. If your input and output have the same value range, NoData will be transferred over without any changes. However, if your value range changes, there will be no value for NoData in your output. This is the default method.
  • Maximum—The maximum value in the output data range will be used as your NoData value.
  • Minimum—The minimum value in the output data range will be used as your NoData value.
  • Map values up—The lowest value in the range will be promoted and the lowest will become NoData. If the data is unsigned, the value of zero will become one, the NoData value will be zero, and the rest of the values remain the same. If the data is signed, the lowest value in the range will be promoted and the lowest will become NoData. For example, with 8-bit signed integer data, -127 will become -126, and the NoData value will be -127.
  • Map values down—The NoData value will be the maximum value in the data range, the highest value of the data range will become one value less, and the rest of the values remain the same. For example, with 8-bit unsigned integer data, the NoData value will be 255, the value of 255 will become 254, and the rest of the values will remain the same.
  • Promotion—If there is a NoData value outside the input's data range, the pixel depth of the output will be promoted to the next available level, and NoData will take the maximum value in the new data range. For example, an 8-bit unsigned integer dataset that requires the 256 value to be NoData will be promoted to a 16-bit dataset and the maximum value will become NoData. If there is a NoData value within the input's data range to be written to the output, or if there isn't any NoData, the pixel depth will not be promoted. If there is a NoData value outside of the input's data range, the pixel depth will be promoted to the next available level, and the Nodata value will be the one specified by the user. For example, an 8-bit unsigned integer dataset that requires 256 as NoData will be promoted to a 16-bit dataset and value 256 becomes the NoData value. If the NoData value specified is within the input's data range, the pixel depth will not be promoted for the output.

I assume your bands have different NoData values and that is what is causing the change of values. Depending on the other values, you can choose one of the mapping methods described above to keep the required NoData values. To specify a mapping method using arcpy simply write in your script:

import arcpy

arcpy.env.nodata = "PROMOTION"  # change for other method if necessary
2
  • Using arcpy.env.nodata = "PROMOTION" resulted in the same output as the previous run. I did check the input GeoTiffs, they do have different NoData values, have all the same NoData value would be ideal.
    – nofunsally
    Aug 19, 2020 at 17:12
  • The above answer led me to look at the NoData values. I was using a curvy feature to clip the rasters before stacking. This led to the NoData values because the raster still had a rectangular extent (more to learn). Instead, I can just use a rectangle clipping feature and then this NoData issues is avoided.
    – nofunsally
    Aug 19, 2020 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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