- Programming ArcGIS 10.1 with Python Cookbook
- Eric Pimpler
- 606字
- 2021-07-30 17:29:54
Accessing ArcPy with Python
Before you can take advantage of all the geoprocessing functionality provided by ArcPy, you must first import the package into your script. This will always be the first line of code in every geoprocessing script that you write.
Getting ready
ArcPy is a Python site package that is part of the ArcGIS 10 release, and fully encompasses the functionality provided with the arcgis scripting
module at ArcGIS 9.2, which further enhances its capabilities. With ArcPy you have access to the geoprocessing tools, extensions, functions, and classes for working with ESRI GIS data. ArcPy provides code-completion and integrated documentation for the modules, classes, and functions. ArcPy can also be integrated with other Python modules to widen the scope of its capabilities. All ArcGIS geoprocessing scripts that you write with Python must first provide a reference to ArcPy.
How to do it…
Follow these steps to import the arcpy
site package into the ArcGIS Python window:
- Open the
c:\ArcpyBook\Ch2\Crime_Ch2.mxd
file with ArcMap. - Click on the Python window button to display a shell window where you can write the Python code.
- In the Python window, import the
arcpy
package and press the Enter key on your keyboard. After each statement that you enter in the Python window, you will press the Enter key. You will include this line of code in every single script that you write, so get used to it! Thisimport
statement is what gives you access to all the functionality provided by ArcPy.Note
Technically, you don't have to include the
import arcpy
statement when working inside the ArcMap Python window. It's inherent to this window. However, it is required when creating standalone scripts in IDLE, PythonWin, or any other integrated development environment. It's also a good habit to get into as many of your scripts will ultimately be run as standalone scripts. - ArcPy also provides code-completion functionality that makes your life as a programmer much easier. On the second line, begin by typing
arcpy
and then a dot. ArcPy is an object-oriented package, which means that you access the properties and methods of an object using the dot notation. Notice that a drop-down list of available items is provided. These are the tools, functions, classes, and extensions that are available on this particular object. All objects have their own associated items, so the list of items presented will differ depending on the object that you have currently selected: - This is an auto-filtering list, so as you begin typing the name of the tool, function, class, or extension, the list will be filtered by what you have typed:
- You can choose to have the Python window auto-complete the text for you by selecting an item from the list using your mouse or by using the arrow keys to highlight your choice, and then using the Tab key to enter the command. This auto-completion feature makes you a faster, more efficient programmer. Not only is it easy to use, but it also dramatically cuts down the number of typos in your code.
How it works…
Once the ArcPy module has been imported, you get access to the geoprocessing tools, extensions, functions, and classes for working with ESRI GIS data. One of the most important aspects of ArcPy is that it provides access to all of the geoprocessing tools available, based on the license level of ArcGIS Desktop currently in use. The tools available to your script will vary depending upon whether you are using the ArcGIS Basic, Standard, or Advanced license level, with the Basic level providing the fewest tools and the Advanced level providing a complete set of tools.
- Building a RESTful Web Service with Spring
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- FreeSWITCH 1.6 Cookbook
- Java EE 8 Application Development
- Kubernetes源碼剖析
- 從零開始:UI圖標設計與制作(第3版)
- Orleans:構建高性能分布式Actor服務
- UX Design for Mobile
- Test-Driven iOS Development with Swift
- VMware vSphere Design Essentials
- Python程序設計現代方法
- C#從入門到精通(微視頻精編版)
- Daniel Arbuckle's Mastering Python
- Java Web開發任務教程
- R統計應用開發實戰