1. ArcObjects Introduction The software reuse is the target of the industry. People have always hoped that they can "assemble" applications like wood; the component object acts as a role of building blocks. The so-called component object is actually pre-defined, and can complete a certain functional service or interface. Microsoft's Component Object Model (Component Object Model, Abbample COM) is a specification that interfaces between components objects. Any object that follows the COM interface specification can communicate and interact between each other, even if these objects are written by different vendors, they are built on different Windows versions even on different machines.
ArcObjects is a set of COM technology-based component libraries provided by ESRI. ArcGIS (TM) software family ARCMAP (TM), ArcCatalog (TM), and ArcScene (TM) applications are built from ArcObjects. COM is still a client / server mode, such as "Figure A", customer (usually an application) requests to create a COM object and manipulate the COM object through the interface of the COM object, and the server creates and manages the COM object according to the customer's request. COM is a binary specification. It is not related to the source code. We can use any programming language that supports COM (such as Visual Basic, Visual C , Delpi, etc.) to do ArcObjects application development. However, the current ArcObjects is not an independent SDK, so use ArcObjects to develop a separate application, must be performed in an environment where ArcInfo (TM), ArcEditor (TM), or ArcView (TM) is installed to obtain software. license.
Second, the development process of ArcObjects under the Delphi programming environment is written in Visual Basic and Visual C due to the random arcobjects development help manual (ArcObjects Developer Help) and the ArcScripts on the ESRI homepage. In order to make the programmers who are accustomed to using Delphi can easily use ArcObjects to develop independently, we use Delphi 5 ArcObjects to construct a simple GIS application as an example for reference. This application implements some: graphical data loading, magnification, reduction, roaming, panoramic display, and features that add a point-like graphic tag on the map.
Explanation: After you have done first, steps of work can be skipped, walking directly from the third step. Step 1: Introducing the ArcObjects type library file Using the Delphi 5.0 "Project | Import Type Library ..." menu item opens the Import Type Library dialog, found "Esri Object Library (Version 1.0)" from its type library file list box. , Is "% Archome / Bin / Esricore.olb" file. Next, it is necessary to pay attention, at this time, in the "class name" list, all Esricore.olb implementation classes are listed in the class name. Since some of the class names are repeated with the class names defined in Delphi's VCL component library, in order to avoid generating Conflict, it is recommended to turn all the names of the above list by the original "T" start to the beginning of "TESRI", and finally press "CREATE UNIT", which is in the "Unit Dir Name" edit box. Generate an Object Pascal jacket file called "Esricore_TLB.PAS", which can see all GUID constants, types, interfaces, and CoClass component classes in this type library. Step 2: Introducing ArcObjects Map Control Use the "Component | Import ActiveX Control ..." menu item to open the Import ActiveX dialog, find "Esri ArcObjects Controls 8.1" Esri ArcObjects Controls 8.1 (Version1.0) "and press" "from its ActiveX control list box. Install ...... button and then "confirm" all the way. This will appear on a "TMAPControl" type ActiveX control on the ActiveX page of the Palette Control Panel.
Step 3: Functional implementation 1. Prepare a new project first using the "File | New Application ..." menu item, then select the "MapControl" control on the ActiveX page of the Palette Control Panel, drag and drop with the mouse to the new project On the form, the MapControl's Name property is set to mapControl, the Align property is set to AlClient, and the Showscrollbars property is set to false. Finally, add reference to "Esricore_TLB" after the Uses sentence in the Unit1 unit interface section, which is a critical, otherwise the compiler can not find the relevant Interface and CoClass declaration. 2. Loading a layer on the MapControl control This is introduced herein to use the data of the Shapefile format. Form1 form to add a method of loading the shapefile global AddShpLayer, codes are as follows: function TForm1.AddShpLayer (FilePath, FileName: String): String; varpWFactory: IWorkspaceFactory; pPropertySet: IPropertySet; pWorkspace: IWorkspace; pFWorkspace: IFeatureWorkspace; pFClass: IFeatureClass; pFLayer: IFeatureLayer; begintrypWFactory: = CoShapefileWorkspaceFactory.Create as IWorkspaceFactory; pPropertySet: = CoPropertySet.Create as IPropertySet; pPropertySet.SetProperty ( 'DATABASE', FilePath); pWFactory.Open (pPropertySet, self.Handle, pWorkspace); pFWorkspace: = pWorkspace as IFeatureWorkspace; Delete (FileName, Length (FileName) -3,4); pFWorkspace.OpenFeatureClass (FileName, pFClass); pFLayer: = coFeatureLayer.Create as IFeatureLayer; pFLayer.Set_FeatureClass (pFClass); pFLayer.Set_Name (FileName) MapControl1.addlayer (pflayer); Result: = filename; ExcePton E: Exception do result: = '; end; end; then add the following code in the form Form1 on the oncreate event: AddShplayer (' d: / gisdata / ',' Stats.shp '; press F9 running program (previously ensured D: /Gisdata/states.SHP layer file exists, i.e., at least D: /Gisdata/states.SHP, D: / gisdata / stats. SHX, D: /GiSData/states.dbf three files), you will find that the States layer has been added to the mapControl control.
3. Map of magnification, shrink, roaming, and panorama Add the following code in the onmousedown event of the MapControl control: Procedure TForm1.mapControlmousedown (Sender: Tobject; Button, Shift, X, Y: Integer; Mapx, MAPY: Double); Varenvlp: ienvelope; biSempty: wordBool; begin // Press the left mouse button on MapControl to do the mouse button, implement the map to enlarge function if (button = 1) and (shift = 0) Then BeginmapControl.MousePointer: = esripointerzoom ;; Envlp : = MapControl.TrackRectangle; Envlp.get_ISempty (Bisempty); if not bisempty lifeMapControl.extent: = envlpeXITEND; // Press the Shift key while pressing the left mouse button on MapControl to make a click action, implement a map Reduce Function IF ( Button = 1) and (shift = 1) Then BeginmapControl.MousePointer: = esripointerzoomout; envlp: = mapControl.extent; envlp.expand (2, 5, false); mapControl.extent: = envlp; exit; end; // after pressing the right mouse button to make the drag operation Mapcontrol achieve roaming map if (button = 2) and (Shift = 0) then beginMapControl.MousePointer: = esriPointerPanning; MapControl.Pan; MapControl.MousePointer: = esriPointerPan; exit; End; End; add the following code in the onDoubleClick event of the MapControl control: Procedure TFORM1.MAPControl1doubleClick (Sender: Tobject; Button, Shift, X, Y: Integer; Mapx, MAPY: Double); Begin // Double-click on MapControl, implement map panorama display function mapControl1.extent: = mapControl1.fullextent; end;
4. Add a point-like graphic tag to the map first declare the private variables of the two forms of Form1: f_multipoint: iMultipoint; f_pts: ipointCollection; add the following code in the form Form1 on the oncreate event: f_multipoint: = Comult.create as IMultiPoint; F_Pts: = F_MultiPoint as IPointCollection; then add to the Form1 form a global method for adding marks in a dot pattern DrawPoint, codes are as follows: procedure TForm1.DrawPoint; varpt_cnt, i: integer; sym: ICharacterMarkerSymbol; pt: IPoint; ft: TFont; oleft: variant; ScreenDisplay: IScreenDisplay; ActiveView: IActiveView; beginActiveView: = MapControl.ActiveView; ActiveView.Get_ScreenDisplay (ScreenDisplay); F_Pts.Get_PointCount (pt_cnt); if pt_cnt> 0 thenbeginScreenDisplay.StartDrawing (0 , 0); for i: = 0 to PT_cnt-1 dobeginf_PTS.GET_POINT (I, PT); SYM: = COCharactermarkersymbol.create as iCharactermarkersymbol; sym.set_size (30); ft: = tfont.create; ft.size: = 40; ft.name: = 'WINGDINGS'; oleft: = fonttoolefont (ft); sym.set_font (iDispatch (oleft))); Sym.Set_CharacterIndex (i 33); ScreenDisplay.setsymbol (SYM as ISYMBOL); ScreenDisplay.drawpoint (pt); end; screen; end; end; then in the MapControl control The following code is added to the onMouseDown event: / / Press the Shift key to press the mouse button on the mapControl to do click action, // Implement the function IF (Button = 2) and (Button = 2) AND Shift = 1) then beginpt: = mapcontrol1.ToMapPoint (x, y); F_Pts.AddPoint (pt, EmptyParam, EmptyParam); DrawPoint; exit; end; finally, add the following code in the event Mapcontrol OnAfterDraw in control: procedure TForm1 .Mapcontrolafterdraw (sender: TOBJECT; Constisplay: Idisplay; Phase: toleenum); BegindrawPoint; // Used to refresh the dot graphics end; this, a application containing some simple GIS features is completed (Press F9 to run).