1

I made a little model and at the end I want to rename the feature class file to something based on the fields in that feature class. I want to rename that feature class by the date the data was collected (its a field in the FC) follow by an underscore then by the editor of the FC (which is also a field). The way our files are setup is the data is collected on the same date by one person. So there is no danger of having 2 editors to one file or 2 dates. I am just really new to Python.

I used it to do field calculations and have that understood fairly well. But I am trying to figure out the command to pull the field value and print it in the rename.

I have the stock python script for rename

# Name: Rename_Example2.py
# Description: Rename fileGDB feature class
# Import system modules
import arcpy
from arcpy import env
# Set workspace
env.workspace = "C:/workspace/test.gdb"
# Set local variables
in_data = "test"
out_data = "testFC"
data_type = "FeatureClass"
# Execute Rename
arcpy.Rename_management(in_data, out_data, data_type)

How do I put the fields with the data into the "out_data"? I figure I have to collect it some how, maybe in the local variables? You don't need to write the script for me, but if you could point me to a solid source for commands and strings that would be great. I already checked out other threads and the python site.

https://docs.python.org/2/library/string.html#formatspec

It seems close to what I need but I am still not getting it.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 12, 2014 at 20:16
0

2 Answers 2

2

You want ListFields: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001p000000

in_data = "test"
out_data = "testFC"
fields = arcpy.ListFields(in_data)
for f in fields:
 print f.name
# join prefix and desired field names with an _
new_name = '_'.join([out_data, fields[0].name, fields[1].name])
# data_type is usually optional...
data_type = "FeatureClass"
arcpy.Rename_management(in_data, new_name, data_type)
answered Dec 12, 2014 at 20:49
0
0

In case someone has the same issue, this is my solution.

import arcpy
fc = "C:\mygdb\myfile"
f1, f2, f3 = "EDITOR", "SPECIES", "OBJECTID"
clause = arcpy.AddFieldDelimiters(fc, f3) + "= 1"
for row in sorted (arcpy.da.SearchCursor (fc, [f1, f2], clause)):
 print ("{0}_{1}".format(row[0], row[1]))
 name =("{0}_{1}".format(row[0], row[1]))
 arcpy.Rename_management(fc, name)

Our field data is collected on a trimble. Each time we start to collect we open a new file, so everyday its a new file, meaning the date is always the same as is the editor (we have our own units). So I made a complicated model that buffered our points and lines into polygons, then merged them with our polygon layer, than did some spatial joins to slops and aspect layers than calculates the slope field into a text value (Steep or whatever), than there is a bunch of other things but the output is always the same file name, so I made this last script to run and rename each file based on the park the data was collected in (one of the joins is to a park layer) the editor, and the date. It worked really well and was fun to learn.

answered Dec 16, 2014 at 15:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.