0

I am working on a script that will run through a variety of selections within each state. The extents are fine for all states except Hawaii and Alaska where the islands trail off and cause the feature extent to be much bigger than I want it to be. What I'm trying to do is when the script is running, once it hits Alaska, it does the selections, then zooms to a custom extent.

I've tried to use code I've found in other posts without success. Anyone have insight into how to do this?

def zoomToFullExtent(map_document):
DF = map_document.activeDataFrame
DF_extent = DF.extent
for lyr in arcpy.mapping.ListLayers(map_document, data_frame=DF):
    extent = lyr.getExtent()
    DF_extent.XMin = -20022466.14
    DF_extent.XMax = -14434454.96
    DF_extent.YMin = 6025271.58
    DF_extent.YMax = 11927735.38
DF.extent = DF_extent
2
  • Just want to double check- is that exactly what your code looks like? Python requires strict indentation, try indenting everything after your function definition line--
    – GISUser9
    Commented Oct 2, 2017 at 14:30
  • The code above is something I pulled from another post. I'm looking for confirmation about how to do this and whether the code is something I would use for doing it.
    – Dave
    Commented Oct 3, 2017 at 13:31

1 Answer 1

2

Following the example from the ArcGIS help page, something similar to the code you've posted should work to change the data frame extent, not the feature extent. Data frame and feature extents are two different things.

df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = [your xmin], [your ymin]
newExtent.XMax, newExtent.YMax = [your xmax], [your ymax]
df.extent = newExtent

Just make sure your extents are in line with the coordinate system you are using.

1
  • Thanks! Looks like I didn't indent a line enough, and was using the wrong x/y values. It's working now.
    – Dave
    Commented Oct 3, 2017 at 18:46

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.