7

I have a raster of landcover that I have reclassed and the different land cover classifications are now represented by numbers which correspond to fertilizer inputs.

Using ArcGIS 10.3, I am trying to extract a certain set of those values while converting the rest to zeros.

Is this possible using the extract by attributes tool?

When I have tried previously, the values other than the ones i selected for all are converted to NoData which is causing me issues later when I try to add rasters.

4 Answers 4

7

When using the Raster Calculator in ArcToolbox (version 10.3.1) the Con function is expressed as follows for a raster that is named "streams":

Con(IsNull("streams"), 0, "streams")

this returns zero if streams is null else it returns the value of streams.

In this example all NoData pixels in the Streams are set to zero, otherwise they contain the pixel value found in the Streams dataset.

5

As you have reclassified this raster I'll assume that you have access to the Spatial Analyst extension, so will continue with instructions that require this extension.

The tool you want to use is Con, although you can do it with Extract by Attributes Con gives you more control over the 'false' case. Your SQL statement has the potential to be quite long unless you've got a suitable range for example:

Value > 350 && Value < 360 || Value = 340

Like this:

enter image description here

Note that the input conditional raster and input true raster or constant are the same value.. this is saying where the expression is true the output will be what's in the input; the false raster or constant is 0... so where the expression is true the output will be the input, where it's false it will be 0.

For individual values (for example 3,5,7,9) you can specify implicitly:

Value == 3 || Value == 5 || Value == 7 || Value == 9

Which can get quite long winded, however for Integer rasters (not floating point) like classified rasters you can use the SQL in operator:

Value in (3,5,7,9)

Which is significantly less typing and you don't need to search all over your keyboard for the pipe (|) symbol to do a C style OR.

2

The fastest way to convert NoData value to 0 in ArcGIS is to use map algebra with the Con operator

Con(IsNull(your_raster), O, your_raster)

Now if you want to avoid creating those NoData values when you extract some values and there is no simple conversion rule, you can use the "reclassify tool" making sure that you have an output value (which can be zero) for each input (even for NoData).

enter image description here

2
  • I believe you have your Con() syntax backward. It should be Con(IsNull("your_raster"), 0, "your_raster") as @Rich answered. The first replacement value is returned when the conditional statement (IsNull, in this case) evaluates to True, and the second value when False. Commented Oct 27, 2016 at 2:36
  • exactly, I've edited my answer with the correct syntax. Thanks a lot.
    – radouxju
    Commented Oct 27, 2016 at 5:44
1

Be sure to hit "Enter" as you are adjusting the values to "0" in the Reclassification tool. Sometimes if you don't it will just revert to "NODATA". That is a problem that I have ran into from time to time. If you want to leave the layer as a raster then it would be best to reclassify it, rather than to extract it using the extract by attributes tool, since the reclassify tool was made for rasters.

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.