Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am currently working on a County plat book and am in the process of prepping the "Owner_Nm" field that will serve as my annotation layer. I am trying to whittle down the owner names, based on parcel size, to either full name (easily done) to first initial + full last name or just initials. The format of the names is currently something like this "John H Smith" or "John H Smith & Lucy L Smith" for example. I know next to nothing about python in field calculator so I am hoping to get some help from this community. INRE: how to write my python code in field calculator to return, dependent on parcel size, either (using the above examples) "J H Smith" or "J H S" or "J H Smith & L L Smith" or "J H S & L L S". I have nothing to offer as to the code I've tried as it has mostly returned gibberish....Thanks in advance.

share|improve this question
    
Have you considered using the Maplex Labelling Engine (now included at all license levels) to abbreviate and truncate your labels? –  PolyGeo Feb 28 at 22:46
    
@PolyGeo I like the idea of Maplex labeling in theory for all of this task, but that may be a LOT of work to correctly populate the abbreviations table or rely on Maplex to handle all of the abbreviations consistently. I think it would be easier for them to do the up-front calculating work they are asking about and then use Maplex to place the labels (shrink, overrun, etc... to make all labels fit once you have them generically size appropriate). –  John Feb 28 at 23:12
    
@PolyGeo, I am trying to cut down on the amount of work as there are some 29000 parcels total with annotation, either acreage or ownername, or both. I have ID'd the parcels that have changed or been created, about 4000, since the last plat book publication. I would like to keep the previous versions annotation layer and just update/append to it rather than use, and trust, mapplex to do the job. –  user21646 Mar 1 at 3:44

2 Answers 2

up vote 0 down vote accepted

Well, I agree with one of the comments above about using Maplex if that will work for you. If it doesn't though, what you could do is use the field calculator as you suggest. For the all initials (J H S & L L S) You would want to do something like the following:

Code Block / Pre-Logic Script Code:

def nameCalc(inName):
    outName = ""
    namesList = inName.split("&")
    for name in namesList:
        outName = outName + " &"
        nameL = name.split()
        for word in nameL:
            outName = outName + " " + word[0]
    outName = outName.strip(" &")
    return outName

and then in the expression you would put nameCalc(!Owner_Nm!)

You could select the parcels you want just initials for and then run that. However, if you want to do them all at once and you have an area field or such as that that you want to use to automate the process (ex: all parcels larger than or equal to 5 acres get full name, between 5 and 1 acres get abreviated, and smaller than 1 gets just initials), then you could do something like the following in the code block:

def nameCalc(inName,area):
    outName = ""
    if area < 1:
        namesList = inName.split("&")
        for name in namesList:
            outName = outName + " &"
            nameL = name.split()
            for word in nameL:
                outName = outName + " " + word[0]
        outName = outName.strip(" &")
    if area >= 1 and area < 5:
        namesList = inName.split("&")
        for name in namesList:
            outName = outName + " &"
            nameL = name.split()
            for word in nameL:
                if word != nameL[-1]:
                    outName = outName + " " + word[0]
                else:
                    outName = outName + " " + word
    if area  >= 5:
        outName = inName
    outName = outName.strip(" &")
    return outName

and then in the expression you would put nameCalc(!Owner_Nm!,!Acres!) PLEASE NOTE THOUGH: if you do that, you would A) Have to replace the 1, 1, 5, & 5 with the appropriate values for your data and what you want and B) you would have to replace !Acres! in the expression with whatever area/size field you wanted to use and that field would have to be a numeric field for the code above to run correctly.

I know that's a lot of code, and it may be a bit to work your way through, but it should return each of the 3 desired results and will correctly handle both single names and double names separated by &

I hope that helps, and if you have questions, feel free to comment and if I can help, I will try to.

share|improve this answer
    
@ user2856159 I have created another field that will use a coded domain to break out my acreage/parcel sizes by what annotation I will use. I can then just change the code you supplied, as you pointed out, to make my name field changes. You gave me enough to play around with, format wise, (I do know a LITTLE python, enough to get myself in trouble, anyway)to make any changes I might wish to see...I will come back to this if there is something else I need to ask. Thank You! –  user21646 Mar 3 at 18:46

The easiest method for this using python is to use the find method, or in this case rfind, so you can look for the last space to pull out the last name. find/rfind will return a numerical value for where the character you are looking for is in the string. You can use this number to slice the sting using [].

In the "Pre-Logic Script Code" section in the field calculator paste the below.

def initial(name):
    return name[0]+" "+name[name.rfind(" ")+1:]

Then in the "field_name =" section you can write initial(!Owner_Nm!). The way this works is for each value in "Owner_Nm" it runs it through the initial function. The initial function takes the 1st letter (name[0])in the name and concatenates it with everything in the name after the last space it finds.

So for the example you provided "John H Smith", you would get "J Smith".

share|improve this answer
    
@ Hotpepper thanks for the suggestion, but it didn't quite give the results i was looking for in respect to multiple owners of a parcel. Works perfect for a single owner though. –  user21646 Mar 3 at 18:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.