[GIS] Single label for multiple features with different values in ArcGIS Desktop

arcgis-10.2arcgis-desktoplabelingpython-parser

I have several sample locations, that have been sampled several times at the same location. I want to label each location with stacked data from each location. So it would hopefully look like this

"Sample Location 1:

Depth 0-6: .314

Depth 6-12: .315

Depth 12-48: .398"

And so on. The problem right now, is that if I try and label them with label expressions, I can stack the fields but not the rows. So I get 5 labels for each location. This is because the depth measurements have their own points. I need the unique values so I cannot dissolve/aggregate the points into mean values, so that eliminates a lot of tools.

I also cannot simply display the different readings in labels located around the point. Because there are so many points, and I need to label all of them, the only way I can think of to label all of them at once is to combine them into single labels for each point and THEN do Maplex operations to get all the labels displayed properly.

I have explored python expressions and I am having a hard time finding something close to what I am doing. This StackOverFlow question has been suggested for me to attempt but it has not worked for me:
Can labels for overlapping points be combined/merged into one label?

When I try the "Update #2" code in that solution it simply says "No Features Found: Could not Verify Expression". I am also not sure that's what I am even looking for because I do not want the sample data averaged or aggregated; I want the unique sample data displayed for each point.

In terms of label expression, I think of pseudocode like this:

def FindLabel ( [SAMPLE], [DEPTH], [READING]): 
     print [SAMPLEID]
     for [DEPTH] within [SAMPLEID]:
        return [DEPTH],  [GLNPO_TOTA], [FIELDS_TOT]

Where hopefully it would be possible to have ArcGIS display a sample location, then the depths and values below it, all as one label. That's the idea at least.

Best Answer

Look at my code in this blog post for how to connect a single point to a separate table or feature class to list all of the related data stored in multiple records/points. You want to dissolve your points based on a location ID to create a separate point feature class that contains just a single point for each physical location (you won't be using any aggregated fields created by the dissolve, just the location ID). This avoids having to deal with label duplication and greatly improves the speed of labeling. The single point feature class must have a field with a unique ID for each point that is also contained in all of the overlapping points at that location. Then the code can list all of the overlapping point data in a single label using a cursor and a dictionary.

The key to the code I have designed is the use of a global dictionary variable in the label expression that is populated for all points once by a cursor when the first label is being created. The actual labels do not read the data directly from the cursor, they just use the dictionary, which is at least 10 times faster than running separate queries for each point. The dictionary key is the Unique ID for each unique physical point location and the value associated with each dictionary key contains a list of all the related data you need from the separate points for each given location. Once you are set up to read field data from the lists in the dictionary, the rest of the label code is all about formatting the output.