Selective Labeling in Data-Driven pages based on data frame extension

3173
6
12-19-2013 03:40 AM
MateusRomanholi
New Contributor
Hello,

I've been working with Data Driven pages that show an overview map for the selected index layer feature.

However, under the index feature layer I need to show the boundaries of municipalities (polygons) as well as a point feature indicating their urban area.

I need to label both feature classes and that's where the challenge arises:

1 - When the point feature is labelled, the polygon feature should not get its label;

2 - If the point feature is not within the data frame extension (thus not labelled), the polygon feature gets its label;

3 - Each polygon feature has a corresponding point feature.

I'm attaching an image to make it clearer. I need to automate the process, as I'm using Data Driven pages.

Is it do-able with scripting? Is there any easier way for doing that?

[ATTACH=CONFIG]30007[/ATTACH]
0 Kudos
6 Replies
MattSayler
Occasional Contributor II
You could add attributes to the index features and use that to drive which layer to label. I.e. add a yes/no "LabelPoints" field and then add something like the following:
# untested, ~psuedo code
rows = arcpy.SearchCursor(indexGridLayer, "{0} = '{1}'".format(arcpy.addFieldDelimeters(indexGridLayer,"PageName"), currentPageName)
for row in rows:
  if row.getValue("LabelPoints") == "yes":
    pointsLayer.showLabels = True
    polygonsLayer.showLabels = False
  else:
    pointsLayer.showLabels = False
    polygonsLayer.showLabels = True


This does add a little maintenance to the process, as you need to review that the attribute is correct periodically, but if things don't change much, that's probably not a big deal. With that added maintenance, I'm not sure if this is the best solution but it is a solution.
0 Kudos
MateusRomanholi
New Contributor
You could add attributes to the index features and use that to drive which layer to label. I.e. add a yes/no "LabelPoints" field and then add something like the following:
# untested, ~psuedo code
rows = arcpy.SearchCursor(indexGridLayer, "{0} = '{1}'".format(arcpy.addFieldDelimeters(indexGridLayer,"PageName"), currentPageName)
for row in rows:
  if row.getValue("LabelPoints") == "yes":
    pointsLayer.showLabels = True
    polygonsLayer.showLabels = False
  else:
    pointsLayer.showLabels = False
    polygonsLayer.showLabels = True


This does add a little maintenance to the process, as you need to review that the attribute is correct periodically, but if things don't change much, that's probably not a big deal. With that added maintenance, I'm not sure if this is the best solution but it is a solution.


Hello, msayler, I really thank you for your answer!

I know almost nothing about coding, so I apologize if the following questions seem too dumb:

- Does this code you provided allow some point and some polygon features to be labelled at the same time (at the same page)? I need both features to be labelled, the preference being for point features over polygon features when features that have the same attributes (one being point and the other being polygon) occur within the data frame.

- Where in ArcMap should I insert the code, so it executes every time I change data-driven pages?
0 Kudos
MattSayler
Occasional Contributor II
Hello, msayler, I really thank you for your answer!

I know almost nothing about coding, so I apologize if the following questions seem too dumb:

- Does this code you provided allow some point and some polygon features to be labelled at the same time (at the same page)? I need both features to be labelled, the preference being for point features over polygon features when features that have the same attributes (one being point and the other being polygon) occur within the data frame.


Are you refering to label weighting? i.e. if the two labels are in conflict, show the one for the point?


- Where in ArcMap should I insert the code, so it executes every time I change data-driven pages?


That example is just a snippet of pseudo code. It would have to be either set up as part of a script tool that generates the maps outside of an ArcMap session (i.e. exports to a pdf mapbook), OR if you want to work in a live session, you'd probably want custom add-in tools (or copy and paste into the python window, but that's not as user-friendly).

Either way, you're looking at investing some time in learning python or finding someone who can build it for you (unfortunately, I just don't have the time to put the whole thing together).

If you do a lot of this sort of custom mapbook work and if you can make the time, I would highly recommend learning python. Even just a foundation in the basics can be pretty liberating.
0 Kudos
MateusRomanholi
New Contributor
mslayer, I followed your advice and started learning Python this week!

Today I was able to come up with a script that does exactly what I want!

Basically, the workflow I created is as follows:

1. Loop through each Data Driven Page
2. Create a temporary polygon from the data frame extension
3. Select the point features that intersect that polygon
4. Run a cursor through the selected point features and store their attribute values in a list
5. Set an SQL Query in the label class of the polygon features so as not to label the values stored in the list
6. Print the map to PDF.

Despite all the time I spent debugging, it was really good to see everything work in the end! 🙂

Thanks!
0 Kudos
MattSayler
Occasional Contributor II
Congratulations! Whole new world now, isn't it? 😮
0 Kudos
MateusRomanholi
New Contributor
Congratulations! Whole new world now, isn't it? 😮


Sure! Liberating indeed! 🙂
0 Kudos