3

I am creating a map of protected areas/parks and want to display a letter label (A, B, C...) inside the polygons of all the parks in the map. The full names of the parks are too long to fit inside their respective polygons and make the map look cluttered. I know I could add a new field to the park layer's attribute table and type in the letters manually line by line, but since I have to repeat this process for several maps, I am seeking a more streamlined way to do this. Ideally the letters would appear in order on the map from left to right (W to E) and top to bottom (N to S) for easy reading, though that's not a requirement. I can't use the first letter of the parks as their label letter, since there are a lot of the names start with the same letter.

sample map

My goal is to create a map with the label letters inside the polygons, and then have a reference table with the letters, names, and other attributes on the side, where there's more room to write them out.

I'm working in ArcMap 10.6.1.

  • Sort using shape field, add text field and populate it using chr(!fid!+65) if sort output is shapefile. – FelixIP Nov 17 '18 at 1:13
1

I ended up obtaining numbers instead of letters, but here's my workflow.

1) add two new fields to the attribute table, and using the calculate geometry, calculate X_centroid and Y_centroid of the polygons.

2) Use the Advanced sorting to sort the fields: first sort the X centroid field as ascending (assuming your xs increase from west to the east, otherwise sort descending) and then the Y centroid field (descending, bigger numbers are the northern ones).

3) create a new field, where you will add sequential numbers, based on the sorting (the original code is here Calculating sequential numbers into sorted table using ArcGIS Desktop?)

So, with the field calculator, using python as Parser:

mxd = arcpy.mapping.MapDocument("CURRENT")
lr=arcpy.mapping.ListLayers(mxd)[0]
tbl=arcpy.da.TableToNumPyArray(lr,("oid","A","B"))
bs=sorted(tbl, key=lambda x: (x[1], x[2]))
aDict={}
for i,row in enumerate(bs):
aDict[row[0]]=i
def sortSeq(fid):
return aDict[fid]

-----------------------

sortSeq( !OID!)

Be sure to replace A and B with the actual X_centroid and Y_centroid fields.

If you now label your polygons, you will have increasing numbers from north to south and from west to east.

2

From what I have read, the easiest way would be create a new field(type string) in the feature table, instead of manually write out all the label names; use Field Calculator, select type string and apply a logic to create values for all the records in this new field.

Another way would be right click on the layer, go to Properties.., under Lables tab, click on Expression, apply some logic to display the label based on the selected existing filed name.

  • 1
    I'm able to convert a number in another field into a character via a formula. I'm having a hard time coming up with a formula to find the relative rank of each feature in the North → South, West → East order, but I suppose that's a different problem. – Mon Mo Nov 16 '18 at 23:48

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.