Zoom Dependent on If Point is Within Frame

604
5
05-16-2012 06:54 AM
JoelMadero
New Contributor
Hi All,

At the last stages of this script I'm writing and this is just one of those "would be nice to have" options.

Situation is that I have two polygons that "usually" contain a point when you zoom to them. In some cases if you zoom to the two polygons the point is outside of the frame (ie. off the map) and I need to zoom out a bit to show the two polygons and the point. I'm looking for some kind of check to say "if polygon is not on map, zoom out to the best zoom to include both polygons and point, else, zoom to two polygons"

Is this possible without getting too tricky? If it's not, really not a big deal but there are maybe 5 maps out of 250+ that will have to be reprinted if I can't include this check. Thanks in advance
Tags (2)
0 Kudos
5 Replies
MathewCoyle
Frequent Contributor
Easiest way is to select all features you want within your map extent and zoom to selected.
0 Kudos
JoelMadero
New Contributor
Easiest way is to select all features you want within your map extent and zoom to selected.


the point is a different layer though, how do I select from multiple layers?

Edit: Oh you mean an actual selection. I really am trying to avoid selecting as it's so much slower than what I'm doing now (definition query, zoom to layer). Not sure why the speed difference but it's at least 50% faster avoiding selection and with 250+ maps being printed from a mid speed computer, 50% is a lot of time saved
0 Kudos
MathewCoyle
Frequent Contributor
If you want performance it would be fastest I would imagine to check the XY extent of your dataframe against the XY position of your point to see if it is greater than your max X and Y extents, or lesser than your min X and Y extents.
0 Kudos
JoelMadero
New Contributor
If you want performance it would be fastest I would imagine to check the XY extent of your dataframe against the XY position of your point to see if it is greater than your max X and Y extents, or lesser than your min X and Y extents.


This sounds promising. Any way that you can link me to an example or provide one for me (appreciate the help by the way).

My layers are:

Consolidations (Field is Precinct)
Polls (field is PollID)
0 Kudos
BenjaminGale
New Contributor III
One way you could check this is to see if the dataframe's extent contains the point layer's extent.

import arcpy

mxd = arcpy.mapping.MapDocument("C:\GIS\dfTest\Map1.mxd")
mxd.activeView = "PAGE_LAYOUT"

df = arcpy.mapping.ListDataFrames(mxd)[0] 
lyr = arcpy.mapping.Layer('point') 

#Test if df extent contains the extent for the layer symbology
df.extent.contains(lyr.getExtent("True"))
0 Kudos