Introduction to AO

Source: Internet
Author: User
Tags imap map class
Arcobject description

Chapter 1 Understanding ArcObjects
Welcome to the world of AO (abbreviated as ArcObjects! This section introduces you to the world of AO and answers some related questions, such as: What is AO, why does AO make development more powerful, and how to learn and obtain relevant resource information.
What is 1.1ao?
Is ao esri ArcGIS? Family application ArcMap ?, Arccatalog? And arcscene? Development Platform, which is based on Microsoft? A series of COM component sets built by COM technology. It should be clarified that up to now, AO is not an independent application product, and it is a software development kit attached to your ArcGIS desktop product. That is to say, you have purchased any product of ArcGIS Desktop, either ArcView or ArcInfo, and you have a powerful AO component set that uses the components provided by AO for application development.

1.2ao Functions
With AO, you can complete the following or more GIS functions:
? Display, query, search, edit, and analyze spatial data;
? Create various topic charts and statistical reports;
? Advanced drawing and output functions;
? Space Data management and maintenance;
..............................
And so on. In fact, the three applications ArcMAP, arccatalog, and arcscene are all built by AO. Therefore, theoretically, these tasks can be completed by applications, it can also be done through AO (but re-constructing an ArcMap-type application doesn't take the cost into consideration first, so reliability and stability are doubtful, in the future, I will talk about this issue ). What we need to do most of the time now is to use the AO components provided by ESRI for building blocks. AO has provided many basic underlying functions, and your task is to assemble these underlying functions into a more powerful COM object according to application requirements. We now know that a o is built based on Microsoft's COM technology, so it is open and scalable. The openness here refers to the selection of development environments with a variety of development tools supporting com standards, such as VBA, VB, v c ++, and dephi, scalability refers to the functionality not provided by AO components. to define a new data format, you can use COM technology to write your own COM components, extends and supplements the AO component library. In ESRI's document, I have seen that there is no limit to using the AO development function. It depends on your imagination. Oh, don't be confused. AO is indeed very powerful. Just look at the functions shown by ArcMap. Because of the use of COM technology, you can not only construct your own COM components on the basis of AO, but also complete a COM component to supplement AO. As for why AO is based on the COM technology, I personally think that the current and future GIS development will be more and more closely integrated with mainstream IT technologies. After all, any software product will eventually be used, therefore, in addition to providing professional GIS functions, it is extremely important in terms of ease of use and scalability, and the COM technology provides a solution. Isn't it a little wordy? The reason for emphasizing its importance is that we need you to take an injection of doping before starting our AO development, although powerful and easy-to-use applications have never been easily dragged by several lines of code and controls, you also need to constantly learn and grasp more new things, but this investment is worthwhile for a developer, as well as for those who try to use AO for development. Are we not starting?

1.3 technical basis required
How to Develop AO software? For senior AO programmers, I think there must be four major technical barriers:
1. Object-oriented technical ideas;
2. COM technology;
3. Organization and relationship of each component object of AO;
4. Support for various COM development tools and their environments (such as VB, Vc, and dephi)
What actually belongs to ESRI is nothing more than this Ao component library. For those who first entered the AO development field, I personally think (there are other tasks that can be put aside for the moment on com, but it is still no problem to finish a lot of tasks as you look at them) you can start with the application of ArcGIS Desktop and have an understanding of AO layers and related concepts (such as map, layer, view, label, and supported data formats ), otherwise, when you see the AO example, it may suddenly be in the fog. The hatchback confirms that I think it is most likely to be suddenly connected.
1.4ao Development Kit
You can install the AO Development Kit either by installing ArcGIS desktop or by using the setup.exe file under the \ ArcGIS \ ArcObjects developer kit directory on the installation CD. The following is the directory structure after the AO Development Kit is installed:
ArcObjects developer Kit
Help --- contains development help files: aodev. CHM, ArcObjects. CHM, etc.
Kits --- the source code of additional developer materials such as projection engine header files, category ID files, and ESRI sample commands (in the latest version 8.2, this code location has changed)
Object Model diagrams --- including all object model diagrams in PDF Format
Samples --- contains the source code of all sample project files
Utilities --- tools including ESRI object browsers

1.5ao development resources
1. ArcObjects developer help ----- This is the preferred resource for Ao development. I personally think it can be comparable to Microsoft's msdn to a certain extent. Both basic COM and AO object hierarchies of AO are described. In addition, a large number of development examples are provided.
2. ArcObjects online ----- provides the latest AO Component Library documentation. One of the technical forums on AO is believed to have many unexpected gains;
3. indexing ArcObjects ----- A Very Good AO technical document, which is well organized for Ao development and has a large number of examples that can be copied and used at any time;
4. building a Geodatabase ----- the application is centered on data. This book is mainly used to design and create Geodatabase. However, it understands and master the layers and methods of geodatabas E, it is a good supplement to AO development.
5. microsoft msdn-even if your AO development tool is not Microsoft, you are advised to install a complete set of msdn. msd n is a treasure if you want to learn more and use Com for design and development.

Chapter 2 basics of AO ----- com
The idea of componentized program design is widely used today. So what about com? In this section, I will introduce related concepts such as class, object, interface, and COM.
2.1 class and object (class and object)
To introduce COM, we can't help but mention Object-oriented thinking. So let's take a look at what objects are? In daily life, you and I are all objects, including names, height, weight, and other external characteristics, as well as their respective work skills. They also need to communicate with each other in a language, the concept of objects also exists in development applications and GIS.
You have used a widget on the form, which has a series of external representations called properties, including the size, position, color, and name, there will also be a communication action such as click, which is called an event (events. In the world of AO, everything is an object, such as the objects we can see as map, form, layer, and cursor when the query result set is generated in the table) -This class of invisible objects. How is an object generated? Oh, it is produced by class instantiation. Many AO classes are very familiar to us (such as point, line, polygon, lay er, table, if you are not familiar with GIS ). If you don't need to talk too much nonsense, you should first enter ao to show what classes and objects are.
Map class
Properties Methods
Mapscale (1:3, 800,000) addlayer (+)
Mapunits (6234233.32, 5234234.56) clearselection
(Unfortunately, I cannot use graphs to express the above concepts. I suddenly feel a little funny-I am writing a GIS topic ).
If you have used the ArcMap application and are still impressed, you will find that this mapscale is actually the content of the text box in the application, the add layer method seems to be the one used to increase the "+" behavior of the layer.
What is 2.2com?
(There are too many things about com. The following content is a good understanding of Ao's initial developers, so you don't have to go into it now ).
At last, com started. It was a very heavy and interesting thing. I think many developers of AO may have different feelings about it. Com is Microsoft's c omponent object model abbreviation. It not only defines the standard for interaction between component programs, it also provides the environment required for component program running (COM itself needs to implement an API called C om Library (COM Library), which provides components such as the customer's query, as well as a series of services such as component registration/anti-registration. Generally, the com library is implemented by the operating system, so we don't have to worry about its implementation details, as we often see ActiveX, DirectX, oledb is based on the COM technology), mainly used on Microsoft Windows operating system platform. Com is usually published in the format of Win32 dynamic link library (DLL) or executable file (exe.

2.3com goals and features
Reusability at the binary code level (through inclusion and aggregation );
Language independence, as long as it can generate com compliant standards;
Process transparency for client programs using COM objects;

2.4 objects, classes, and interfaces
Objects are one of the basic elements of COM. Unlike objects in C ++, they are encapsulated in a true sense) in addition, the reusability of COM objects is manifested in the inclusion and aggregation of COM objects. One object can fully use all the functions of another object, the reusability of C ++ objects is manifested in the inheritance of C ++ classes.
An interface is an interface of a component object. It contains the data structure of a group of functions. Through this data structure, the customer code can call the functions of the component object, component Objects are accessed through interfaces. The interface design must meet the following requirements:
1. It must be inherited directly or indirectly from the iunknown interface (this interface is missing in AO );
2. The interface must have a unique identifier. The interface is immutable. Once an IID is assigned and published, no factors in the interface definition can be changed.
Developing with COM means using interfaces, which can also be called interface-based design models. All communication between objects is performed through their interfaces. The COM interface is abstract, meaning that the related interfaces are not implemented, and the Code related to the interfaces comes from a class implementation. How to implement interfaces is different for different objects. Therefore, an object only inherits the class type of the interface, rather than its implementation. This is called type inheritance. Functions are abstracted and implemented using classes. In COM, classes and interfaces are generally treated as "what to do" and "how to do". Interfaces define what an object can do and Classes define how to do it.
The com class provides Code related to one or more interfaces, so functional entities are encapsulated in the class. Several Classes can have the same interface, but their implementations may be very different. By implementing these interfaces, com implements object-oriented polymorphism. com does not support multiple inheritance concepts. However, this is not a drawback because a class can implement multiple interfaces.

Other components of 2.5com
The interface of the COM object can be a dual interface. The dual interface is different from the general interface (custom Interface) because the dual interface is inherited from the basic interface idispatch of automation, the normal interface is inherited directly from the iunknow n interface. The default Interface Model is the double interface model and the double interface model.
2. Inbound interface (outbound Interface)
Com call can be unidirectional (that is, the client program creates a component object, and then the client program calls the functions provided by the object and releases the object as appropriate), which is usually called an inbound interface. If a COM Object supports one or more interfaces that actively communicate with the customer program, this interface is called an outbound interface because these interfaces are not implemented by the object but implemented by the customer program. Type Library)
A type library is used as the binary version of an Interface Definition Language (IDL) file. It is a collection of COM objects and interfaces, it is compiled into a binary file, such as olb, d LL, or OCX. To support a component set that does not depend on the development language tool, all data related to the ArcObjects library is packaged into esricore. the olb Type Library includes a binary description of all coclasses, interfaces, methods, and server types.
Microsoft provides multiple com interfaces for the Type Library. The two interfaces are itypeinfo and itypelib. Using the standard COM interface, different development tools and compilers can obtain the coclasses supported by a specific library and interface-related information.
4. Bidirectional com support means that a COM object can be used in either a language or a COM object;
5. In-process COM, local com, and Remote COM
Com is a client/server system. The server (or object) provides functions and the client program uses these functions. If the com program and the client program are in the same process address space, they are called in-process COM, which is usually implemented in the form of DLL, and the local com refers to the EXE in different processes on the same computer, remote COM refers to the DLL or EXE in different computers. Are you impatient or looking back at this chapter and have doubts? After talking about so many com and COM, what is this DLL when I use ao to write a DLL in dephi or vB? Well, let me use the concept of C/S for an explanation. If you write your own application framework, your application is the client, and the called DLL is actually the server. If You Are In ArcMap, then the AR cmap application actually acts as a client to send a request, which is passed to the COM server through the com mechanism-the DLL you wrote to complete the corresponding functions, the external and internal services of this server are completed by esri ao interfaces and classes.

