0

I'm trying to automate the conversion of raster to polygon and the raster files are in "TIF" format which is a "floating point". I copy the code below from raster to polygon conversion so it needs some changes because of "unsigned integer" and ...that I don't know.

How can I correct this code?

I'm getting an error while executing it.

Runtime error Traceback (most recent call last): File "", line 18, in TypeError: 'NoneType' object is not iterable

Code

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

#To overwrite output
arcpy.env.overwriteOutput = True

#Set environment settings
env.workspace = "K:\1400-10-20"

outws="K:\1400-10-20\m"

#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(i, outPolygons, "NO_SIMPLIFY", field)
1
  • Edit and remove the ...
    – Bera
    Commented Jan 10, 2022 at 9:13

1 Answer 1

1

As the error shows "Nonetype", it means that your variable "inraster" is empty. It is because of the incorrect way of writing the folder paths in your code. The variables where you are setting the workspace and other paths should be written with either double backslash ("\\") or single forward-slash ("/").

For example in your code:

env.workspace = "K:\1400-10-20"
outws="K:\1400-10-20\m"

must be replaced with

 env.workspace = "K:/1400-10-20"
 outws="K:/1400-10-20/m"

or

env.workspace = "K:\\1400-10-20"
outws="K:\\1400-10-20\\m"
4
  • hi first of all i appreciate your consideration i did what you mentioned but there is another problem
    – coral
    Commented Jan 18, 2022 at 7:33
  • Runtime error Traceback (most recent call last): File "<string>", line 21, in <module> File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\conversion.py", line 337, in RasterToPolygon raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000864: Input raster: The input is not within the defined domain. ERROR 000367: Invalid GP data type Failed to execute
    – coral
    Commented Jan 18, 2022 at 7:41
  • i think that the ERROR 000864 is related to "float" format type i have to change all my float raster files to integer then convert to polygon could you please tell me how can i do it automitically and with python.thank you so much
    – coral
    Commented Jan 18, 2022 at 7:49
  • Yes, you are right. Integer raster is required to run the required tool. Please go through the below given link, it will help you to resolve your issue. Accordingly, you can write a code to automate that task. support.esri.com/en/technical-article/000012554 Commented Jan 18, 2022 at 9:26

Your Answer

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

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