Unable to open feature class Failed to execute (RasterToPolygon)

3873
6
Jump to solution
08-11-2014 03:46 AM
RobertBeno
New Contributor

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"

 

 

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Ok, does it print the other raster names and just not produce anything?  if it prints the other names, have you looked on disk to confirm whether they are or are not there.  I am not sure about the wildcard you are using either,

View solution in original post

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

are these lines indented?  your code isn't formatted correctly if it isn't

print raster #check the presence of rasters"

#convert the raster to polygon

arcpy.RasterToPolygon_conversion(raster, raster +".shp", "SIMPLIFY")

0 Kudos
RobertBeno
New Contributor

oh, sorry for my formatting, yes my for loop is indented.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ok, does it print the other raster names and just not produce anything?  if it prints the other names, have you looked on disk to confirm whether they are or are not there.  I am not sure about the wildcard you are using either,

0 Kudos
XanderBakker
Esri Esteemed Contributor

Apparently the wildcard is working, assuming that the rasters of interest start with "nofpt" are TIF fiels and reside in the workspace indicated.

Some remarks:

  • There is no need for spatial analyst to convert raster to polygons
  • With your code the output shapefile will have the name "nofpt_somename.tif.shp". Not sure if you want that...

Have a look at the code below. This will remove the .tif extension from the output shapefile name (see line 9).

import arcpy

arcpy.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"):

    shp_name = "{0}.shp".format(os.path.splitext(raster)[0])

    print "Converting raster '{0}' to polygons '{1}'".format(raster, shp_name)

    #convert the raster to polygon

    arcpy.RasterToPolygon_conversion(raster, shp_name, "SIMPLIFY")

print "Finish converting the rasters to polygon"

For testing you could comment out line 13 and see what it prints. How many rasters are found?

Kind regards, Xander

0 Kudos
RobertBeno
New Contributor

thank you for this! Now, I've successfully converted my rasters.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Great to hear you managed to solve your problem

0 Kudos