concatenation of fields using python

2007
11
Jump to solution
12-07-2012 07:04 AM
JessicaKirby
New Contributor III
Hi Python Guru's
I need help figuring out how to populate an attribute field using python

I need to create a label field that is a concatenation of 4 fields in my dataset; Quad, Township, Range and Section

My problem is that the Quad is a numeric field that represents the direct or text label

for example
Quad = 3 (where 1= NW, 2 = NE, 3 = SW, 4 = SE)
Township = 16
Range = 42
Section = 36

the output label field needs to be a text field that reads like this:  T16S R42W Sec36 
Where the S in township  and W in range come from the quad = 3 for SW

I have no idea where to start this one. Any help is truly appreciated!
Tags (2)
0 Kudos
11 Replies
JessicaKirby
New Contributor III
This is awsome! Works like a charm, Thank you so very much!

Caleb,
I have to bug you one more time.  So this worked just fine on my test dataset with lives on my c: drive in a GDB, but when I try to apply it to my SDE feature class I get an error :

  File "V:\GIS\DataEdits\AutomatedTasks\test\addTRSLabel.py", line 54, in <module>
    row.LABEL = 'T%s%s R%s%s Sec%s' %(twp, quad.split(' ')[0], rng, quad.split(' ')[-1], sec)

Error Info:
'NoneType' object has no attribute 'split'

ArcPy ERRORS:


and when I look at the attribute for the new feilds in the fc on SDE they are not populated....any thoughts as to why this would happen.  Note that I did change the sections source  from
sections = r'C:\Users\jkirby\Desktop\Junk and Email\TestData\TestData.gdb\Owner_Surface'
sections = r'Database Connections\owner_PUB@tla-gis.sde\SITLA.PUB.Owner_Surface_1'

thanks again for your time!
0 Kudos
by Anonymous User
Not applicable
I'm afraid I cannot help you there.  I have never used SDE before, but I have seen that people have had a similar problem.  Have you verified that the field names are the same?  If the table has the same schema it doesn't make sense why it would work on your test FC and not on the FC in the SDE database.  Did it add those fields extra fields in?  Hopefully someone with who knows more about SDE will see this and have some insights.
0 Kudos