import arcpy, os, sys mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, df)[0] North = arcpy.GetParameterAsText(0) South = arcpy.GetParameterAsText(1) East = arcpy.GetParameterAsText(2) West = arcpy.GetParameterAsText(3) if North > 0: whereClause = ''' "North" = '{0}' AND "South" = '{1}' AND "East" = '{2}' AND "West" = '{3}' '''.format(North, South, East, West) elif South > 0: whereClause = ''' "North" = '{0}' AND "South" = '{1}' AND "East" = '{2}' AND "West" = '{3}' '''.format(North, South, East, West) elif East > 0: whereClause = ''' "North" = '{0}' AND "South" = '{1}' AND "East" = '{2}' AND "West" = '{3}' '''.format(North, South, East, West) elif West > 0: whereClause = ''' "North" = '{0}' AND "South" = '{1}' AND "East" = '{2}' AND "West" = '{3}' '''.format(North, South, East, West) else: whereClause = ''' "North" = '{0}' AND "South" = '{1}' AND "East" = '{2}' AND "West" = '{3}' '''.format(North, South, East, West)
Solved! Go to Solution.
mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] newExtent = df.extent newExtent.XMin = df.extent.XMin + deltaX newExtent.YMin = df.extent.YMin + deltaY newExtent.XMax = df.extent.XMax + deltaX newExtent.YMax = df.extent.YMax + deltaY df.panToExtent(newExtent) arcpy.RefreshActiveView()
Provides the ability to get or set the data frame's map extent using map coordinates (i.e., map units). A copy of the Extent object must be made before modifying its properties. The modified copy is then used to set the new extent properties. Note: If you try to set the extent by simply referencing the Extent object, changes won't be saved. For example, df.extent.xMin = some value won't work.from here: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000003000000
If the aspect ratio of the extent does not match the shape of the data frame, the final extent will be adjusted to fit the new extent within the shape of the data frame. In other words, if you set explicit X, Y coordinates, you may not get the same values returned if you attempt to read them later.
Note: The properties of the Extent object are by default read-only in the help system. A special exception was made for the arcpy.mapping scripting environment to enable changing extents during a map automation process.
df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = -180.0, -90.0
newExtent.XMax, newExtent.YMax = 180.0, 90.0
df.extent = newExtent
You can't modify the extent object directly. Once you figure out where you want to move it, you will need to make a copy of the extent object.
From the docs:
from here: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000003000000
Should be able to shift the Ymin Ymax by 5 feet north.
R_
df = arcpy.mapping.ListDataFrames(mxd)[0] newExtent = df.extent newExtent.XMin, newExtent.YMin = -180.0, -90.0 newExtent.XMax, newExtent.YMax = 180.0, 90.0 df.extent = newExtent
>>> df.extent.YMin 150602.61868704704 >>> df.extent.YMax 152774.79701295635 >>>
## So, after you have done whatever if statements you need to determine how far to shift it, you use the code. if MyShiftNorthTest == true: deltaY = 5 # this is my variable set to 5 "map units" that I want to shift my extent North if MyShiftEastTest == true: deltaX = 5 # this is my variable set to 5 "map units" that I want to shift my extent East ##Then (and I'll break it up to read it more easily): df = arcpy.mapping.ListDataFrames(mxd)[0] newExtent = df.extent newExtent.XMin = df.extent.XMin + deltaX newExtent.YMin = df.extent.YMin + deltaY newExtent.XMax = df.extent.XMax + deltaX newExtent.YMax = df.extent.YMax + deltaY df.extent = newExtent
mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] newExtent = df.extent newExtent.XMin = df.extent.XMin + deltaX newExtent.YMin = df.extent.YMin + deltaY newExtent.XMax = df.extent.XMax + deltaX newExtent.YMax = df.extent.YMax + deltaY df.panToExtent(newExtent) arcpy.RefreshActiveView()
I was thinking of using arcpy.mapping to control a closed mxd. for real time pan of the display, this is that language (at least for the dataframe named "Layers"):mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] newExtent = df.extent newExtent.XMin = df.extent.XMin + deltaX newExtent.YMin = df.extent.YMin + deltaY newExtent.XMax = df.extent.XMax + deltaX newExtent.YMax = df.extent.YMax + deltaY df.panToExtent(newExtent) arcpy.RefreshActiveView()
if you pass it a positive value for deltaY, it will pan the display north by the entered value (in map units), negative will shift south
if you pass it a positive value for deltaX, it will pan the display East by the entered value (in map units), negative will shift west
R_