7

I'm writing a short python script that includes processing rasters with different geoprocessing tools in ArcGis 10, for example, the three processes below, is this best way to use multiple tools successively, i.e. create temporary rasters in the scratch workspace and then delete them all at the end of the script? By "best", I guess I mean is this the fastest/most efficient way to do this?

# calculate distance (inR is the input raster)
tmp1 = EucDistance(inR, "", "1000", "")
# convert to integer raster
tmp2 = Int(tmp1)
# Reclassify again
arcpy.CalculateStatistics_management(tmp2, "1", "1", "")
tmp3 = Reclassify(tmp2, "VALUE", "0 NODATA", "DATA")
asked Mar 10, 2011 at 17:11

2 Answers 2

8

For operations that require intermediate data sets, I think that this is really the best/only way to do it.

There are cases where you can create 'in_memory' data sets for use in the next analysis without serializing the data to disk, but for large data sets this probably isn't the greatest idea.

If you wanted to get deeper into the programming, you could use ArcPy (or GDAL) to read your first raster into a numpy array. You could then do the processing in arrays, in memory and just output your final raster.

answered Mar 10, 2011 at 18:02
2
  • Thanks, it's good to know I'm on the right track. I guess the processing in arrays would be quicker as well, does numpy have ready-made functions similar to geoprocessing ones (I've yet to look at numpy), using R would also be another option, right? Commented Mar 10, 2011 at 19:37
  • 4
    There is some great information about using gdal, numpy, and Python in raster GIS in weeks 4-6 of Chris Garrard's Geoprocessing with Python using Open Source GIS at: gis.usu.edu/~chrisg/python/2009 Commented Mar 10, 2011 at 19:46
2

While I agree with DavidF, note that you can actually combine these statements to reduce the amount of serialization to disk as well as avoid any of the sets becoming permanent:

# calculate distance (inR is the input raster), convert to integer raster, & Reclassify again
# calculate statistics is probably not necessary for the reclass coming out of the Int()
tmp3 = Reclassify(Int(EucDistance(inR, "", "1000", "")), "VALUE", "0 NODATA", "DATA")

I've found you can handle some pretty large sets this way. And once they get large enough, you switch to numpy arrays.

answered Sep 28, 2011 at 0:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.