I am trying to edit my existing python code in the label expression in order to add one more bit of information to the map.

The purpose is to automate fire maps creation through data driven pages for info/billing purposes. The existing code displays the acreage of the owner agencies responsible the fire. It would be ideal if it will display their ownership as a percentage as well.

Attached is an example of the map currently being produced. Alcorn Fire Map

Code for the label in the center of the fire:

def FindLabel ( [BLM] , [BR] , [DNR] , [DOD] , [DOE] , [NPS] , [OS] , [Private] , [SITLA] , [SL_F] , [Tribal] , [UDOT] , [UDWR] , [USFS] , [USFWS] , [USP] ):
xBLM = xBR = xDNR = xDOD = xDOE = xNPS = xOS = xPrivate = xSITLA = xSL_F = xTribal = xUDOT = xUDWR = xUSFS = xUSFWS = xUSP = ""
if [BLM]:
    xBLM = "BLM: {} acres \n".format([BLM])
if [BR]:
    xBR= "BR: {} acres \n".format([BR])
if [DNR]:
    xDNR= "DNR: {} acres \n".format([DNR])
if [DOD]:
    xDOD= "DOD: {} acres \n".format([DOD])
if [DOE]:
    xDOE= "DOE: {} acres \n".format([DOE])
if [NPS]:
    xNPS= "NPS: {} acres \n".format([NPS])
if [OS]:
    xOS= "OS: {} acres \n".format([OS])
if [Private]:
    xPrivate= "Private: {} acres \n".format([Private])
if [SITLA]:
    xSITLA= "SITLA: {} acres \n".format([SITLA])
if [SL_F]:
    xSL_F= "SL_F: {} acres \n".format([SL_F])
if [Tribal]:
    xTribal= "Tribal: {} acres \n".format([Tribal])
if [UDOT]:
    xUDOT= "UDOT: {} acres \n".format([UDOT])
if [UDWR]:
    xUDWR= "UDWR: {} acres \n".format([UDWR])
if [USFS]:
    xUSFS= "USFS: {} acres \n".format([USFS])
if [USFWS]:
    xUSFWS= "USFWS: {} acres \n".format([USFWS])
if [USP]:
    xUSP= "USP: {} acres \n".format([USP])

return "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format(xBLM, xBR, xDNR, xDOD, xDOE, xNPS, xOS, xPrivate, xSITLA, xSL_F, xTribal, xUDOT, xUDWR, xUSFS, xUSFWS, xUSP)

If you have a field that represents the total area of the fire perimeter, which if you don't you can create it and calculate it in acres. You could then use that field, we will call it AREA, in combination with your other fields like this:

def FindLabel ( [AREA], [BLM]):
    return 'Percentage: %s' % str(float([BLM])/float([AREA]))

Without additional details about your fields, it is difficult to provide more specific information. In my example I simplified things to just one of your fields, however this should get you on your way. More information from ESRI about label expressions is available here.


Since it looks like all your passed fields are area values, get the total area, using your field list (place at beginning of function):

total = sum(map(int,locals().values())) # collect all passed values, cast to int (or float), and sum

Then, it's just a matter of formatting your labels to include the percentage, using the field value and the total.

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.