Using Python to make an ArcGIS plugin (1) Tool introduction

Source: Internet
Author: User
Tags python script

Using Python to make an ArcGIS plugin (1) Tool introduction

by Li Yuanxiang

ArcGIS supports plug-in authoring in AddIn (also known as an add-in in ArcGIS software) starting from 10.0. Compared to the previous 9.x series, AddIn is easier and faster to use or write. With the development language, you can create plugins for each software module in ArcGIS Desktop.

AddIn supports a variety of development languages, such as. NET, Java, and Python. Where. NET and Java need to work with the ArcGIS SDK for development using Arcobjects. The advantage is that arcobjects can control the various operations of ArcGIS desktop very finely, and the difficulty is that arcobjects is very large and the learning cost is very high, which is generally only suitable for developers who have many years of programming experience and are familiar with ArcGIS. The Python language is developed for AddIn and is very suitable for people who do not have the programming ability, but often use ArcGIS tools. Why do you say that? Because the Python language is very concise and unique, because it is suitable for people who have not learned the programming language to get started (without any programming language fetters is sometimes a good thing), and ArcGIS has built in arcpy, a development package that uses Python for ArcGIS calls, You can easily invoke all of the Toolbox tools in ArcGIS Desktop and extend it nicely in Python language, so you can say that using Python for addin development, the threshold is pretty low and fast. But the shortcomings are also obvious, that is, arcpy positioning is a tool-level operation, the granularity relative to Arcobjects is very large, do not apply to do complex interactive operations, if some logic is strong, and map interaction is not much work, you can use Python to create plug-ins to complete.

The so-called 工欲善其事 its prerequisite. So what tools do you need to use Python for ArcGIS addin? ESRI provides the Python Add-in wizard tool to implement the AddIn interface and can download the tool Python Add-in Wizard on the ESRI website. From the introduction, the minimum required ArcGIS version for this designer is 10.1, as shown in

The tool is very simple and very small, less than 7M of space, mainly used to design the interface of the plug-in, and the interface of each interface is retained, the specific implementation of the developer can choose their favorite Python editor to achieve program writing. Download down is a ZIP package, unzip can see its file structure, directly to its Bin folder, find the only one can run the program Addin_assistant.exe, as shown in

Double-click to run the tool, enter its involved interface, will prompt to select a project folder, if it is to create a new project, it is recommended to select a new folder, if you want to open an existing project, then select the project so-called folder can, as shown, use a new folder to save the project.

After clicking the "OK" button, you can enter and input some information about the plugin, such as the name of the plugin, the version, the company, the description, the author and the plugin's icon, etc., which will be written to the plugin's configuration file.

This information will be displayed when the plugin is installed. The next step is to create the content of the plugin, such as buttons, panels, toolbars, menus, and so on, which can be set in the Add-in Contents panel. As shown

For example, in this example, our goal is to create a tool for batch cropping, where the work of the tool is already described in the description, and then created in the form of a toolbar, made directly into a tool, you can choose to use toolbar. Right-click Toolbar, create a new toolbar, and enter some instructions for the toolbar, such as caption. But the ID aspect recommends that these be entered in English, because eventually this part of the configuration will reserve some interface for the event interface.

In the new toolbar right click, you can create some new interface elements, such as buttons, menus, tools, panels, drop-down menus, etc.

Also create each interface element, the ID is recommended to use English, because the Python language itself on the code has a relatively strict restrictions. In order to meet some of the column requirements for batch cropping, we can define some of the interfaces appropriately, as shown in

Once the design is complete, we can click on the "Save" button to save the project. At this point, the Python Add-in wizard tool can take a break, and it's hard to write code. Next open the project folder to see the structure of the project.

These files and directories have their respective functions.

Images Table of Contents: A variety of images that store interface elements

Install directory: Used to save the plug-in source code, which usually generates a "mytools_addin.py" file, if the interface redesign, there will be a series of files, named after the file name by adding 123 of these numeric numbers. Some of the initialization code is written in the file, as you can see from the file, that some of the configuration and events of these interface elements have been created, and that the subsequent work only needs to supplement the implementation code for that file.

Config: Log the various configuration information of this plugin, such as text description, associated picture, interface element type, etc.

Because some Chinese input is used in the designer, there are some encoded conversions in the configuration file, such as

makeaddin.py: Plugin-generated run script, run this script will compile the plug-in, and in the project directory to build the final can install plug-ins. Since the file is also a Python script, it is written in plaintext, it can also be opened in text view, but do not modify its code, because we also need to run it in the Python environment.

Double-click the file and run it using Python.exe (the Python environment is automatically installed when ArcGIS is installed, which does not need to be installed yourself)

At the end of the run, you can generate a final file with the suffix Esriaddin, which is an ArcGIS plug-in installation package with the same name as the project's folder, such as

README.txt: Record some information of the project, generally can be ignored.

Next, you can double-click the plug-in to install, directly double-click, you can see the previous creation of the project when the input plug-in description information, such as

Click "Instrall add-in" to install, after the installation is complete, you can right click on the ArcMap menu blank, the tool will be recalled to use

To manage these plugins, you can delete them in the ArcMap menu custom-add-ons manager

Since the tool does not have a specific code implementation, clicking on any of the buttons does not respond. In a later chapter, we'll show you how to implement these features.

Using Python to make an ArcGIS plugin (1) Tool introduction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.