python errors

04-29-2013 05:54 AM
New Contributor

I'm working on mine final internship en thesis. And working for the first time with pythonwin.

I'm trying to make the python script work but i'm getting a lot of errors. I'm using pythonwin (2.6)

Traceback (most recent call last):

  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\", line 309, in RunScript, __main__.__dict__, start_stepping=0)

  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\debugger\", line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)

  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\debugger\", line 624, in run
    exec cmd in globals, locals

  File "T:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\", line 69, in <module>
    arcpy.ASCIIToRaster_conversion(Blok_asc, ASCIITo_asc9, "INTEGER")

  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\", line 1615, in ASCIIToRaster
    raise e

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000885: Input ASCII raster file: t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_input/'s does not have a file extension.

ERROR 000876: Output raster: t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\workspace\Blok_asc.asc's extension is invalid for the output raster format.
Failed to execute (ASCIIToRaster).

Is there anyone who can help me with this? If you need more information, let me know:)


0 Kudos
4 Replies
Esri Esteemed Contributor
Hi Daisy,

Can you post your code?  Don't forget to wrap it in CODE tags (using the # above).
0 Kudos
New Contributor
# import arcinfo
# Import arcpy module
import arcpy
from arcpy import env # Analysis environment
from import *
arcpy.env.overwriteOutput = True #enable output

# Import sys, os, glob modules
import sys
import os
import glob

# Set Geoprocessing environments
env.scratchWorkspace = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\workspace/"
env.workspace = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\workspace/"

# Check out any necessary licenses

# inputdir
inDir = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_input/"
OutDir = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output/"
OutDir2 = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output2/"

# scan files to process
fileList = glob.glob(inDir + "pt*.asc")
# filename starts at
fileStart = fileList[0].rfind('\\')+1

for inPut in fileList:
    print("processing " + inPut[fileStart::1])
    inPutWater =    inDir + inPut[fileStart::1]
    outPut =        OutDir + "water_goed" + inPut[fileStart+2:-4:1]
    outPut2 =        OutDir2 + "water_fout" + inPut[fileStart+2:-4:1]
# Script arguments
    Blok_asc = arcpy.GetParameterAsText(3)
    if Blok_asc == '#' or not Blok_asc:
        Blok_asc = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_input/" 

    Select_no_value_area = arcpy.GetParameterAsText(0)
    if Select_no_value_area == '#' or not Select_no_value_area:
        Select_no_value_area = "\"GRIDCODE\"  = 1" # provide a default value if unspecified

    Area = arcpy.GetParameterAsText(1)
    if Area == '#' or not Area:
        Area = "10 Unknown" # provide a default value if unspecified

    Select_areas_ = arcpy.GetParameterAsText(2)
    if Select_areas_ == '#' or not Select_areas_:
        Select_areas_ = "\"F_AREA\" > 40" # provide a default value if unspecified

# Local variables:
#    ASCIITo_01301 =             env.workspace + "/Blok_asc.asc"
    Output_raster =             env.workspace + "/ASCIITo_asc9.asc"
    ASCIITo_asc9 =              env.workspace + "/Blok_asc.asc"
    RasterT_IsNull_2_shp =      env.workspace + "/Output_raster.shp"
    RasterT_IsNull_1_Select =   env.workspace + "/Select_no_value_area.asc"
    Output_Feature_Class__2_ =  env.workspace + "/RasterT_IsNull_1_Select.shp"
    Output_Feature_Class =      env.workspace + "/Output_Feature_Class__2_.shp"
# output
    Output_Feature_Class__3_ = OutDir + "/output.shp"
# Process: ASCII to Raster
    arcpy.ASCIIToRaster_conversion(Blok_asc, ASCIITo_asc9, "INTEGER")

# Process: Is Null, Output_raster)

# Process: Raster to Polygon
    arcpy.RasterToPolygon_conversion(Output_raster, Block_asc, "NO_SIMPLIFY", "VALUE")

# Process: Select
    arcpy.Select_analysis(Block_asc, RasterT_IsNull_1_Select, Select_no_value_area)

# Process: Calculate Areas
    arcpy.CalculateAreas_stats(RasterT_IsNull_1_Select, Output_Feature_Class__2_)

# Process: Select (2)
    arcpy.Select_analysis(Output_Feature_Class__2_, Output_Feature_Class, Select_areas_)

# Process: Eliminate Polygon Part
    arcpy.EliminatePolygonPart_management(Output_Feature_Class, Output_Feature_Class__3_, "AREA", Area, "0", "CONTAINED_ONLY")

    if isEmpty(Output_Feature_Class__3_):
        arcpy.Copy_management(Output_Feature_Class__3_, outPut, "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output/")
        arcpy.Copy_management(Output_Feature_Class__3_, outPut2, "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output2/")
0 Kudos
Esri Esteemed Contributor
Hi Daisy,

I believe the problem is with your directory paths.  When using a backslash, specify 'r' in front of the path.  For example, change your paths from:




Also, you will want to remove the ending forward slash.
0 Kudos
New Contributor
There was someone in my office who know how to fix the errors.

But thank you for responsing en your help!
0 Kudos