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:
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="comment token">#Set the evironment settings</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\Grids'</SPAN>
Grids <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\Grids'</SPAN>
<SPAN class="comment token"># Get the list of shapefiles i.e. the grids of the VIC area</SPAN>
List <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*.shp"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> List
<SPAN class="comment token">#Now load the DEM</SPAN>
DEM <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\DEM.tif'</SPAN>
<SPAN class="comment token"># 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</SPAN>
<SPAN class="comment token"># The following inputs are layers or table views: "DEM.tif"</SPAN>
<SPAN class="comment token">#Run the contour tool on each grid</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">189</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"D:\Spring2020\VIC\EB_Correct_File_ArcGIS\Grids"</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">".shp"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>gp<SPAN class="punctuation token">.</SPAN>Contour_sa<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"DEM"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"D:/Spring2020/VIC/EB_Correct_File_ArcGIS/Contours/*.shp"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"490.848333"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"1742.06"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"1"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CONTOUR_POLYGON"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
List of grid shape files:
1.shp, 2.shp, 3.shp ..... 189.shp
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"D:/Spring2020/VIC/Contours.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">16</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>List<SPAN class="punctuation token">)</SPAN>
File <SPAN class="string token">"C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\geoprocessing\_base.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">541</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> set_
self<SPAN class="punctuation token">[</SPAN>env<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> val
File <SPAN class="string token">"C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\geoprocessing\_base.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">601</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> __setitem__
ret_ <SPAN class="operator token">=</SPAN> setattr<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">.</SPAN>_gp<SPAN class="punctuation token">,</SPAN> item<SPAN class="punctuation token">,</SPAN> value<SPAN class="punctuation token">)</SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> Object<SPAN class="punctuation token">:</SPAN> Error <SPAN class="keyword token">in</SPAN> accessing environment <SPAN class="operator token"><</SPAN>extent<SPAN class="operator token">></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I think there is a problem with line 16 syntax