I'm trying yo execute the RastertoPolygon conversion tool in ArcGIs 10.1. I'm executing it through a for loop, then it resulted to an error (Unable to open feature class Failed to execute (RasterToPolygon)) at the python console. As I checked for some output, the first raster from the list is successfully converted to shp file while the rest are not. Any suggestions? Note: (All of my rasters are already in integer data type)
#import the module
import arcpy
from arcpy.sa import *
from arcpy import env
arcpy.CheckOutExtension("Spatial")
env.overwriteOutput = True
#set the workspace
arcpy.env.workspace = r"C:\Users\Windows\Documents\JO_GIS_Analyst"
#Get a list of rasters and convert to shapefile
for raster in arcpy.ListRasters("nofpt*", "TIF"):
print raster #check the presence of rasters"
#convert the raster to polygon
arcpy.RasterToPolygon_conversion(raster, raster +".shp", "SIMPLIFY")
print "Finish converting the rasters to polygon"
the output of print is the name of my raster file, the first item on my list:
nofptreprojected_2014121_geog.tif
the exact error message is:
Traceback (most recent call last):
File"C:\Users\Windows\Dropbox\PythonScripts\batch_convert_raster_to_polygon.py", line 22, in <module>
arcpy.RasterToPolygon_conversion(raster, r"C:\Users\Windows\Documents\JO_GIS_Analyst\\" + raster + ".shp", "SIMPLIFY")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\conversion.py", line 178, in RasterToPolygon
raise e
ExecuteError: ERROR 010157: Unable to open feature class C:\Users\Windows\Documents\JO_GIS_Analyst\nofptreprojected_2014121_geog.tif.
Failed to execute (RasterToPolygon).
1 Answer 1
Although it is cut off in the output you posted it appears that you are trying to create a shapefile named nofptreprojected_2014121_geog.tif.shp
which I suspect is not a valid shapefile name.
Try replacing:
arcpy.RasterToPolygon_conversion(raster, raster +".shp", "SIMPLIFY")
with:
arcpy.RasterToPolygon_conversion(raster, raster.replace("tif","shp"), "SIMPLIFY")
or even simpler - purely as a test:
arcpy.RasterToPolygon_conversion(raster, "test.shp", "SIMPLIFY")
Explore related questions
See similar questions with these tags.