I have a layer called addLayer0 which is largely filled with nodata values.

addLayer0. In black the no data values, orange/red/yellow the actual values

    for l in list_dfs:

where list_dfs is a list of all dataframes in the document.

I want all dataframes to show the extent of the layer called addLayer0.

However as the Layer is largely made up of nodata values, the layer extent is much larger than the relevant area which has values >0, so it zooms to the extent shown in the image instead of the colored area.

How can I zoom to the extent of the colored area only? EDIT: The extent needs to be determined automatically as the script runs over many different files with different extents.


2 Answers 2


I’m sure there are more elegant ways, but if you vectorize your raster as a polygon, you could get an extent object for the minimum bounding rectangle around your valid raster values from that. If your input raster values are float, you’ll need to convert to integer before vectorizing.


If you get the bounding coordinates of your area with data, based on the DataFrame extent property you could do something like this:

mxd = mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)
for dataframe in df:
    newExtent = dataframe.extent
    #coordinates of your data
    newExtent.XMin, newExtent.YMin = 30.401, -12.057 
    newExtent.XMax, newExtent.YMax = 31.786,  -10.428
    dataframe.extent = newExtent

You can figure out the coordinates manually - read them off the status bar. But
I think its probably possible to get the extents of the area with data using arcpy.

  • Thanks for the tip, but I need an automatic way to do this. I will edit in the original post
    – uetli
    Commented Feb 9, 2018 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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