Chapter 3 Use of AO objects
In chapter 2, we talked about many com concepts, such as classes, objects, interfaces, methods, etc, so how does an actual AO development reflect these com concepts? Since AO is based on COM. In this section, I will use the VB code to describe how to use the AO object and introduce how to read the OMD (Object Model digoal.
3.1ao object usage
Let's start this journey directly with AO-related code, if you think so. :)
Dim pmap as IMAP
Set pmap = new map
Pmap. Name = "Map Name:-Tour"
.........................
.........................
Pmap. clearlayers
Pmap. Clear // Error
How to run this code is the content of the next chapter. First, let's take a look at why the code is written like this. There are many mysteries in it.
Dim pmap as IMAP
We know that access to objects in COM is implemented through interfaces. Therefore, you cannot directly call properties or execute methods using their names, just like many visual controls. This statement defines an interface variable, fortunately, VB has demonstrated all this ). This interface variable does not work, because the interface is defined on the object, so the next step should be to generate an object, and the object comes from it --- class.
So we have the code set pmap = new map.
In this sentence, the map object is not simply an instance, and the pmap interface variable in the above sentence is used as the default Interface of the object. OK. Now we can use this interface to modify the map name, or call the clearlayer method to delete all layers in the map. Let's take a look at the execution of the last sentence-errors may occur. The reason is very simple. Methods or attributes in different interfaces can only be accessed through their interfaces, the clear method is owned by another interface I activeview of the map class. You can use the query interface to 'failed' to iactiveview. The Code is as follows:
Dim mview as iactiveview
Set mview = pmap
Mview. Clear

