I remember that when I first learned the arcpy script, no one took me with me. I had to find out for a long time. I don't know how to use the arcpy script. I don't know how to read the help documentation, one day, I finally figured out how to use arcpy in idle (the python compiling environment that comes with ArcGIS installation. Here, I would like to write an entry-level tutorial for those shoes that are struggling to get started with arcpy.
Remember that when learning programming, there will always be "Hello, world ". Here we will not talk about what arcpy is, but how to use arcpy first.
After ArcGIS is installed, the corresponding Python installation package is automatically installed. First, open the python idle compiling environment (arcgis10.2 and python2.7 are used) from start to the program, for example, 1:
Figure 1 I think that I was thinking about this command window and didn't know how to use arcpy. Khan, the wooden way. It was originally a very simple thing. I also blame myself for having never learned Python before.
Enter import this in the Command window and press enter, as shown in Figure 2:
Figure 2 above is the famous Zen of Python, many of which are not described in detail on the Internet.
In fact, Figure 1 is a command window. It works in the same way as Windows Command windows. It can be understood as executing programs by statement or block. This leads to the command line window, the first method used by arcpy.
Command Line window
There are two types of command line windows: the idle command line window described above and the command line window Embedded In ArcMap.
Input: Import arcpy, and press Enter;
Input: Help (arcpy), 3
Figure 3 shows the arcpy package initialization file, package directory, and included functions. This shows that arcpy can be used normally, and the other party has the right to use it as a simple example. How to introduce Python packages and find help.
The command line window Embedded In ArcMap opens ArcMap. The command window is shown in Figure 4:
Input: Import arcpy, and press Enter;
Input: Help (arcpy), 5
When using the command line window, you will find that the command line window has a certain smart prompt function, and the result is the same as the command line window of idle.
The command line is executed by command or by program block. How can I use a script file, that is, a file suffixed with. py? This leads to the second arcpy usage: script file.
Script File
Calmly think that arcpy is the most convenient way to use a script file, and it also makes up for the disadvantages of ArcMap. We will talk about how to create a script file later.
Under the File menu of idle, click New window. You will see that the three arrows in the command line disappear, and you can input program statements in a connection.
Input:
Import arcpy
Help (arcpy)
Run module under the run menu. You will be prompted to save it. Click OK.
If the file is saved as a. py file, the running result is displayed in the command line window. Of course, the running result is the same as that in the command line window.
This is a simple way to use arcpy in Python files.
I will create the arcpy file, which will lead to another question. How can I use these files in the ArcMap tool? This involves a lot of things. Let's talk about it later, only the third method of using arcpy is introduced: arcpy tool.
Arcpy tool.
For how to create the arcpy tool, see the documentation.
Arcpy basics-1. How to Use arcpy