出图是项目里常见的任务,有的项目甚至会要上百张图片,所以批量出土工具很有必要。arcpy.mapping就是ArcGIS里的出图模块,能快速完成一个出图工具。
arcpy.mapping模块里常用的类有MapDocument、DataFrame、Layer、DataDrivenPages和TextElement。
MapDocument类是地图文档(.mxd文件)对应的类。初始化参数是一个字符串,一般是.mxd文件的路径:
mxd=arcpy.mapping.MapDocument(r"F:\GeoData\ChinaArea\ChinaVector.mxd")
DataFrame类用于操作地图内的Data Frame(即下图的Layers),能够控制地图的范围、比例尺等。用arcpy.mapping.ListDataFrames(map_document, {wildcard})函数获取。
df= arcpy.mapping.ListDataFrames(mxd)[0]
Layer类用于操作具体的图层。能够控制图斑的样式、可见性等。可以用.lyr文件的路径初始化,也可以通过arcpy.mapping.ListLayers(map_document_or_layer, {wildcard}, {data_frame})函数获取。
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工具使用。用于一个矢量文件内的全部或部分图斑每个出一张图的情况。
TextElement类用于操作地图上的文字,比如图名、页数。通过arcpy.mapping.ListLayoutElements (map_document, {element_type}, {wildcard})函数获取。
txtElm=arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT")[0]
常见的出图模式有两种:一个矢量文件里每个图斑出一张图,一个文件夹下每个矢量文件出一张图。
每个图斑出一张图:
这种情况有Data Driven Pages工具配合最好。打开ArcMap的Customize->Toolbars->Data Driven Pages,设置好图层、名称字段、排序字段、显示范围和比例尺,保存地图。
# 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'
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHP中文网。
更多python使用arcpy.mapping模块批量出图方法相关文章请关注PHP中文网!

PythonArraysSupportVariousoperations:1)SlicingExtractsSubsets、2)Appending/ExtendingAdddesements、3)inSertingSelementSatspecificpositions、4)remvingingDeletesements、5)sorting/verversingsorder、and6)listenionsionsionsionsionscreatenewlistsebasedexistin

numpyarraysAressertialentionsionceivationsefirication-efficientnumericalcomputations andDatamanipulation.theyarecrucialindatascience、mashineelearning、物理学、エンジニアリング、および促進可能性への適用性、scaledatiencyを効率的に、forexample、infinancialanalyyy

UseanArray.ArrayOverAlistinPythonは、Performance-criticalCode.1)homogeneousdata:araysavememorywithpedelements.2)Performance-criticalcode:Araysofterbetterbetterfornumerumerumericaleperations.3)interf

いいえ、notallistoperationSaresuptedbyarrays、andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorintorintorinsertizizing、whosimpactsporformance.2)リスト

toaccesselementsinapythonlist、useindexing、negativeindexing、slicing、oriteration.1)indexingstartsat0.2)negativeindexingAcsesess.3)slicingextractStions.4)reterationSuseSuseSuseSuseSeSeS forLoopseCheckLentlentlentlentlentlentlenttodExeror。

Arraysinpython、特にvianumpy、arecrucialinscientificComputing fortheirefficienty andversitility.1)彼らは、fornumericaloperations、data analysis、andmachinelearning.2)numpy'simplementation incensuresfasteroperationsthanpasteroperations.3)arayableminablecickick

Pyenv、Venv、およびAnacondaを使用して、さまざまなPythonバージョンを管理できます。 1)Pyenvを使用して、複数のPythonバージョンを管理します。Pyenvをインストールし、グローバルバージョンとローカルバージョンを設定します。 2)VENVを使用して仮想環境を作成して、プロジェクトの依存関係を分離します。 3)Anacondaを使用して、データサイエンスプロジェクトでPythonバージョンを管理します。 4)システムレベルのタスク用にシステムPythonを保持します。これらのツールと戦略を通じて、Pythonのさまざまなバージョンを効果的に管理して、プロジェクトのスムーズな実行を確保できます。

numpyarrayshaveveraladvantages-averstandardpythonarrays:1)thealmuchfasterduetocベースのインプレンテーション、2)アレモレメモリ効率、特にlargedatasets、および3)それらは、拡散化された、構造化された形成術科療法、


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

ホットトピック









