How do I convert a text file with point coordinates to database tables in the dBase (*.dbf) format in Python?
I am using ArcGIS Desktop.
2 Answers 2
You can use Table to Table (Conversion) or Copy Rows (Data Management) here. Both of them have a very similar structure.
Usage of Table to Table:
This tool supports the following table formats as input:
dBASE (.dbf)
Comma Separate Value (.csv)
tab delimited text (.txt)
Microsoft Excel worksheets (.xls or .xlsx)
INFO
VPF
OLE database
personal, file, or SDE geodatabase
in-memory table views
For file input (.csv or .txt), the first row of the input file is used as the field
names on the output table. Field names cannot contain spaces or special characters
(such as $ or *), and you will receive an error if the first row of input file
contains spaces or special characters.
Syntax
TableToTable_conversion (in_rows, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword})
Example:
import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.TableToTable_conversion("inputFile.txt", "C:/output/Dbase.dbf", "outputFile")
As you're using ArcGIS, Aragon's answer should be sufficient. However, you can do it without ArcPy too. Python has a module for reading CSVs. You can then use dbfpy to write out the DBF. I believe there is a PyPi module for reading and writing to XLS, which might also serve.
Explore related questions
See similar questions with these tags.