1

I am creating a ModelBuilder model, and from a feature class I am exporting the final output as .txt with "table to table" tool. (I just want a list of two fields (PID and DIST ). On the tool's field mapping list, the OID field is not there, but it shows up in the text file I create.

I tried to run "Make Table View" tool without the ObjectID field, but it still shows up in the output.

So, in the final output I have 3 fields: OID, PID, DIST (instead of PID and DIST only).

How can I get rid of the OID field?

  • 2
    I doubt you can. ArcGIS tools need a rowid column, so they populate tables in a way that they can read what was just populated. – Vince Aug 28 at 23:01
  • Why do you need to have the OID field removed? Ie, how is the .txt file going to be used? (This may help to determine how to manage the issue.) Also, are you open to a Python solution? – Son of a Beach Aug 28 at 23:23
  • I am creating a model which other people will use. And they want the end product to be clean. In this case, I do not have much choice... I will try to do it with Python, possibly with pandas. Thanks a lot!! – Meriç Aug 29 at 15:51
3

I don't think it's possible for ArcGIS to produce a table without an OID column. Therefore, a solution/work-around would be to remove the OID column after it is created.

You can do this within the model itself by using a 'Calculate Value' item to run some Python code to remove the OID field after the export. (You can just ignore the output of the 'Calculate Value'. Or you could use it as a precondition if the model needs to do anything else afterwards.)

The Python could use a CSV or data management module such as 'Pandas' and would be a fairly simple script, something like the following (untested)...

Expression:

removeOIDFromCSV("%Output Table%", "%NEW Output Table%")

Code Block:

import pandas

def removeOIDFromCSV(inCSV, outCSV):
    dataframe = pandas.read_csv(inCSV)
    del dataframe['OID']
    dataframe.to_csv(outCSV, index=False)

Note that the percent symbols in the Expression are used to delimit the names of other objects in the model. When the model is executed, these items will be replaced with the values of those objects. In the example above, you would use the names of your original output CSV object in the model, and the name of the intended (no-OID) output CSV object in the model (or if there is no such object elsewhere in the model, just use the actual full path to the intended CSV location).

Note also that in this case, these parameters must be in quotes, because they will be string literals.

  • Thank you for the response! I already know how to do it in pandas/geopandas but putting it in a model never came to my mind!! Thanks a lot. – Meriç Aug 29 at 15:49
  • Yes, using 'Calculate Value' in a model is very useful for incorporating odd snippets of Python without having to have part of process in a model and part of it separate from the model! I don't think it was intended to be used this way, but it sure is useful for this. – Son of a Beach Aug 29 at 22:37
  • That really worked well! But I need to type the whole path in order to get the tool run. For example, before using Calculate value I am using "Table to Table" tool, and I specify Output table location for it. But when I use the Calculate Value tool I have to write the entire path of the Table to Table output table. I could not find a way to use the output table location for the CV. Is it possible to set it for CV? I am creating this tool for other people, and I want them to enter the output location only once. – Meriç Sep 3 at 19:54
  • You can use any item in your model, including the output table, in the 'Expression' part of your Calculate Value. I'll add the the details to this answer... – Son of a Beach Sep 3 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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