Hello again,

First off, please accept my apologies for my last message, which was sorely 
lacking in the detail department. I'm such a beginner with programming that I 
assumed the error would be glaringly obvious to an experienced programmer and 
would jump of the page/screen right away. This wasn't the case, though. 

Second, thanks to everyone who did reply, despite the absence of detail, and 
the info. I got from these enable me to modify the script a little and also get 
more information about what might be going wrong.

So, to start again, and with much more detail...  

I have several thousand files of x,y,z coordinates in dBaseIV format (.dbf file 
extension) that I am trying to convert into shapefiles in order to be able to 
perform cut/fill analyses in ArcGIS 9.0. I am thus trying to automate this 
conversion using a Python script (in Python 2.1). I’ve taken as my starting 
point the batch clip tool that can be found at: 

http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=26892
 

and have tried to modify it to suit my purpose. I have replaced the clip tool 
with the Make XY Event Layer tool (from the the Data Management Tools toolbox), 
in order to create an xy Layer from the .dbf files, and with the Feature class 
to Shapefile (multiple) tool (from the Conversion Tools toolbox) in order to 
turn this xy layer into a shapefile. The full script as I have modified it is 
below.

Prior to running the script I use the ‘check’ button in the PythonWin and the 
script’s syntax is fine. When I run the script though, the message 

‘Script ‘C:\ dBase_File_To_Shapefile.py’ returned exit code 0’   

appears in the status bar at the bottom of the PythonWin window. The following 
text also appears in the Interactive window…

Traceback (most recent call last):
  File "C:\dBase_File_To_Shapefile2.py", line 37, in ?
    GP.FeatureClassToShapefile_conversion(outxyLayer, outputShapefiles)
  File "", line 2, in FeatureClassToShapefile_conversion
com_error: (-2147467259, 'Unspecified error', None, None)
Executing: FeatureClassToShapefile C:/xyLayerFiles/R302190.dbf C:\Shapefiles 
C:\Shapefiles
Start Time: Thu Feb 17 14:23:09 2005
Running script FeatureClassToShapefile...
Error in script FeatureClassToShapefile.
Error in executing: cmd.exe /C C:\PROGRA~1\ArcGIS\ARCTOO~1\Scripts\FEATUR~1.PY  
"C:/xyLayerFiles/R302190.dbf" "C:\Shapefiles" "C:\Shapefiles"

Failed to execute (FeatureClassToShapefile).
End Time: Thu Feb 17 14:23:10 2005 (Elapsed Time: 1.00 secs)

What I think my code should be doing is using the .dbf files from the "C:/One" 
folder, storing the xy layer files in the "C:/xyLayerFiles" folder and, 
finally, storing the shapefiles in the "C:/Shapefiles" folder. After I've run 
the code, however, there is nothing in either of the latter two folders. 

One possibilty is that there is a problem with the way that I am passing the 
input and output variables from the first toolbox command to the second, and 
perhaps also with the way that these variable are, or are not, being saved in 
the folders in which I think they should be saved.

Another possibility is that all the slashes in the workspace paths in the code 
are forward slashes, whereas all paths appear with back slashes in the address 
bar in my computer. However, if I try changing the forward slashes to back 
slashes in the code I get a warning about syntax when I use the 'check' button. 
 

I’ve been trying to automate this conversion process since Monday of this week 
and it is beginning to drive me insane!

Regards, 

Chris Bromley.


Here is the script as I have modified it:

#Import standard library modules
import win32com.client, sys, os

#Create the Geoprocessor object
GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

import traceback

#Set the input workspace
GP.workspace = "C:/One"

#Set the xyLayer output workspace
xyLayerFiles = "C:/xyLayerFiles"

#Set the shapefile output workspace
outputShapefiles = "C:/Shapefiles"

try:
    # Load required toolboxes...    
   GP.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data       
Management Tools.tbx")
    GP.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion 
Tools.tbx")
    
    #Get a list of dBase files in the input folder
    fcs = GP.ListTables("*","dBASE")

    #Loop through the list of dBase files
    fcs.Reset()
    fc = fcs.Next()

       while fc:
           # Set the outputname for each output to be the same as the input.
           outxyLayer = xyLayerFiles + "/" + fc

           #Convert each dBase table in the list into an xyLayer.
           GP.MakeXYEventLayer_management(fc, "X", "Y", outxyLayer, "")
           #Convert each xyLayer into a shapefile
           GP.FeatureClassToShapefile_conversion(outxyLayer, outputShapefiles)
           #Move to the next fc in the list.
           fc = fcs.Next()

except:
    traceback.print_exc()
    # If an error occurred print the message to the screen
    print GP.GetMessages()


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to