1

I 'm trying to automate the conversion of raster to polygon and the rasters files are in "TIF" format which is a "unsigned integer". I have the code below. However, I 'm getting an error while executing it. Could you have some suggestion please?

Code:

import arcpy, os
from arcpy import env
from arcpy.sa import *

#To overwrite output
arcpy.env.overwriteOutput = True

#Set environment settings
env.workspace = "C:/Subhasis/Test/Neshanic_Python/extract"

outws="C:/Subhasis/Test/Neshanic_Python/extract/clip/"

#checkout ArcGIS spatial analyst extension license
arcpy.CheckOutExtension("Spatial")

inraster = arcpy.ListRasters("*", "TIF")

for i in inraster:
    filename=os.path.splitext(i)[0]
    outPolygons= outws + str(filename) + '.shape'
    field = "VALUE"
    arcpy.RasterToPolygon_conversion(inraster, outPolygons, "NO_SIMPLIFY", field)

Error: Traceback (most recent call last): File "C:\Subhasis\Test\Neshanic_Python\extract\Clip.py", line 23, in arcpy.RasterToPolygon_conversion(inraster, outPolygons, "NO_SIMPLIFY", field) File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\conversion.py", line 241, in RasterToPolygon raise e

  • @artwork21. Thank you very much for editing my post! Do I need any software for this editing? if yes where do I get it? – Inception Jul 28 '14 at 17:51
  • 2
    Shapefiles don't have the extension ".shape"; it's .shp – Paul Jul 28 '14 at 17:56
  • also the formatting help page is here. gis.stackexchange.com/editing-help – Brad Nesom Jul 28 '14 at 18:18
  • FYI, you also don't need to check out the spatial analyst extension to convert raster to polygons. It's core ArcGIS. – Fezter Jul 29 '14 at 5:11
3

For this line:

arcpy.RasterToPolygon_conversion(inraster, outPolygons, "NO_SIMPLIFY", field)

You are inserting a list not an individual raster file, trying changing it to:

arcpy.RasterToPolygon_conversion(i, outPolygons, "NO_SIMPLIFY", field)
  • Yes, I did that stupid mistake.Thank you very much It worked! Another topic, How do I post my question so that you don't have to edit it? If I need anything to install,Where do i get it? Thank you! – Inception Jul 28 '14 at 17:56
  • There should be text called edit under the question tags that you can click on to edit it. – artwork21 Jul 28 '14 at 18:00
  • good morning! Sorry to bother you. I may sound stupid, I was looking for the text "edit" to edit my code. But I didn't get it. I was wondering do I need to install something as I didn't see anything under "question tab". Thank you! – Inception Aug 1 '14 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.