Creating dbf in Python

1998
3
10-10-2011 07:10 PM
MelissaTalley
New Contributor
I currently have a python script that I'm using in the middle of a model which performs matrix algebra from an output of my model (a .txt file) and another .txt file.

I need to use the resulting array of the matrix algebra in my model. The best way I can think of to do this would be to create a .dbf file that I would join to my original shapefile. Is there a way to accomplish this? I know I can create a text file from the array, but I can't seem to find a way to import this into my model.
Tags (2)
0 Kudos
3 Replies
KimOllivier
Occasional Contributor III
A text file can be loaded as a table, you would need to have a valid header and it helps a lot if you also have a schema.ini file with an entry to define field types, otherwise they all default to char fields 255 wide.
0 Kudos
MelissaTalley
New Contributor
Thank you! I will try this. I know how to create the table in Python, but what tool would I use to load the table from the text file in Model Builder?
0 Kudos
Jasonvan_Warmerdam
New Contributor
Using the arcpy module for Arc 10 you can use the following two functions to convert a text file back to a shapefile:

#Variable that is assigned an input folder location
workspace = 'C:/folderPath'

#Variable that is assigned a string name. This will be what your exported shapefile will be called.
newLayer = 'layerName'

#Create the new Event Layer. The arguments 'x','y' and 'z' are the header names associated with your lat,lon and elevation respectively
arcpy.MakeXYEventLayer_management('textFile.csv', 'x', 'y', newLayer, '', 'z')

# Process: Feature Class To Shapefile (multiple)
arcpy.FeatureClassToShapefile_conversion('layerName', workspace)

0 Kudos