使用ArcPy缩放到所选特征?


Answers:



16

我有一段有效的代码。我发现这里的ESRI网站上。将其作为脚本添加到模型,然后将按属性选择工具的输出连接到该模型。它正是我想要的。

import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()

大多数处理文档(mxd)管理,显示或输出的脚本功能将使用ArcPy映射模块。help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/…–
mindless.panda

3
+1 df.zoomToSelectedFeatures()是我的方法。您可能还希望设置比例df.scale = yourscalehere
纳撒努斯2011年

10

正如您已经推测的那样,

df.zoomToSelectedFeatures()

会将数据框的范围更改为地图框中的所有选定要素。如果您只想缩放到特定图层的选择集,请使用lyr.getSelectedExtent()。我还调整了地图比例因子,因此我的代码如下所示:

df.extent = lyr.getSelectedExtent()
df.scale *= 1.5
arcpy.RefreshActiveView()

或这个:

df.extent = lyr.getSelectedExtent()
df.scale = 12000 # 1:1,000
arcpy.RefreshActiveView()

1

因此,除此之外,我一直需要在未选择任何功能的情况下跨多个层跟踪最广泛的范围。以下代码将跟踪每个方向上最远的范围。scope_object在对函数的所有调用中保持不变,应初始化为要包含的层之一。track_extent的参数“ layer”是arcpy.Mapping.Layer对象。准备好保存地图时,只需通过诸如data_frame.extent = scope_object之类的内容来设置数据框的范围

extent_object = initial_layer.getExtent()

def track_extent(extent_object,layer):

    l_properties = layer.getExtent()

    # each of these essentially says that if this layer is further out to one direction than the current setting, change the setting
    if l_properties.XMin < extent_object.XMin:
        extent_object.XMin = l_properties.XMin
    if l_properties.YMin < extent_object.YMin:
        extent_object.YMin = l_properties.YMin
    if l_properties.XMax > extent_object.XMax:
        extent_object.XMax = l_properties.XMax
    if l_properties.YMax > extent_object.YMax:
        extent_object.YMax = l_properties.YMax
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.