Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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'>

Thank you for your help!

share|improve this question
    
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 Jun 26 '13 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 Jun 26 '13 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 Jun 26 '13 at 15:55
add comment

2 Answers

up vote 2 down vote accepted

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
arcpy.CheckOutExtension("Spatial")

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

# Save the output 
outSetNull.save("C:/temp/convertedNDVI.img")
share|improve this answer
    
Thank you for your help! When I tried running the script I get the following error: >>> env.workspace = "C:\Python" >>> inRaster = "\landcover-wi.tif" >>> inFalseRaster = "\ndvi-wi.tif" >>> whereClause = "VALUE == 11" >>> arcpy.CheckOutExtension("Spatial") u'CheckedOut' >>> outSetNull = SetNull(inRaster, inFalseRaster, whereClause) Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000860: Input conditional raster: is not the type of Composite Geodataset, or does not exist. ERROR 000865: Input false raster or constant value: dvi-wi.tif does not exist. –  Andrea Jun 26 '13 at 15:24
    
I would be happy to try and debug the script if you post it in chat. –  Aaron Jun 26 '13 at 15:31
    
Unfortunately I need 20 reputation points to post in a chat. –  Andrea Jun 26 '13 at 15:39
    
The error code is saying that the NDVI file "does not exist." I am able to load the file into ArcMap. The land cover file is in the same format, and that file loads properly. –  Andrea Jun 26 '13 at 16:26
    
Sounds like an issue with the workspace. Make sure to define the workspace to the folder that contains your NDVI. Then specify your input files directly including the extension (e.g. "inFalseRaster = myndvi.img"). –  Aaron Jun 26 '13 at 17:04
show 5 more comments

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.

Edit:

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.

share|improve this answer
    
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 Jun 25 '13 at 15:11
    
I've edited my answer to highlight some information from the ESRI documentation that should help. –  Nick Ochoski Jun 25 '13 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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