Date8

Arcpy:

引用当前的地图文档:

__author__ = "Brill"
#引用当前的地图文档
import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
mxd.title = "Crime Project"
mxd.saveAcopy("C:/ArcpyBook/Ch2/crim_copy.mxd")
View Code

引用磁盘上的文档:

__author__ = "Brill"
#引用磁盘上的文档
import arcpy.mapping as mapping
mxd = mapping.MapDocument("C:/ArcpyBook/Ch2/crim_copy.mxd")
print(mxd.title)
View Code

获取地图文档中的图层列表:

__author__ = "Brill"
#获取地图文档中的图层列表
import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
layers = mapping.ListLayers(mxd)
for lyr in layers:
    print(lyr.name)
View Code

获取地图文档中的图层的子集:

__author__ = "Brill"
#获取地图文档中的图层的子集
import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
for df in mapping.ListDataFrames(mxd):
    if df.name == "Crime":
        layers = mapping.ListLayers(mxd,'Burg*',df )
        for layers in layers:
            print(layers.name)
View Code

缩放所选要素:

__author__ = "Brill"
#缩放所选要素
import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd,"Crime")[0]
layer = mapping.ListLayers(mxd,"Burglaries*",df)[0]
df.extent = layer.getSelectedExtent
View Code

改变地图范围:

__author__ = "Brill"
#改变地图范围
import arcpy.mapping as mapping
mxd  =  mapping.MapDocument("CURRENT")
for df in mapping.ListDataFrames(mxd):
    if df.name == 'Crime':
        layers = mapping.ListLayers(mxd,'Crime Density by School District',df)
        for layer in layers:
            query = '"NAME" = \'Lackland ISD\''
            layer.definitionQuery  = query
            df.extent = layer.getExtent()
View Code

添加图层到底图文档:

__author__ = "Brill"
#添加图层到底图文档
import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
df  = mapping.ListDataFrames(mxd)[0]
layer = mapping.Layer(r"C:\ArcpyBook\data\School_Districts.lyr")
mapping.AddLayer(df,layer,"AUTO_ARRANGE")
View Code

 

posted @ 2018-05-18 10:26  iDataSharing  阅读(164)  评论(0编辑  收藏  举报