欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python使用arcpy.mapping模塊批量出圖

 更新時間:2017年03月06日 09:04:38   作者:樂水悠悠  
出圖是項目里常見的任務(wù),有的項目甚至?xí)习購垐D片,所以批量出土工具很有必要,這篇文章主要介紹了python使用arcpy.mapping模塊批量出圖,有興趣的可以了解一下。

出圖是項目里常見的任務(wù),有的項目甚至?xí)习購垐D片,所以批量出土工具很有必要。arcpy.mapping就是ArcGIS里的出圖模塊,能快速完成一個出圖工具。

arcpy.mapping模塊里常用的類有MapDocument、DataFrame、Layer、DataDrivenPages和TextElement。

 MapDocument類是地圖文檔(.mxd文件)對應(yīng)的類。初始化參數(shù)是一個字符串,一般是.mxd文件的路徑:

 mxd=arcpy.mapping.MapDocument(r"F:\GeoData\ChinaArea\ChinaVector.mxd")

DataFrame類用于操作地圖內(nèi)的Data Frame(即下圖的Layers),能夠控制地圖的范圍、比例尺等。用arcpy.mapping.ListDataFrames(map_document, {wildcard})函數(shù)獲取。

df= arcpy.mapping.ListDataFrames(mxd)[0]

 Layer類用于操作具體的圖層。能夠控制圖斑的樣式、可見性等??梢杂?lyr文件的路徑初始化,也可以通過arcpy.mapping.ListLayers(map_document_or_layer, {wildcard}, {data_frame})函數(shù)獲取。

lyr1=arcpy.mapping.Layer(r" F:\GeoData\ChinaArea\Province.lyr")

df.addLayer(lyr1)

lyr2=arcpy.mapping.ListLayer(mxd,"",df)[0]

DataDrivenPages類需要配合ArcMap中的Data Driven Pages工具使用。用于一個矢量文件內(nèi)的全部或部分圖斑每個出一張圖的情況。

TextElement類用于操作地圖上的文字,比如圖名、頁數(shù)。通過arcpy.mapping.ListLayoutElements (map_document, {element_type}, {wildcard})函數(shù)獲取。

txtElm=arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT")[0]

常見的出圖模式有兩種:一個矢量文件里每個圖斑出一張圖,一個文件夾下每個矢量文件出一張圖。

每個圖斑出一張圖:

這種情況有Data Driven Pages工具配合最好。打開ArcMap的Customize->Toolbars->Data Driven Pages,設(shè)置好圖層、名稱字段、排序字段、顯示范圍和比例尺,保存地圖。

# coding:utf-8

import arcpy

 

mxd=arcpy.mapping.MapDocument(r"F:\GeoData\ChinaArea\ChinaVector.mxd")

for pageNum in range(1,mxd.dataDrivenPages.pageCount):

     mxd.dataDrivenPages.currentPageID=pageNum

     mapName=mxd.dataDrivenPages.pageRow.getValue(mxd.dataDrivenPages.pageNameField.name)

     print mapName

     arcpy.mapping.ExportToPNG(mxd,r"F:\GeoData\ChinaArea\Province\\"+mapName+".png")

print 'ok'

一個文件夾下的每個矢量文件出一張圖:

# coding:utf-8

import arcpy

import os

 

def GetShpfiles(shpdir):

     shpfiles=[]

     allfiles=os.listdir(shpdir)

     for file in allfiles:

          if os.path.isfile(file):

              if file.endswith('.shp'):

                   shpfiles.append(file)

          else:

              shpfiles.extend(GetShpfiles(file))

     return shpfiles

 

allshps=GetShpfiles(r"F:\GeoData\ChinaArea\Province")

mxd=arcpy.mapping.MapDocument(r"F:\GeoData\ChinaArea\ChinaVector.mxd")

lyr=arcpy.mapping.ListLayer(mxd)[0]

for shp in allshps:

     paths=os.path.split(shp)

     print paths[1]

     lyr.replaceDataSource(paths[0],"SHAPEFILE_WORKSPACE",paths[1])

     arcpy.mapping.ExportToPNG(mxd,r"F:\GeoData\ChinaArea\Province\\"+paths[1]+".png")

print 'ok'

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論