I would like to dynamically classify a layer's symbology based on the current view extent. As in, quantities of a specified field will be classified into quantiles based on the range of values of the visible features. Since the symbology tab does not appear to support this out of the box, I need to instead limit the layer's values to those within the visible extent. I know ArcMap supports exporting data to those features limited to the view extent.

Is this possible with ArcPy?

closed as off-topic by PolyGeo Nov 17 '18 at 4:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I think exporting all features in the view extent is no problem using ArcPy. However, dynamically classifying symbology is where you may come unstuck. I think you should focus this question on solving just that first part, and start by including a code snippet of what you have tried so far. – PolyGeo Oct 24 '15 at 0:40
  • Have a look at gis.stackexchange.com/questions/142890/… – FelixIP Oct 24 '15 at 2:56
  • @FelixIP - Thanks, but that question was specifically for raster. The first answer would have been useful, but Clip_analysis does not support coordinates as clipping bounds, unlike it's raster-based equivalent, Clip_management. Looks like I would have to create a vector to clip to in order to go that route. – user1185790 Oct 24 '15 at 3:25
  • Virtual polygon geometry will do. After this you can do clip into in_memory, or just select by location and re-compute min-max for selected values – FelixIP Oct 24 '15 at 3:37
  • 1
    I've not seen it called that but the term seems to be being used for a geometry object which is being created in the answer code by polygon = arcpy.Polygon(array) – PolyGeo Oct 24 '15 at 4:26

Have a look at this script, it clips all the layers in mxd using clipping polygon or optional dataframe extent


import arcpy, sys, os
from arcpy import env
env.overwriteOutput = True
# Argument 1 is the list of Rasters to be converted
clipFeatures = arcpy.GetParameterAsText(0)
inRasters = arcpy.GetParameterAsText(1)
# The list is split by semicolons ";"
inLayers = inRasters.split(";")
anOutPutFolder=arcpy.GetParameterAsText(2)+ os.sep
mxd = arcpy.mapping.MapDocument("CURRENT")

    def isLayerExist(mxd,lName):
            layers = arcpy.mapping.ListLayers(mxd)
            for l in layers:
                if l.name in lName:
                    return l
            raise NameError,'\n%s layer not found. Exiting..\n'%lName
    if len(clipFeatures)==0:
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        array = arcpy.Array([arcpy.Point(ext.XMin,ext.YMin),
        polygon = arcpy.Polygon(array)
    envelope='%f %f %f %f' %(anExtent.XMin, anExtent.YMin, anExtent.XMax, anExtent.YMax,)
    for inL in inLayers:
        desc = arcpy.Describe(inRaster)
        if theType=='RasterDataset':
            arcpy.Clip_management (inRaster, envelope,anOutPutFolder+os.sep+theFile )
            if m==-2:
                theFile=theFile +".shp"
            arcpy.Clip_analysis(thePath, clipFeatures, outFile, "")
            if nFeatures==0:
        arcpy.AddMessage ("...processed")
except NameError, theMessage:
    arcpy.AddMessage (theMessage)
    arcpy.AddMessage("Something wrong")

You'll see clearly what virtual polygon is. It is just a geometry..

  • Sweet! That did the trick! Thanks man. The symbology portion should be a bit more straight forward - I believe I'll need ApplySymbologyFromLayer and symbology.classBreakValues for the final portion of creating a dynamic symbology. @PolyGeo - I'll do my best to add the completed code once this is all done. Thank you for your help @FelixIP! – user1185790 Oct 24 '15 at 4:09
  • Glad it works. Correct classBreakValues is the only thing to recalc – FelixIP Oct 24 '15 at 4:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.