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")
引用磁盘上的文档:
__author__ = "Brill" #引用磁盘上的文档 import arcpy.mapping as mapping mxd = mapping.MapDocument("C:/ArcpyBook/Ch2/crim_copy.mxd") print(mxd.title)
获取地图文档中的图层列表:
__author__ = "Brill" #获取地图文档中的图层列表 import arcpy.mapping as mapping mxd = mapping.MapDocument("CURRENT") layers = mapping.ListLayers(mxd) for lyr in layers: print(lyr.name)
获取地图文档中的图层的子集:
__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)
缩放所选要素:
__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
改变地图范围:
__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()
添加图层到底图文档:
__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")
你只管努力,其他的交给天意~