Contour tool to create contour polygons based on iterating shapefiles in extent environment

478
0
11-09-2020 06:29 PM
Arthur_Morgan
New Contributor III

I am trying to run the contour tool on arcpy in Python IDLE 2.7 to produce contour polygons. Moreover, I have 189 grid polygons, and I would like to set each of these as processing extent, and the script will create separate contour polygons based on these looped extents. I tried the following code:

import os
from arcpy import env
from arcpy.sa import *
#Set the evironment settings
arcpy.env.workspace = 'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\Grids'
Grids = r'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\Grids'
# Get the list of shapefiles i.e. the grids of the VIC area
List = arcpy.ListFiles("*.shp")
print List
#Now load the DEM
DEM = r'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\DEM.tif'
# 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: "DEM.tif"
#Run the contour tool on each grid
for i in range(189):
 arcpy.env.extent = (r"D:\Spring2020\VIC\EB_Correct_File_ArcGIS\Grids"+".shp")
 arcpy.gp.Contour_sa("DEM", "D:/Spring2020/VIC/EB_Correct_File_ArcGIS/Contours/*.shp", "490.848333", "1742.06", "1", "CONTOUR_POLYGON", "") ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

List of grid shape files:

1.shp, 2.shp, 3.shp ..... 189.shp

Traceback (most recent call last):
 File "D:/Spring2020/VIC/Contours.py", line 16, in <module>
 arcpy.env.extent = (List)
 File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\geoprocessing\_base.py", line 541, in set_
 self[env] = val
 File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\geoprocessing\_base.py", line 601, in __setitem__
 ret_ = setattr(self._gp, item, value)
RuntimeError: Object: Error in accessing environment <extent>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I think there is a problem with line 16 syntax

Tags (2)
0 Kudos
0 Replies