raster to polygon conversion

2243
3
07-28-2014 10:14 AM
InceptionWoznicki
New Contributor

Hi Guys,

I 'm trying to automate the conversion raster to polygon and the rasters files are in "TIF" format. I have the code below. However, I 'm getting an error while executing it. Could you have some suggestion please? Thank you very much for your time and help!

 

Regards,

Subhasis

 

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)

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor

It is always a good thing to include the actual error message, since it helps us to determine the reason for which the error occurs. Another thing that would increase readability of the code, would be to use syntax highlighting. You can read more about this here:

Posting Code blocks in the new GeoNet

You do not have to import the sa module, nor is it necessary to check out a sa license. All the tools you are using are available at each license level without the need for any extension.

I notice that you define the outPolygons by using ".shape"  as extension. If you want to create a shapefile, you should specify ".shp" as extension.

Kind regards,

Xander

0 Kudos
InceptionWoznicki
New Contributor

Thank you very much Xander again! Yes, I should have posted the error message and would  read about code blocks.

Regards,

Subhasis

0 Kudos
InceptionWoznicki
New Contributor

The above code worked. Except I had to replace inraster by i in

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

0 Kudos