0

I am trying to automate a mapping effort: I am mapping a (FC) features class ( with multiple data fields representing different results). I need to visualize each data field (from the same FC) using similar graduated color symbology (~ 5 classes) with specific brake values for each data field. Save the layer, save the mxd, export a PDF.

How do I set up a Library for each data field (break values for symbology classes), iterating through the data fields (field 1, field2, ….field36), updating layer symbology, save layer, save mxd, export PDF. I am using 3 data frames, each maps same FC with an definition query.

  • 1
    Do you have any experience with Python? – juturna Mar 11 '15 at 19:19
  • Obviously not enough. Learning. I imagine arcpy.mapping.UpdateLayer should do the trick. But I can’t figure out how to loop through the data fields. Perhaps create a Library first with the specific parameters for each data field?? – Alex Vasiliev Mar 11 '15 at 19:25
3

This script works on current mxd:

import arcpy, traceback, os, sys
from arcpy import env
env.overwriteoutput=True
try:
    def showPyMessage():
        arcpy.AddMessage(str(time.ctime()) + " - " + message)
    def isLayerExist (mxd,lName):
        layers = arcpy.mapping.ListLayers(mxd,lName)
        if len(layers)==0:
            raise NameError,'\n'+lName + " layer not found. Exiting.."+'\n'
        result=layers[0]
        return result
    mxd = arcpy.mapping.MapDocument("CURRENT")
    theLayer = isLayerExist(mxd,"Points")
    theFields=["aspect","arc2mdem"]
    theSplits=([-1,0,22.5,247.5,360],[0,10,20,30,70])
        sm=theLayer.symbology
        m=0
    for fld in theFields:
                breaks=theSplits[m]
                sm.valueField=fld
                sm.classBreakValues=breaks
                arcpy.RefreshActiveView()
                arcpy.RefreshTOC()
                m+=1
                arcpy.mapping.ExportToPDF(mxd, "D://rubbish//"+str(m)+".pdf")   
    del mxd
except:
    message = "\n*** PYTHON ERRORS *** "; showPyMessage()
    message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
    message = "Python Error Info: " +  str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyMessage()

It works on 2 fields as an example, obviously you need to modify it to suit your needs. You might also consider adding

sm.classBreakLabels = ["0-10", "10-20" etc]

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.