Clip a raster dataset against a fishnet

92 views
Skip to first unread message

Nuno Vilaça

unread,
Oct 7, 2007, 7:15:16 AM10/7/07
to esri
Dear all,

I am using a raster with a 0.66 x 0.66 m² resolution in which I need
to perform some calculations. As you can imagine, this will take aeons
of time if I do it in the complete raster dataset. Therefore I have
created a fishnet that covers the region in which I want to perform
the calculations in.
Now i need to clip my raster dataset against this fishnet, but in an
automatic way so I do not have to perform a new action everytime I
calculate a fishnet cell with the raster.
I think this is possible to do it in Python language but I simply have
no knowledge at all with this language and I am very short on time,
can anyone help me? AML scripting is also welcome!
Thank you!

Roc1

unread,
Oct 8, 2007, 3:45:44 PM10/8/07
to esri
Yes. Python will work for you. Here is a script I wrote that reads
in the polygons of a feature class and for each one, it executes some
geoprocessing functions. You can modify this slightly to get what you
need.

Hope that helps!
----------------------------
Robert Claypoool
Nashville, TN

#
---------------------------------------------------------------------------
# MakeDEMs_Geoprocess.py
#
---------------------------------------------------------------------------

# Import system modules
import sys, string, os, win32com.client

# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

# Set product license
gp.SetProduct("ArcView")

# Check out any necessary licenses
gp.CheckOutExtension("spatial")

# Load required toolboxes
gp.AddToolbox("C:/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
gp.AddToolbox("C:/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst
Tools.tbx")

# Create a search cursor
Buffer_Polygons = "C:\\Documents and Settings\\robert.claypool\\Desktop
\\Bucks_Co\\Approx_Study\\MergeStream_Buffers.shp"
rows = gp.SearchCursor(Buffer_Polygons)
row = rows.Next()

# Loop through all the records in the shapefile
# Geoprocess each record.
try:
while row:
# Find the FID field
FID = row.GetValue("FID")

# Find the "Source_Nm" field. Get it's value for this row.
This value will be used to select the feature and name output
files.
Name = row.GetValue("Source_Nm")
Name = Name[0:-4] # This removes the last 4 characters
(".mdb") from the string

# Generate an expression to select the feature
Expression = '\"FID\" = ' + str(FID) # Where "FID"=FID

# Execute Process: Select the feature for this row, save it to
a new shapefile
Output_Path_1 = "C:\\temp\\" + Name+ "_BUFFER.shp"
gp.Select_analysis(Buffer_Polygons, Output_Path_1,
Expression)

# Execute Process: Clip DEM using the new shapefile as a mask
Dem = "C:\\Documents and Settings\\robert.claypool\\Desktop\
\Bucks_Co\\DEM\\dem"
Output_Path_2 = "C:\\temp\\dem" + Name
gp.ExtractByMask_sa(Dem, Output_Path_1, Output_Path_2)

# Advance the cursor for next iteration of the loop
row = rows.Next()

except:
# If an error occurred while running a tool, print the messages
print gp.GetMessages()

#
---------------------------------------------------------------------------
# END MakeDEMs_Geoprocess.py
#
---------------------------------------------------------------------------

Roc1

unread,
Oct 8, 2007, 3:49:29 PM10/8/07
to esri
PS. The script requires a spatial analyst license.

Nuno Vilaça

unread,
Oct 12, 2007, 5:29:43 AM10/12/07
to esri
Thanx Roc!
I'm sorry i took suc a long time answering, but i have been away!
anyway, the outputs of your script seem good, gotta perform some
statistics on them now to make sure they r just perfect!
thanx once again!
kind regards!
nuno

> > > Thank you!- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages