Select Field to export

5123
7
Jump to solution
12-03-2015 09:45 AM
ModernElectric
Occasional Contributor III

I am trying to write a model and/or python script that will select specific attributes and export a particular field.

Example:

I have a feature class of 10,000 electric meters and each meter is assigned a feeder assignment. I want to be able to select all of the rows that has a specific feeder assignment "P-1 Feeder" and than select only those in the "TWACs_Number" field and export ONLY the TWACs_Number field to a .CSV file so when someone opens the file, they see only the attributes from that one field, but nothing else. I already have the process to export but having a hard time getting the rest of it. I need to build a model/script that I can have run every night.

Thanks

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ChrisSmith7
Frequent Contributor

If you follow the model steps and select only the field you want in the "Export Feature Attribute to ASCII", it should only export that particular field (plus x and y, which you can remove by editing that tool's script).

So, say you have a table with 20 fields... you can apply your filter (where some attribute = "P-1 Feeder"), then select only the [TWACs_Number] field in the fields list within the "Export Feature Attribute to ASCII" tool. When you export, you should only have a CSV with the [TWAVs_Number] field and all of its attributes, where the feeder assignment = "P-1 Feeder".

I was able to get this to work both with making a feature layer, and by skipping this step (making a feature selection update, like in the model).

View solution in original post

7 Replies
ChrisSmith7
Frequent Contributor

Have you tried creating a table view from the selection with only that field marked for inclusion, then exporting your CSV?

UPDATE:

Actually, try using the "Make Feature Layer" tool - add your selection query, then choose only the field you want, e.g.:

That should output a temporary layer (for the session) you can then export.

ChrisSmith7
Frequent Contributor

After you do this, you can use "Export Feature Attribute to ASCII" to get a CSV, e.g.:

After you get your model set-up, you can export the Python script and schedule a Windows task to have it run every night. Here's some info on that:

Scheduling a Python script or model to run at a prescribed time | ArcGIS Blog

You may notice the "Export Feature Attribute to ASCII" includes x,y data in the output, in addition to your chosen field... you can open the script and edit this out, if needed.

ChrisSmith7
Frequent Contributor

One last suggestion, rather than using the "Make Feature Layer" tool, you can simply use the "Select Layer By Attribute" tool:

And then make your output column selection in the "Feature Attribute to ASCII" tool. So, you would have your input table, then you'd apply the query, then you'd export the CSV:

0 Kudos
ModernElectric
Occasional Contributor III

This is kind of what I am looking for. However, when I open the Excel file, there are a number of fields included even though I selected only (1) field in the "Visible" column of the Make Feature Layer tool. Not sure why that is? I have around 20 fields and only need to export the attributes selected from (1) of those fields.

Basically, I am saying find all of the attributes from the CIRCUIT_ID field that match "F-1 Feeder" and export the attributes under the TWACs_NUMBER field and only export the TWACs_NUMBER field. Somehow, it is not working exactly that way. Am I missing something or is there a setting wrong on my part? So far, you seem to be on the right track but I must be doing something wrong.

0 Kudos
ChrisSmith7
Frequent Contributor

If you follow the model steps and select only the field you want in the "Export Feature Attribute to ASCII", it should only export that particular field (plus x and y, which you can remove by editing that tool's script).

So, say you have a table with 20 fields... you can apply your filter (where some attribute = "P-1 Feeder"), then select only the [TWACs_Number] field in the fields list within the "Export Feature Attribute to ASCII" tool. When you export, you should only have a CSV with the [TWAVs_Number] field and all of its attributes, where the feeder assignment = "P-1 Feeder".

I was able to get this to work both with making a feature layer, and by skipping this step (making a feature selection update, like in the model).

DanPatterson_Retired
MVP Emeritus

One out of ordinary is to use

TableToNumPyArray—Help | ArcGIS for Desktop just specifying the fields to keep

then back to

NumPyArrayToTable—Help | ArcGIS for Desktop

to get it backinto Arc*

However, you can even skip that last step since numpy and python have the capability to get data into a variety of formats either directly (ie txt or csv) or via other modules.

You would have to make a script to use ina model however... unless you are ultimately getting the model to formulate  a script

AddisalemAbera
New Contributor

is there anyway to work on feature layer instead of feature class . it is powerful tool

0 Kudos