-1

I have little experience with python. I'm using ArcGIS 10.4. I'm attempting to create pdfs of layouts in which polygon features are symbolized with the same colors for classes, but the assignments change in each of 1,000 fields in the feature class. That is, I want to loop through each field (00000, 00001, 00002...), symbolize the categories (1-13) as set up in a .lyr file, change the map title to match the field name, print a pdf of the layout, & move to the next field to do it again.

What I have will have to change is the map title & print the pdf with the title. The problem is every map is the same, except for the title. The polygons aren't given symbology according to the .lyr file, they're identical to the .lyr file.

I don't think it should matter, but the shapefile I'm symbolizing has 2692 rows. I need to display one field at a time, with each polygon (row) in the field shaded a specific color, depending on it's value, 1-13. Clarification:(Actually, there will be many rows of each class 1-13. Each row with a particular value gets the same color)

I've been asked to clarify the question. Yes, I want to generate 1000 pdfs, one for each field in a feature class, each with a title corresponding to the field name. The legend should stay the same. The colors for class 1, class 2, class 3, etc. should stay the same (they're defined by RGB values).

What I have:

import arcpy  
import os  
mxd = arcpy.mapping.MapDocument("CURRENT")   
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]    
featureclass = arcpy.mapping.ListLayers(mxd, "*", df)[2]   
symbologyLyr = arcpy.mapping.Layer(r"\\path\Maps\SymbologyShp.lyr")  
field_names = [f.baseName for f in arcpy.ListFields(featureclass)] 
for f in field_names:          
    if f.startswith("Map"):        
        arcpy.mapping.UpdateLayer(df, featureclass, symbologyLyr, True)       
        TextElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitleText")[0]               
        TextElement.text = f                 
        arcpy.mapping.ExportToPDF(mxd, r"\\path\outputPDF\Map_" + f)
  • 2
    Typically better to use the "code block" for codes >3 lines. I've edited this for you, but you should also remove the "..." before posting. – GISKid May 17 '17 at 20:39
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. – Midavalo May 18 '17 at 15:00
  • Do you have 1000 Fields in your feature class? Currently your script is outputting 1000 PDFs (one for each field) of the exact same map with a different title. Is this what you want? If not please edit your question to include a bit more information and description of your data. – Midavalo May 18 '17 at 15:17
  • I'm still finding this unclear. I note your clarification, so I have another query - are you wanting your PDFs to be identical other than the page title? What else are you expecting to see changed, and how are you changing that? – Midavalo May 18 '17 at 18:19
  • Re-reading I see I didn't exactly clarify. Each map has a different title and shows different polygons, within the same extent (a particular US state). – R_exists May 18 '17 at 18:35
1

Your loop is changing only the title, nothing else.

for f in field_names:          
    if f.startswith("Map"):        
        arcpy.mapping.UpdateLayer(df, featureclass, symbologyLyr, True)   

The exact same layer is being applied here every time it loops; there is no reference to values in a field or to a different layer file. You could put the arcpy.mapping.UpdateLayer() line outside of the loop and it would have the same effect.

Since you say you want to apply the symbology from the layer, you probably should look at using arcpy.ApplySymbologyFromLayer_management(featureclass, symbologyLyr) instead of UpdateLayer(). See Apply Symbology From Layer.

        TextElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitleText")[0]               
        TextElement.text = f                 

The Text Element is being changed to the name of the field, as you require

        arcpy.mapping.ExportToPDF(mxd, r"\\path\outputPDF\Map_" + f)

And the PDF is created using the field name.

  • Midavalo, Thank you for your help. Based on results, it could be that the 'UpdateLayer' statement isn't looping. Question: if 'UpdateLayer' isn't looping, why do 'TextElement' and 'ExportToPDF' below it loop? I thought everything under 'for f in field_names:' would loop. – R_exists May 18 '17 at 18:01
  • @R_exists It's in the loop, so it's running every time. What I mean is that it's not doing anything different each time it runs, it's performing the exact same operation. The Text Element and Export are performing different operations. – Midavalo May 18 '17 at 18:02
  • I see what you're saying now. Thinking about ApplySymbologyFromLayer, not sure how that would work. I need to find a way to change the value field for the feature class. – R_exists May 18 '17 at 18:26
  • @R_exists What do you mean? Are you trying to filter what is shown based on a field, or calculate a field, or symbolise on a value? – Midavalo May 18 '17 at 18:27
  • I am trying to symbolize on values in a field. – R_exists May 24 '17 at 16:20

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.