3

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).
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 11, 2014 at 8:50
0

1 Answer 1

4

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")
answered Aug 11, 2014 at 10:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.