9

I have an RGB orthoimage that has black area instead of NoData, as pictured here: enter image description here

When I use the SetNull tool, it does remove the black area, however it then turns it into a grayscale orthoimage, which is not what I want.

enter image description here

I know that there is a way around this by using the Clip (Data Management) tool to clip the raster to itself and in there you can set the NoData value to be the value of the black cells (0). However, I am creating a workshop for students and I would like to use a less counterintuitive method.

There is of course the option of running the NoData tool on each band individually and then combining the three bands together, however I need to have a condition where band1, band2, and band3 all equal 0 to set that as NoData. Being able to do this in ModelBuilder would be ideal, but scripting it using ArcPy would also be good.

I am using ArcGIS 10.2 Desktop with Advanced License.

  • You say you are using "ArcGIS 10.2 Pro" but the ArcGIS Pro application was only released with ArcGIS 10.3 for Desktop. Can you edit your question to clarify what you are using, please? – PolyGeo Feb 19 '15 at 19:52
  • My apologies. I'm using ArcGIS 10.2 for Desktop with the Advanced license. – Alex McVittie Feb 19 '15 at 19:54
  • Thank you for asking this question. I have clients who come back to me all the time thinking there's something wrong with their imagery. – Wes Sep 18 '15 at 13:32
11

What you want to do is Set Raster Properties in a script or change it manually in ArcCatalog. This will not create a new raster or even take very long.

In python it's a bit tricky:

import sys, os, arcpy

InFolder = sys.argv[1]
arcpy.env.workspace = InFolder

for Ras in arcpy.ListRasters():
    arcpy.AddMessage("Processing " + Ras)
    arcpy.SetRasterProperties_management(Ras,nodata="1 0;2 0;3 0")

Because the nodata is way down the list I find it easier to specify that; the parameters are Band Value;Band Value;... until all the bands are addressed. If you are likely to have more bands (or less) in the same folder then you will have to use arcpy.Describe and the bandCount property to set the null for the correct number of bands:

import sys, os, arcpy

InFolder = sys.argv[1]
arcpy.env.workspace = InFolder

for Ras in arcpy.ListRasters():
    arcpy.AddMessage("Processing " + Ras)
    desc = arcpy.Describe(Ras)
    if desc.bandCount == 3:
        arcpy.SetRasterProperties_management(Ras,nodata="1 0;2 0;3 0")
    elif desc.bandCount == 4:
        arcpy.SetRasterProperties_management(Ras,nodata="1 0;2 0;3 0;4 0")
    elif desc.bandCount == 1:
        arcpy.SetRasterProperties_management(Ras,nodata="1 0")

In ArcCatalog, right click on the layer and go to properties: enter image description here

hit the edit button:

enter image description here

Enter the values then hit OK to dismiss the NoData editor and OK to enforce the change.

Now the raster will display nothing in ArcMap where the cell value is 0,0,0.

3

If you go to the raster properties, and if the symbology is set as RGB composite (which it seems to be), you can check the Display Background Values (RGB) box and set whatever you like as a hollow background. So just set 0 0 0 as the background value and you should be in business.

2

I think the easiest way to achieve this would be to create a null condition raster first, then use that raster to assign the NoData values to each band seperately.

Try running the Con function to create the null condition raster.

nullCondition = Con(((band1 == 0) & (band2 == 0) & (band3 == 0)), 1, 0)

Then use the null condition raster to assign NoData values to each band with the set Null function. You should be able to do this with model builder or python.

2

I believe that you can use tree different procedures that theoretical should work. Raster calculater where you can use this expression SETNULL([raster] == value, [raster]) Reclassify where you should only reclass the value that you want. And using ArcPy you can use this script that I've found here https://gis.stackexchange.com/a/24578/47790

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outSetNull = SetNull("elevation", "elevation", "VALUE = 9999")
outSetNull.save("C:/sapyexamples/output/outsetnull")

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.