POST
|
Greetings, I'm trying to understand the help files, and I am seeing that using arcpy.Describe(object) applies to layers. What I'm trying to do is loop through a large folder of raster files outside of ArcMap and grab their extent. My first thought was to use the Describe method, but if it applies only to layer files, that means I'd have to create a layer file (temp or not) for 900+ rasters, which is not ideal. Is there any other method I could use that doesn't involve geoprocessing to grab the extent of raster data sitting in a folder outside of ArcMap using arcpy? Thanks, Colin
... View more
05-12-2014
07:41 AM
|
0
|
4
|
4203
|
POST
|
eibenm, Thanks for the help, your logic worked great. I beefed it up a little to make sure that anything within the visible extent stays visible. One caution to anybody that grabs this: it breaks for polygons or polylines whose actual extent meets the criteria, but visible extent does not. In other words, if your polygon is present just off screen to the left, and also just off screen to the top, for instance, it will still be left visible. In my case, this code suits my needs because I'm only using square rasters whose visible extent is the same as their actual extent. import arcpy
# Get reference to your dataframe
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
# Loop through layers in first dataframe
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
extent = arcpy.Describe(lyr).extent
extentArray = arcpy.Array(i for i in (extent.lowerLeft,
extent.lowerRight,
extent.upperRight,
extent.upperLeft,
extent.lowerLeft))
extentPolygon = arcpy.Polygon(extentArray, arcpy.SpatialReference(4269))
# Check if the layer can be seen at all... if not, turn it off
if (df.extent.overlaps(extentPolygon) == True or
df.extent.within(extentPolygon) == True or
df.extent.contains(extentPolygon) == True):
lyr.visible = True
else:
lyr.visible = False
del extent
del extentArray
del extentPolygon
# Refresh the View
arcpy.RefreshActiveView() Colin
... View more
05-09-2014
12:31 PM
|
0
|
0
|
417
|
POST
|
Greetings, I'm looking to turn off all of the layers NOT in the current visible extent. I figured a Python Add-In would be the easiest way to achieve this functionality. I've snooped around the arcpy classes and their methods, and I'm not seeing what I'm looking for (i.e. Layer.inVisibleExtent). Does this mean I'll have to create an add-in with .Net/ArcObjects? I've seen the powerpoint that's floating around about accessing Arc Objects with Python, but don't necessarily want to go that route. Thanks, Colin
... View more
05-09-2014
07:50 AM
|
1
|
3
|
3259
|
Title | Kudos | Posted |
---|---|---|
1 | 05-09-2014 07:50 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|