pythongisarcmap

How to use python to turn a .dbf into a shapefile


I have been scouring the internet trying to find a pythonic (sp?!) way to process this data..

Everyday we will recieve a load of data in .dbf format (hopefully) - we then need to save this data as a shapefile.

Does anyone have any links or any suggestions as to my process?


Solution

  • It was in model builder all along!

    #   (generated by ArcGIS/ModelBuilder)
    # Usage: DBF2SHAPEFILE <XY_Table> <Y_Field> <X_Field> <Output_Feature_Class>
    # ---------------------------------------------------------------------------
    
    # Import system modules
    import sys, string, os, arcgisscripting, datetime
    
    # Adds the creation date to all of the previous shapefiles in that folder
    filename = 'D:/test.txt'
    fileinfo = os.stat(filename)
    creation_date = datetime.date.fromtimestamp(fileinfo.st_ctime)
    os.rename(filename, filename + '-' + creation_date.strftime('%Y-%m-%d'))
    
    # Create the Geoprocessor object
    gp = arcgisscripting.create()
    
    # Load required toolboxes...
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
    
    # Script arguments...
    XY_Table = sys.argv[1]
    
    Y_Field = sys.argv[2]
    
    X_Field = sys.argv[3]
    
    Output_Feature_Class = sys.argv[4]
    
    # Local variables...
    Layer_Name_or_Table_View = ""
    
    # Process: Make XY Event Layer...
    gp.MakeXYEventLayer_management(XY_Table, X_Field, Y_Field, Layer_Name_or_Table_View, "")
    
    # Process: Copy Features...
    gp.CopyFeatures_management(Layer_Name_or_Table_View, Output_Feature_Class, "", "0", "0", "0")