Select to view content in your preferred language

Problem with coding on ExportXYv_stats  tool

1290
2
09-03-2012 04:38 PM
NickEubank
Deactivated User
Hi All!

I'm having issues with the arcpy tool arcpy.ExportXYv_stats. According to the documentation, the tool accepts 5 arguments, but I can't get the tool to accept the final argument, which determines whether variable labels will be included in an exported ASCII file. (I'm running Arc 10).

Any advice?

Thanks!
Tags (2)
0 Kudos
2 Replies
by Anonymous User
Not applicable
Can you post the full code? I have included this function in many scripts for creating spreadsheets for the non-GIS people in my office. Here is what it looks like in one of my scripts:


import arcpy, os, sys, traceback

arcpy.env.workspace = 'G:\\Data\\Geodatabase\\Cedar_County.mdb'
arcpy.env.overwriteOutput = True

infeat = 'G:\\Data\\Geodatabase\\Cedar_County.mdb\\SOILS\\SOILS_BY_PARCEL'
outputpath = 'O:\\CSR_Report\\'
dissolveoutpath = 'G:\\PROJECTS\\Cedar\\Soils\\testing\\'
outfeat = dissolveoutpath + 'dissolve.shp'
out_table = outputpath + 'CSR_Report.csv'

dfield = "PID"
statfield = "WEIGHTED_AVERAGE_CSR FIRST; SUM_ FIRST"
dfield = ['PID']

expression = "!FIRST_WEIG!"
expression2 = "!FIRST_SUM_!"
dropfields = ["FIRST_WEIG", "FIRST_SUM_"]

try:


    print "Starting Dissolve..."
    arcpy.Dissolve_management(infeat, outfeat, dfield, statfield,
                              "MULTI_PART", "DISSOLVE_LINES")

    arcpy.AddField_management(outfeat, "AVE_CSR", "FLOAT")
    arcpy.CalculateField_management(outfeat, "AVE_CSR", expression,
                                    "PYTHON")
    arcpy.AddField_management(outfeat, "TOTAL_CSR", "FLOAT")
    arcpy.CalculateField_management(outfeat, "TOTAL_CSR", expression2,
                                    "PYTHON")
    print 'Cleaning table' 
    arcpy.DeleteField_management(outfeat, dropfields)
    print 'Dissolve finished, now converting table to CSV'

    fieldnames = [f.name for f in arcpy.ListFields(outfeat)]
    arcpy.ExportXYv_stats(outfeat, fieldnames, "COMMA", out_table,
                          "ADD_FIELD_NAMES")
    
    print 'CSR table created sucessfully'

except:
    arcpy.AddError(arcpy.GetMessages(2))
    

    

0 Kudos
by Anonymous User
Not applicable
I have had a lot of problems with that tool as well, it seems to always have strange behavior.  I have just been using a work around and creating text files manually.  Here is an example:

 print 'Creating Text File...'
    text = open(p.join(ws, "Addresses2.txt"), "w")
    text.writelines('"Parcel_ID"\t"FULL_ADD"\t"POINT_X"\t"POINT_Y"')
    srows = arcpy.SearchCursor(address)
    for row in srows:
        pid = row.getValue('PID')
        add = row.getValue('FULL_ADD')
        x   = row.getValue('POINT_X')
        y   = row.getValue('POINT_Y')
        text.writelines('\n"%s"\t"%s"\t%f\t%f' % (pid,add,x,y))
    text.close()
 
    del row, srows
    print 'Text File Created Successfully'


This script uses a search cursor to grab the values from a table and writes them out into a text file.  This one is tab delimited, but it can easily be changed to comma delimited by replacing the \t with a comma.  If you don't have a lot of fields to write out this could be used as a work around.
0 Kudos