1

I'm clipping some rasters with the ArcPy Clip tool (from the raster toolset) and a polygon feature and I'm having some problems with nodata values.

The script I'm using is based on the code from Arcgis help:

Usage:
Clip_management (in_raster, rectangle, out_raster, {in_template_dataset}, {nodata_value} {NONE | ClippingGeometry})

##Clip Raster Dataset with feature geometry
arcpy.Clip_management("image.tif", "#", "clip.tif","feature.shp", "0", "ClippingGeometry")

If I use '0' as NoData value, the clipping is OK. But there are some pixels where a band has 0 values and I get this in the clipped pixels:

Raster info

So, despite the clipping area it's fine, the raster doesn't look like the original because there's a band without its value.

I have been trying to use the ExtractbyMask tool but I've seen that some raster values are modified. It doesn't works for me because I need exactly the same values from the source.

Does somebody know if it's possible to define in ArcPy a Nodata value that considers the 3 bands at the same time?

Is it possible to define NoData value as '0,0,0' to solve this question?

I've been trying this but I'm not used to Python coding and maybe I'm not doing it properly.

0

1 Answer 1

3

Extract by mask should not be changing the values of the raster. You might be experiencing a shift in cell position, or a value re-sampling if the output cell size is different than the input.

Try to define your input raster as the snap raster in the environment settings to prevent a cell shift from occurring.

2
  • I've seen some pixels that have changed using Extract By Mask, for example from 0,126,180 to 0,127,181. It's a small change probably due to the re-sampling. I will try using the snap raster function.
    – Pau.ReRi
    Commented Feb 6, 2015 at 18:59
  • Extract by Mask and snap raster have solved it. Thanks a lot!
    – Pau.ReRi
    Commented Feb 6, 2015 at 19:18

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.