Setting maximum map extent limits

422
5
02-28-2012 06:36 PM
DamianMilne
New Contributor II
Hi, could someone please help. I have a python script to batch print several maps. It selects a feature, zooms to that feature, prints it, selects the next feature and repeats the process on and on. Here's my question... after zooming to the selected feature, if the map extent exceeds a predefined maximum limit, how do I restrict the map extent to those limits? Cheers, Damian
Tags (2)
0 Kudos
5 Replies
JeffBarrette
Esri Regular Contributor
Could you please clarify your scenario?  I'm not sure what you mean by predefined maximum extent.  Are you talking about scale thresholds?

Jeff
0 Kudos
markdenil
Occasional Contributor III
Try grabing the data frame object after the zoom to feature, and checking the dataframe.scale property.
If the scale denominator reported is larger than a limit you want to set (that is, the sale is smaller (and thus the extents are larger) than you want to see on your map), then add another step that resets the scale to the limit you have decieded upon.
0 Kudos
DamianMilne
New Contributor II
Hi, thank you for your replies, sorry for not explaining myself clearly but I am not referring to scale. Here's my senario. I don't want my latitude of my map extent to be any greater than 20 or any less than 10. If, for example, after zooming to my feature, the maximum latutude of my map extent turns out to be 20.5, I want to pull it back to 20. If the minimum latitude is say 8.5 after zooming, I want to pull it up to 10. I hope this is clear this time. I'm fairly new to python so coding examples would be really really helpful. Cheers, Damian
0 Kudos
markdenil
Occasional Contributor III
Scale is tied to extent for a given view frame page size.
If your data is in rectangular geographic coordinates, there would be a consistant, direct relationship between the two.
If the view is in some projected system, it becomes more complex.
Of these, an equidistant projection (with parallels of latitude at equal intervals) would be simplest.
You can access the YMIin and YMax properties of the extent object property of the data frame object to calculate the height of the visable window, and convert it to degrees to see if it falls in range of distances you want.

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "MAIN_MAP")[0]
yMin = df.extent.YMin
yMax = df.extent.YMax

##    test to see if that distance is within your range
##    calculate the modified extents you want here
##    based on the proportions of your data frame
##    make a copy of the extent object and assign the new values

if changeIt == True:    ## That is, you want to change the extents
    newExtent = df.extent
    newExtent.XMin = newXmin
    newExtent.YMin = newYmin
    newExtent.XMax = newXmax
    newExtent.YMax = newYmax
##   assign the modified object to the data frame extents object
    df.extent = newExtent


In theory, this should work...
Assigning a new scale is simpler, if you can get away with it.
0 Kudos
DamianMilne
New Contributor II
Ah, thanks Mark. Based on your example, I came up with the following code which seems to work (more or less). Any further improvements gladly accepted.

# check mapeextent
  newExtent = df.extent
  maxY = df.extent.YMax
  minY = df.extent.YMin
  maxX = df.extent.XMax
  minX = df.extent.XMin

  if maxY > 20:
   newExtent.XMin, newExtent.YMin = minX, minY
   newExtent.XMax, newExtent.YMax = maxX, 20
   df.extent = newExtent

  if minY < 10:
   newExtent.XMin, newExtent.YMin = minX, 10
   newExtent.XMax, newExtent.YMax = maxX, maxY
   df.extent = newExtent


Cheers, Damian
0 Kudos