Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I was just curious as to whats the best way within a python script to get the output a dbf file/ table while the input is a shapefile. (if possible which i'm assuming it is)

Is there a way of converting a shape file into a table, or by selecting the attribute table of the shapefile and just outputting that.

Or am i going to need to create a table and then import the values?

share|improve this question
    
If you have the path to your shapefile stored as a string variable (say, path_to_shp), you can simply do path_to_dbf = path_to_shp.replace('.shp', '.dbf') and use the attribute table for that shapefile directly. –  nmpeterson Mar 25 at 20:15
    
if all you're looking to do is convert the dbf to a different format, Excel will read a dbf (though it won't write one in Excel 2007 and newer). You can read the dbf and write it as csv or any other Excel-compatible format. You can also convert from shapefile to csv with gdal_translate. –  Llaves Mar 26 at 2:49

1 Answer 1

up vote 9 down vote accepted

This is a very simple implementation using Table to Table (Conversion).

import arcpy

ws = r'C:\temp'
file = r'C:\temp\poly.shp'

arcpy.TableToTable_conversion(file, ws, "outTable.dbf")

For an even more efficient pure python approach, you can copy the shapefile's .dbf file using shutil:

import shutil

file = r'C:\temp\poly.dbf'
outFile = r'C:\temp\poly_copy.dbf'

shutil.copyfile(file, outFile)
share|improve this answer
    
Wow, thank you very much! I didn't even know there was a tool for that! thanks again Aaron! Have a great day! –  Steve Mar 25 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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