Tag Maps label placement animation

For the video shooting with joul, I wanted to create a short animation that illustrates the label placement algorithm for tag maps, placing labels in descending order and in several classes on the map.

Since tag maps visualization is still only implemented in ArcMap / ArcPro, I needed to automate the map generation.

This was done with ArcPy, a python package that allows automation of the ArcMap interface.

Here’s the script that will iterate over Weights and output individual maps (~350), gradually including less weighted tags and emoji in the map.

# coding=utf-8
import arcpy, os

def unique_values_where(table , field, where_clause):
    """Get values from table for specific field in descending order, 
       optional include a limiting where query
    """
    with arcpy.da.SearchCursor(table, [field], where_clause) as cursor:
        return list(reversed(sorted({row[0] for row in cursor})))
        
# Specify output path and final output PDF
out_path = r"C:\temp\out"

# Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(
    r"CampusMap_MapSeries.mxd")

ix = 0
for layer_ref in ["Top10", "HImp", "Other"]:
    layer = arcpy.mapping.ListLayers(mxd, layer_ref)[0]
    layer.visible = True
    
    def_query_old = layer.definitionQuery 
    # print "def query: " + def_query_old
    
    # now we need to get the unique values for "Join_Count"
    # and use those to loop over Definition Query,
    # starting with the smallest values (for Photo Count)
    values_source = layer.dataSource
    
    # process top10 first
    unique_values = unique_values_where(
        values_source, "Weights", def_query_old)
    print len(unique_values)
    print unique_values[0]
    
    # set what is given in mxd layers
    if layer_ref == "Top10":
        base_query = '"HImpTag" = 1 AND "Weights" >='
    elif layer_ref == "HImp":
        base_query = '"HImpTag" = 1 AND "Weights" < 300 AND NOT "FID" = 6232 AND NOT "FID" = 2361 AND "Weights" >='
    else:
        base_query = '"HImpTag" = 0 AND "Weights" < 200 AND "Weights" >='
        
    for unique_value_step in unique_values:
        def_query_new = base_query + str(unique_value_step)
        layer.definitionQuery = def_query_new
        print def_query_new
        arcpy.mapping.ExportToPNG(mxd, out_path + r"\map_" + "%03d" % (ix,) + ".png")
        ix += 1

# clear memory/close the map
del mxd

Afterwards, the generated image sequence was combined to a webm video in Adobe Premiere, using the WebM Plugin.