3.2omd
OMD (Object Model diagram) is based on the representation of OMT (Object Modeling Technique). Let's take a look at what OMD can do for us?
1. What interfaces does this class support;
2. What objects are required to complete the task;
3. How to Use objects of this class;
4. Can classes be directly instantiated;
5. Methods and attributes of interfaces;
6. Whether other classes support this interface;
7. Relationship between objects

3.3omd symbol explanation
There are three classes in OMD: abstract class, coclass, and general class ). The main purpose of an abstract class is to define a public interface for its subclass. An abstract class will delay some or all of its implementations to the subclass. Therefore, an abstract class cannot be instantiated. A component class object can be directly created. Although a common class object cannot be directly created, it can be created as an attribute of other classes or instantiated from other classes. Dataset or geometry classes in AO are examples of abstract classes. A geometry type object cannot be created, but a polyline can be created. This polyl ine object actually implements the interface defined in geometry based on the class, so the interface defined in the base class object can be accessed from coclass.
The relational types in OMD mainly include type inheritance, instantiation, composition, and Associati ons. We mentioned in the com chapter that the inheritance actually completely inherits the superclass interface, which can be clearly seen by the AO Object Browser tool, the component relationship refers to the primary-secondary relationship between objects. That is to say, the existence of the subject's life determines whether the Sub-body exists.

