Select to view content in your preferred language

Control Extent on Export Web Map

988
0
03-09-2021 02:16 PM
Status: Open
Labels (1)
jeremiahsandahl
New Contributor II

We're using ArcGIS Python API to generate images that have symbols added for each row of a spreadsheet. Our script geocodes, adds the features, and filters the features. From those queried features we get the max and min X and Y values and use those to set the map extent. The resulting extent and map definition is used as the basis for our arcgis.export_map, which generates the image. 

Because the symbols are a fixed size, but the distance between them can vary between 50 feet and 100 miles, the rendering is inconsistent. For now, we have 2 workarounds in place to ensure symbols aren't clipped from the resulting image. 

Workaround #1: Make a square extent by using web mercator coordinates to take the shorter of the two sides and pad it equally by the difference of the longer side. Because we know the output will be square, this should prevent a long rectangle from cropping to the center of the rectangular extent. 

Workaround #2: To account for the actual width of the symbols themselves (i.e. 16px) a larger padding is required on larger geographic surfaces than on smaller ones. The symbols could cover 50' on a small map or 50 miles on a large one. So we now add or subtract a percentage of the distance between one side of the square to enlarge the map extent. 

def squareExtent(ex😞
    xdiff = ex["extent"]["xmax"] - ex["extent"]["xmin"]
    ydiff = ex["extent"]["ymax"] - ex["extent"]["ymin"]
    if xdiff > ydiff: 
        y_factor = (ydiff - xdiff)/2
        ex["extent"]["ymin"] = ex["extent"]["ymin"] - y_factor
        ex["extent"]["ymax"] = ex["extent"]["ymax"] + y_factor
    if ydiff > xdiff:
        x_factor = (ydiff - xdiff)/2
        ex["extent"]["xmin"] = ex["extent"]["xmin"] + x_factor
        ex["extent"]["xmax"] = ex["extent"]["xmax"] - x_factor
    maxdiff = max([xdiff, ydiff])
    ex["extent"]["xmin"] = ex["extent"]["xmin"] - .2 * maxdiff
    ex["extent"]["xmax"] = ex["extent"]["xmax"] + .2 * maxdiff
    ex["extent"]["ymin"] = ex["extent"]["ymin"] - .2 * maxdiff
    ex["extent"]["ymax"] = ex["extent"]["ymax"] + .2 * maxdiff
    return ex
 
Instead of these workarounds, it would be nice to have a parameter on the arcgis.export_map() that would control whether to clip the extent or scale out to fit.