- Programming ArcGIS with Python Cookbook(Second Edition)
- Eric Pimpler
- 338字
- 2021-07-16 13:32:21
Referencing map documents on a disk
In addition to being able to reference the currently active map document file in ArcMap, you can also access map document files that are stored on a local or remote drive by using the MapDocument()
constructor. In this recipe, you'll learn how to access these map documents.
Getting ready
As I mentioned earlier, you can also reference a map document file that resides somewhere on your computer or a shared server. This is done simply by providing a path to the file. This is a more versatile way of obtaining a reference to a map document because it can be run outside the ArcGIS Python window. Later, when we will discuss parameters in a script, you'll understand that you can make this path a parameter so that the script is even more versatile, with the ability to input a new path each time it is needed.
How to do it…
Follow these steps to learn how to access a map document stored on a local or remote drive:
- Open the IDLE development environment from Start | All Programs | ArcGIS | Python 2.7 | IDLE.
- Create a new IDLE script window by navigating to File | New Window from the IDLE shell window.
- Import
arcpy.mapping
:import arcpy.mapping as mapping
- Reference the copy of the
crime
map document that you created in the last recipe:mxd = mapping.MapDocument("c:/ArcpyBook/Ch2/crime_copy.mxd")
- Print the title of the map document:
print(mxd.title)
- Run the script, and you will see the following output:
Crime Project
- You can check your work by examining the
c:\ArcpyBook\code\Ch2\ReferenceMapDocumentOnDisk.py
solution file.
How it works…
The only difference between this recipe and the last one is that we provided a reference to a map document file on a local or remote drive rather than using the CURRENT
keyword. This is the recommended way of referencing a map document file unless you know for sure that your geoprocessing script will be run inside ArcGIS, either in the Python window or as a custom script tool.
- Learning LibGDX Game Development(Second Edition)
- DBA攻堅指南:左手Oracle,右手MySQL
- Node.js Design Patterns
- C程序設計簡明教程(第二版)
- JavaScript高效圖形編程
- Learn Type:Driven Development
- 軟件項目管理(第2版)
- 區塊鏈架構與實現:Cosmos詳解
- C語言程序設計教程(第2版)
- Scientific Computing with Scala
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- App Inventor少兒趣味編程動手做
- C語言程序設計與應用實驗指導書(第2版)
- Koa與Node.js開發實戰
- 跟小樓老師學用Axure RP 9:玩轉產品原型設計