To get you started, have a look at the code below. Use this script by adding it as a script to a new toolbox.
Define the 5 parameters as explained on line 18 - 22
#-------------------------------------------------------------------------------
# Name: clip_contour.py
# Purpose: clip raster and create contours
#
# Author: Sandrine Carmet
#
# Created: 08/08/2014
#-------------------------------------------------------------------------------
class LicenseError(Exception):
pass
def main():
import arcpy
import os
# read the parameters
fc_extent = arcpy.GetParameterAsText(0) # define as featurelayer, filter polygon, direction input
ras_in = arcpy.GetParameterAsText(1) # define as rasterlayer, direction input
ras_clip = arcpy.GetParameterAsText(2) # define as raster dataset, direction output
fc_contour = arcpy.GetParameterAsText(3) # define as featureclass, direction output
interval = arcpy.GetParameter(4) # define as Double, set min and max range, provide default
# configuration of contours
contour_interval = interval # not 4...
base_contour = 0
z_factor = 1
try:
if arcpy.CheckExtension("3D") == "Available":
arcpy.CheckOutExtension("3D")
else:
# raise exception
raise LicenseError
# set in memory workspace
arcpy.env.workspace = "IN_MEMORY"
# Determine the extent of the fc
extent = arcpy.Describe(fc_extent).extent
ext_txt = "{0} {1} {2} {3}".format(extent.XMin, extent.YMin, extent.XMax, extent.YMax)
# Clip the raster
arcpy.Clip_management(ras_in, ext_txt, ras_clip, fc_extent, "#", "ClippingGeometry")
# Create the contours
arcpy.Contour_3d(ras_clip, fc_contour, contour_interval, base_contour, z_factor)
# return license
arcpy.CheckInExtension("3D")
# outputs are automatically added to the TOC...
except LicenseError:
print("3D Analyst license is unavailable")
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
if __name__ == '__main__':
main()
Once you run the script successfully, you can go to the Results windows and see the syntax for executing the script.
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "pols", "DEMsmpro"
arcpy.ClipRasterCreateContours("pols","DEMsmpro","D:/Xander/grd/test_clip","D:/Xander/tmp/test2.gdb/test_contours","50")
You could create another script that simply executes this script or change the script to work with a list of inputs.
Kind regards, Xander