赞
踩
现有张一张二张三等100余户宗地shp文件,需要以谷歌影像为底图绘制各户宗地范围图
包含各户shp的gdb文件
出图模板
设置成果图的标题元素名称为mapname
- import arcpy
- mxd = arcpy.mapping.MapDocument(r'C:/Users/Administrator/Documents/ArcGIS/model.mxd')
- df = arcpy.mapping.ListDataFrames(mxd, "图层")[0]
- Layers=arcpy.mapping.ListLayers(mxd, "", df)
- # 读取gdb中的shp
- arcpy.env.workspace = r"C:/Users/Administrator/Documents/ArcGIS/各户shp.gdb"
- datasets = arcpy.ListFeatureClasses('*','Polygon')
- all_shps=datasets
- # 替换数据源,生成新的mdx
- for r in datasets:
- for layer in Layers:
- if layer.name ==u'宗地边界':
- layer.replaceDataSource(r"C:/Users/Administrator/Documents/ArcGIS/各户shp.gdb","FILEGDB_WORKSPACE",r)
- # zoomToLayers
- arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION")
- df.zoomToSelectedFeatures()
- arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
- # 修改图标题
- for elm in arcpy.mapping.ListLayoutElements(
- mxd, 'TEXT_ELEMENT'):
- if elm.name=="mapname":
- elm.text=r+u'宗地示意图'
- mxd.saveACopy(r'C:/Users/Administrator/Documents/ArcGIS/'+r+'.mxd')
- # exportTojpg
- arcpy.mapping.ExportToJPEG(mxd,
- resolution=600,
- out_jpeg=r"C:/Users/Administrator/Documents/ArcGIS/"+r+".jpg")
- # 从内存中释放
- del mxd
1. 作为模板的model.mxd文件名必须是英文,否则python2.x版本没法读取中文会报错如下
2. 涉及到中文的地方最好都加上u,比如u'宗地示意图'。
3. 本方法适用于图例名字不改变的图
全部文件在我的仓库中
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。