12

I'm trying to clip down an Orthophoto to a county boundary. I've been using the Extract By Mask Tool, but this process has been running for about 12 hours! It's gone through 2 cycles already, so I'm assuming this is each band. Can someone correct me if I'm wrong on that.

Would the Clip in Data Management work better (faster)? How would the accuracy be?

I've always tried to use Extract By Mask, but this is taking too long.

  • I've always Clip rather than Extract By Mask to trim a raster to a polygon's outline, and it is fairly fast (minutes, not hours). Can you clarify what you mean by "accuracy" of the result? – Erica Apr 29 '14 at 15:51
  • I've used the Clip tool in data management one time, but it was a precipitation raster that was meant to be used over a much larger area I was working with. It was for a school assignment, and they mentioned that it would not turn out well. – user26133 Apr 29 '14 at 15:57
  • To the best of my knowledge, Clip doesn't change the raster value contents (nor does Extract By Mask), so they may simply have been referring to the analysis values being inaccurate due to the smaller spatial area being analyzed, rather than the clip process affecting the data. That wouldn't be an issue for an orthophoto unless you're using it for analysis rather than background. – Erica Apr 29 '14 at 16:26
  • 2
    Clip only does a rectangular area (envelope) however extract by mask will extract to an irregular/multipart/doughnut polygon. If you want only the data in an extent use clip, it's much faster, but if you need to trim to an irregular shape then use extract by mask. – Michael Stimson Apr 29 '14 at 23:29
  • 4
    Actually, clip can do irregular shapes, too. If you select the polygons in the shp file you want to clip the raster to and then check the "Use input features for clipping geometry" box you get the polygon shape, not the rectangular extent of the whole shp file. – ecologist1234 Dec 3 '15 at 0:35
19

I ran a test to determine how the speed and quality differs between the two methods, here are the results:

Input data

  1. 4-band NAIP DOQQ image in .img format (349.34MB)
  2. A feature class used as the mask/clipper

enter image description here

Performance

Three trials were performed and benchmarked. The Clip (Data Management) method is significantly faster than the Extract by Mask (Spatial Analyst) method.

enter image description here

Quality

Both extents were identical as were NoData values. However, a visual assessment showed that the extract by mask method slightly altered the pixel arrangement--likely the result of some type of resampling. The pixel arrangement in the clip operation were identical to the original input image.


# Import system modules
import arcpy, time, os
from arcpy import env
from arcpy.sa import *

env.overwriteOutput = 1

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Set local variables
inRaster = r'C:\temp\naip2011.img'
inMaskData = r'C:\temp\fgdb.gdb\clipper'
outws = r'C:\temp'
out1 = os.path.join(outws, 'extractbymask.img')
out2 = os.path.join(outws, 'clip.img')

#############TRIAL 1: EXTRACT BY MASK#########################################
start = time.clock()

# ExtractByMask
outExtractByMask = ExtractByMask(inRaster, inMaskData)

# Save the output
outExtractByMask.save(out1)

end = time.clock()
total = end - start

print "The extract by mask method took:  %s seconds" % round(total, 3)

###############TRIAL 2: CLIP#################################################
start = time.clock()

# Clip
arcpy.Clip_management(inRaster, "#", out2, inMaskData, "", "ClippingGeometry")

end = time.clock()
total = end - start

print "The clip method took:             %s seconds" % round(total, 3)
  • 1
    Great answer! I don't claim to be an expert statistician but I was fiddling around in minitab so I put your timings through a 2 sample t-test and I know the sample size is a bit small but it was a significant difference. ;) – Hornbydd May 17 '14 at 17:50
  • 3
    If the extract by mask method altered the original in any fashion, as you report, then it was probably not performed with an appropriate mask: that is, one that was exactly aligned with the original raster. That would have forced the original to be resampled, which would account for the additional computational burden--but also suggests your timing comparisons are not a fair assessment of the situation. Indeed, the clipping procedure most likely begins by creating a mask and then applying it, so one would expect clipping to be a little less efficient than an extraction by mask alone. – whuber May 19 '14 at 14:31
  • 1
    I hope you will not keep your contribution permanently deleted, Aaron: it contains useful information. Ideally, if you could update it to include timing for an accurately registered mask, it would be an exemplary answer. (Who knows, that result might disprove my speculations, too!) – whuber May 19 '14 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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