I have a raster file that I would like to use to perform an inside clip on another raster file. I have tried using the extract by rectangle tool, but it gives me values ranging from 3.40282e+038 to -3.40282e+038. I have also tried to export the file using the selected graphics option, but the option is not available when I try and select it.

I am trying to get an average NDVI value for an area while discounting all of the water areas. I was directed to mask out water areas by:

  1. converting everything to NumPy matrices;
  2. reclassifying all water in the NLCD raster to 0 and all other pixels to 1;
  3. multiplying that resulting raster by the NDVI value raster;
  4. using numpy.sum(new-ndvi) / numpy.count_nonzero(new-ndvi) to get the average NDVI value of all non-water pixels.

However, when I try and convert the 13.5 MB NLCD raster to an array using this:

myarray = arcpy.RasterToNumPyArray('Z:\GISDataWarehouse\Land-Cover\LandCover-WI\landcover-wi.tif')

I get the error Runtime error <type 'exceptions.MemoryError'>

  • You are re-inventing the wheel: a zonal mean of the NDVI raster using the non-water areas of the NLCD raster as the zone(s) will do the job easily and immediately.
    – whuber
    Commented Jun 26, 2013 at 3:28
  • That would be ideal, but I need the average NDVI for specific areas. After I have removed the water values from the NDVI file I will be calculating the average NDVI for over 200 designated areas.
    – Andrea
    Commented Jun 26, 2013 at 15:37
  • If those areas do not overlap, Andrea, the zonal summary will obtain the mean NDVI for them all in a single operation.
    – whuber
    Commented Jun 26, 2013 at 15:55

2 Answers 2


The approach you describe seems overly complicated. Instead, consider using Set Null (Spatial Analyst) to convert all of the corresponding NLCD water values to NoData in your NDVI dataset. NoData values will not be incorporated into your NDVI calculations. The following script should get you started.

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/Your/Path"

# Make sure the cell size output is the minimum of the two datasets
arcpy.env.cellSize = "MINOF"

# Set local variables
inRaster = "NLCD.img"
inFalseRaster = "NDVI.img"

# This expression is used to define which areas will be converted to NoData
whereClause = "VALUE = 11" # I believe "11" is the value for water (2006 NLCD)

# Check out the ArcGIS Spatial Analyst extension license

# Execute SetNull
outSetNull = SetNull(inRaster, inFalseRaster, whereClause)

# Save the output 

You can use the Extract by Mask geoprocessing tool to accomplish this using 2 rasters. This should be a bit more reliable and straight-forward than Extract by Rectangle.

From the Esri documentation:

When a multiband raster is specified as input, a new multiband raster will be created as output. Each individual band in the input multiband raster will be analyzed accordingly. The default output format is an ESRI grid stack. Note that the name of an ESRI grid stack cannot start with a number, use spaces, or be more than 9 characters in length.

If the input is a layer created from a multiband raster with more than three bands, the extraction operation will only consider the bands that were loaded (symbolized) by the layer. As a result, the output multiband raster can only have three bands, corresponding to those used in the display of the input layer.

  • I tried using the Extract by Mask tool, but it exported a new file with only the extracted water values. I would like to have a new file with all of non-water ndvi values and the water values removed.
    – Andrea
    Commented Jun 25, 2013 at 15:11
  • I've edited my answer to highlight some information from the ESRI documentation that should help.
    – Radar
    Commented Jun 25, 2013 at 15:14

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.