3.4ao Organization Division
The OMD of the entire AO looks dense and dizzy. Fortunately, ESRI divides the entire AO structure and finds the corresponding OMD in pdf format according to different application fields. From the help of AO development, we can find the following subsystems:
1. 3D Analyst extension-component objects used for 3D visualization and surface modeling;
2. Application Framework --- allows developers to customize user interfaces In ArcMap and arccatalong;
3. arccatalog --- allows developers to expand the data object model and integrate custom objects and views into the arccatalog application framework ;.
4. ArcMap --- provides core functions of the ArcMap application for operations and display of map documents;
5. ArcMap editor --- includes the extension Component Object of the object editor. You need to edit and develop it;
6. an important application of display --- GIS is data performance, which is especially popular for many end users in China, the objects contained here can be used to complete functions such as Map Symbol display, graphic editing feedback track, coordinate transformation, and screen control;
7. geocoding --- mainly used to create and manage geocoding services;
8. geodatabase --- AO development is indispensable. After all, GIS applications focus on data, therefore, the related GIS Data creation, loading, management, and storage are all implemented through the object here;
9. Geometry --- whether it is a element or a graph, it involves the acquisition and application of spatial information;
10. IMS --- provides the ability to connect to the ArcIMS server and access ArcIMS images and element services;
11. Network --- provides network creation, management, and analysis operations. You plan to customize and develop network objects that can be used by specific network applications;
12. Output --- there is output when there is input. If you want to output the prepared map, use the object provided here to complete it;
13. Raster --- AO object used to access and manage raster data;
14. Spatial Reference --- used to complete the space reference settings;
15. streetmap USA extension --- this has little to do with domestic users.
It is true that in the development of AO, object layers and relationships are extremely important. What is missing is that object-level organizations in OMD seem a bit chaotic, I personally think that the object model graph in Exp Loring ArcObjects is more suitable for getting started-It extracts some common and important objects and expresses them in the lower-level structure.
Chapter iv ao Development
Casual chat, right as a pastime-recently took some time to sort out some previously written programs and began to understand the application of Mo (ESRI MapObject. The biggest task in GIS applications is data collection and arrangement. Although you can use map controls such as Mo and MapX (I have also seen a map control written by South China people using dephi, it is also very characteristic), if you are super-human, you can even make a map control yourself to complete a practical and personalized system. However, it is only an application system. ??? You should know what I want to talk about. All applications are based on a certain data structure. You can define a data model in your application development, but the data source. It's not CAD, it's coverage, shape, (standard) You can convert one or two data formats, but in reality the data types are diverse and you can't write them all at all, besides, can your data format be recognized. Think about how much work you have to do-that is what a GIS platform can do. This is why we cannot use the underlying layer or map control to write a complete GIS system in many cases.
Far away... In this chapter, I will implement a DLL with specific functions to illustrate the methods developed by AO, the use of the AO toolkit, and how to apply the written components. There are a lot of complete and detailed sample code in ArcObjects developer help. Here I want to give a brief description of the method.
4.1 select a development mode
There are two development methods available for AO: custom development based on the ArcMap application framework and independent application development without the ArcMap application framework. Generally, we perform custom development under the ArcMap framework. In the development environment, you can select the VBA that comes with ArcMAP, or select VB, Vc, and dephi (C # is supported for Versions later than AO 8.2 #).
4.2 select a development tool
As the first choice is the VB language, whether in VBA or COM components, you have the most adequate resources to use (the most sampl e in the AO development document is the VB Code ). The second is VC (I prefer to use VC as a powerful backup tool), and the third is helpless in my opinion, that is to say, using de PHI (a bunch of people should scold me :) has always admired dephi for a long time, but there are too few examples of dephi in AO, this is fatal for Fast Application Development ).
4.3 simplest "Hello, world" program
Discussing the number of development tools is a little different. Now let's turn back to a famous small application-"Hello, world". Many languages use this as the first application, I am no exception.
Open the ArcMap application, select the macros sub-menu under the Tools menu, and open the VBA environment. Select ar cmap object under the project, double-click the thisdocument object, select the mxdocument object in the object list in the editing environment on the right, and select opendocumen in the task list, enter the following code:
// Private function mxdocument_opendocument () as Boolean
Dim pmap as IMAP
Set pmap = new map
Pmap. Name = "Hello, world"
Msgbox pmap. Name
// End Function
Then press Ctrl + S to save and exit ArcMap. What do you see when you open your saved project document again? Heheh, I don't know if ESRI's designers will be dizzy when they see such a sample.
Some people have said that I don't understand this pile of VB code. I am familiar with VC. I cannot learn VB first and then do AO development. OK, it doesn't matter. Next I will use this "Hello, world" to write a component and use it in ArcMap.
1. Start VC and Use atl com Appwizard to create a DLL project;
2. select new ATL object under the Insert menu to add an atl com object,
3. Just give the COM object a "world" Name and select the custom interface type (as to why dual is not selected, you can think about it)
4. Select the cworld class in the workspace, right-click the implement interface, introduce ESRI Object Library in the Type Library, and select the interface you want to implement (Here we choose icommand)
5. Add a global variable (iapplicationptr m_ipapp;) to reference an application. I have noticed that the interface variable definition here is different from that of VB except for its own syntax. The 'ptr 'is added to the interface '. Therefore, you should have guessed how to use the AO object in VC.
6. the following work is to implement the interface. Let's see what is in the iworld interface. Oh, this onclick () should be the place where we want to do something.
// Stdmethodimp czoomin: onclick (){
Idocumentptr ipdoc;
M_ipapp-> get_document (& ipdoc );
Imxdocumentptr ipmxdoc (ipdoc );
Imapptr ipmap;
Ipmxdoc-> get_focusmap (& ipmap)
Ipmap-> put_name (_ bstr_t ("Hello, world "));
............
: MessageBox (null, _ T ("Hello world! "), _ T (" wellcom AO "), mb_ OK );
Return s_ OK;
//}
7. Compile the connection project;
8. After registering In ArcMap, you can drag and drop the button to ArcMap for use. (When you click, the modified Map Name "Hello, world" will pop up ".

4.4ao General Procedure
Whether it's using VB, Vc, or others, the first step is to import the AO Object Library (esricore. olb) into the integration environment. The rest of the work is to implement what you want to do in the interface. For complete code and instructions on how to enter VB and VC development, see arcobject developer help.

Chapter 5 AO advanced general components
Probably thanks to the rapid expansion of the independent AO Application Development Group, ESRI not only continues to provide development support for mapcontro l controls in its latest version of arcgis8.2, but also adds a pagelayoutcontrol control, this is undoubtedly a good news for developers who have graphic applications. In many cases, components and controls may be confused. In fact, Active X does not represent the entire com. It is only the encapsulation technology of COM objects. Due to the complexity of using COM objects, therefore, a framework (such as the Active X control) is created to simplify it. Therefore, these two controls are also known as the AO advanced general-purpose component. They are constructed by the Basic AO component and are oriented to common functions, simplifying the user development process, the collaborative control messages between groups are encapsulated. Components of this level are encapsulated to make secondary development easier. For example, for a simple AO application system, if you use basic AO component objects for development, you need to write a lot of code. Using Advanced general-purpose components, you only need a few lines of code.
5.1mapcontrol Control
The mapcontrol control provides a window similar to the data view In ArcMap, through which you can complete the following functions:
* Display the layer map.
* Zoom in, zoom out, and roam.
* Generate graphic elements, such as points, lines, circles, and polygon.
* Notes
* Recognizes selected elements on a map for space or attribute query.
* Add map elements.
In short, most tasks that can be completed in ArcMap can also be completed through the mapcontrol control. By setting mapcontrol General, layers, and map attributes, you don't even need to write a line of code to obtain some GIS functions. There are many complete examples of mapcontrol controls, which are stored in the \ ArcObjects developer kit \ samples \ controls directory.
5.2pagelayout Control
The pagelayout control provides a window similar to the Layout View In ArcMap. It has the following attributes, methods, and events:
* Display settings of management controls
* Manage Display Properties of controls
* Manage page properties
* Add and search elements to the control.
* Load map documents to controls
* You can drag and drop Data from resource manager and arccatalog directly to the control.
* Print the page design.
As for its functions, the Layout View of ArcMap can do the same with pagelayoutcontrol, such as adding and setting legends and printing output. There are many complete application examples for the page layout control, which are also stored in the \ ArcObjects developer kit \ samples \ controls directory.

5.3relationship between mapcontrol and MapObject
Specifically, mapcontrol and MapObject controls are not directly linked. First, mapcontrol is a part of AO, at least so far it is not an independent product, while MapObject is an independent low-end application product of ESRI. Second, mapcontrol is much more powerful and improved than m apobject. the positioning of MapObject is to provide some basic map functions. Advanced functions must be fully implemented by the initiator, relying on the powerful AO Component Library mapcontrol, it can implement many advanced GIS analysis and applications.

Come on, buddy. Start now!

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.