Convert Raster to Numpy Array with only Arcpy and Numpy

المشرف العام

Administrator
طاقم الإدارة
All the articles I'm finding including GDAL or PIL(?) which I cannot use. So I am trying to convert a raster I have to a Numpy Array with Arcpy and Numpy and then calculate some statistics on it but running into an error. Not much documentation on this and not sure what I am doing wrong. I am running ArcGIS 10.3.1 with Python 2.7.8 on a Windows 7 machine with 16gb ram.

Here is my code:

import arcpyfrom arcpy.sa import *from arcpy import envimport numpy as npimport sys, os, string, glob#Set Environmentarcpy.CheckOutExtension("spatial")arcpy.env.overwriteOutput = Trueenv.extent = "MINOF"Coordsystem = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"#Set Input Datatcorr = arcpy.Raster(r"G:/P38R37/test4/TcorrCon/Tcorr198.tif")lowerLeft = arcpy.Point(tcorr.extent.XMin,tcorr.extent.YMin)cellSize = tcorr.meanCellWidth#Convert Raster to Numpy Array#Raster is 7951 columns x 6971 rows, Floating point 32 bit, 211MB in sizetcorr_arr = arcpy.RasterToNumPyArray(tcorr,lowerLeft,7951,6971,nodata_to_value=0)#Calculate the mean and standard deviation of the arrayarr_mean = np.mean(tcorr_arr)arr_std = np.std(tcorr_arr)#Take the mean and std and do mathdouble_std = arr_std * 2cfactor = mean - double_stdprint cfactorThe error I am getting says:

Traceback (most recent call last):File "C:\Python27\ArcGIS10.3\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScriptexec codeObject in __main__.__dict__File "C:\Users\mschauer\Documents\Py Scripts\scratch\numpytest_tcorr.py", line 20, in tcorr_arr = arcpy.RasterToNumPyArray(tcorr,lowerLeft,7951,6971,nodata_to_value=0)File "C:\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 2244, in RasterToNumPyArrayreturn _RasterToNumPyArray(*args, **kwargs)MemoryErrorAny ideas as to what I am doing wrong?



أكثر...
 
أعلى