Select to view content in your preferred language

Delete 1st field/column

1953
3
01-23-2012 09:05 AM
MathieuCain
Occasional Contributor
Hello,

I am in the process of creating a model that will take GIS features and create all the necessary inputs needed for use in an external 3D modelling software, including legend files. What I'm struggling with is getting the legend file into an appropriate csv output with only very specific information (e.g., no extra fields, or records).

Using the "Additional Conversion - Generic Tools" http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=95009B25-1422-2418-7FB5-B8638... tool I am now able to export a table to a csv. However the csv still contains an ID field (i.e., first field) which I would like to remove automatically through the geoprocessing model.

Is there some simple python code I can use for this and if so how do I incorporate it into the model in ArcCatalog?

Thanks!
Tags (2)
0 Kudos
3 Replies
curtvprice
MVP Alum
There is a better tool for this in the Spatial Statistics Tools. It doesn't include any fields you do not want.

Export Feature Attribute to ASCII
0 Kudos
MathieuCain
Occasional Contributor
There is a better tool for this in the Spatial Statistics Tools. It doesn't include any fields you do not want.

Export Feature Attribute to ASCII


Thanks for the reply.

How would this work though using a table as an input rather than a feature layer?
0 Kudos
curtvprice
MVP Alum
Sorry, you're right, this tool (and the python script it calls, D:\ArcGIS\Desktop10.0\ArcToolbox\Scripts\ExportXYV.py), only supports feature class input.

You could manipulate your output csv file using python code in a Calculate Value tool with a function embedded inside, it, for example:

expression:
fixfile(r"%Output file%")

("Output File" is a model element; note the "r" and the quotes, they are important. Make "Output file" a precondition so it will exist when the Calculate Value is run.)

Code block:
def fixfile(infile):
  # read file into a list,   
  f = open(infile,"r")
  lines = readlines(f)
  f.close()
  # for each line, delete first column, write back
  f = open(infile,"w")
  for line in lines:
    linelist = line.split(",")
    lineout = ",".join(linelist[1:])
    f.write(lineout)
  f.close()


I'm assuming there are no embedded commas in your data. That would break the script.
0 Kudos