Design patterns in the ArcGIS engine-Factory mode

Source: Internet
Author: User

The first step in using AE to open or load data is to get a workspace (iworkspace) from the workspace Factory (iworkspacefactory), and then get the dataset (DataSet), feature Class (Featureclass) from the workspace, Tables (table).

For different types of spatial databases, corresponding to different workspace classes, these classes inherit the interface Iworkspacefactory, and then through the Iworkspacefactory interface different methods such as Create, Open, The openfromfile generates a working space of no type (iworkspace).

This pattern is the factory pattern in object-oriented design mode, and when we want to extend the new data type, we just need to create the corresponding workspace class, which inherits from Iworkspacefactory and then creates the corresponding workspace class, which inherits from the Iworkspace interface. This satisfies the principle of dependency reversal, realizes the design of easy maintenance, easy reuse, easy expansion and good flexibility.

Let's look at the relationship between classes and interfaces:

If we have a new data type, we just need to create a class that inherits from the Iworkspacefactory interface.

Where the workspace class contains most of our types (file, Geodata, SDE) to manage the data in the workspace, we can also extend and create classes that inherit from the Iworkspace interface.

Example:

Open Shapefile File:

Iworkspacefactory workspacefactory = new Shapefileworkspacefactoryclass ();
Iworkspace pworkspace = workspacefactory.openfromfile (string_shapefiledirectory, 0);

Open the Personal space database:

Iworkspacefactory paccessworkspacefactory = new Accessworkspacefactory ();

Iworkspace pworkspace = paccessworkspacefactory.openfromfile (pfullpath, 0);

Open the SDE Space database:

Iworkspacefactory paccessworkspacefactory = new Sdeworkspacefactory ();

Iworkspace pworkspace = Arcsdeworkspaceopen ("192.168.70.110", "Esri_sde", "SDE", "SDE", "", "SDE"). DEFAULT ");

The data in the Pworkspace is then manipulated.

If we are going to expand the spatial data type now, we have constructed a "text space data (TXT)", we need to extend the existing classes and interfaces.

First we create the factory class Txtworkspacefactory, inherit from Iworkspacefactory, and then create the interface Itxtworkspace interface, which has an operation method for the data in Txtworkspace. The Txtiworkspace class is then created, inheriting from the Iworkspace interface and the Itxtworkspace interface, which encodes the operation of the data in the Txtworkspacefactory class.

The implementation code is as follows:

Iworkspacefactory ptxtworkspacefactory = new Txtworkspacefactory ();

Iworkspace pworkspace = ptxtworkspacefactory. Openfromfile (Ptxtpath, 0);

Itxtworkspace txtworkspace = pworkspace as Itxtworkspace;

The method in Txtworkspace completes the data operation.

I guess it's the same architecture in ArcGIS engine that makes it easy to scale, easy to maintain, easy to reuse, and flexible.

In real-world development, we can borrow information from a configuration file to automatically instantiate some kind of data and implement dependency injection.

<localfile isenable= "true" mxdpath= "C:\Users\ZHU\Desktop\To \201301001_ detailed investigation \201301001_. Mxd"/>
<sdeserver isenable= "false" >
<serveritem isenable= "true" dbtype= "Oracle" ip= "192.168.1.1" dbname= "" service= "5151" sdeuser= "SDE" sdepassword= " SDE "version=" SDE. DEFAULT "connectiontype=" Serviceconnect "/>
</SDEServer>

According to the configuration file to determine the type of data, and then read the corresponding parameters, to obtain a workspace iworkspace.

In GIS development, our framework is usually created using a singleton pattern that contains information about the project, the coordinate system information of the project, the Mapcontrol of the project, the Pagelayoutcontrol, and so on.

<summary>
Host Program
</summary>
Public partial class Sbapplication:isbapplication,isbstatuscontrol, Isbmapstatuescontrol,isbdockmanager
{
Private Const string LOGNAME = "Sbapplication";
private static isbapplication M_appcontext;
private static bool M_isinitappcontext = FALSE;

Private form m_platform;//main form
Private Ribboncontrol M_ctrlribbon;//ribbon Control
Private Dockmanager M_platdock;//dockmanager
Private Ribbonstatusbar m_platstatusbar;//status bar
Private Axmapcontrol M_platmapcontrol;//mapcontrol
Private Axtoccontrol M_plattoccontrol;//toccontrol
Private Tabbedview m_plattabbedview;//Multi-Document form
Private ImageList m_imagelist;//Icon Collection
Private Isbtool m_currenttool;//Current Operation tool
Private list<popupmenu> m_lstpopupmenus;//Map Right-click popup menu

Private Xtratabcontrol M_tabcontrol;//tabcontrol
private string m_version;//version

Private Enumloadspatialdatatype m_loadspatialdatatype;//Spatial data load type
Private Systemmenu m_systemmenu;//System menu Configuration

Returns the static host program class Appcontext
public static Isbapplication AppContext
{
get {return m_appcontext;}
}

<summary>
constructor, which binds the event to the map control and the button control, the TOC control.
</summary>
<param name= "PlatForm" ></param>
<param name= "Platdock" ></param>
<param name= "Plattabbedview" ></param>
<param name= "Platmapcontrol" ></param>
<param name= "Plattoccontrol" ></param>
<param name= "ImageList" ></param>
Private Sbapplication (Ribbonform platForm, Dockmanager platdock, Tabbedview Plattabbedview, Axmapcontrol Platmapcontrol,axtoccontrol Plattoccontrol, ImageList ImageList)
{
M_platform = PlatForm;
M_ctrlribbon = Platform.ribbon;
M_platdock = Platdock;
M_plattabbedview = Plattabbedview;
M_platstatusbar = Platform.statusbar;
M_platmapcontrol = Platmapcontrol;
M_plattoccontrol = Plattoccontrol;
M_imagelist = imageList;

M_loadspatialdatatype = Enumloadspatialdatatype.loadsdelayer;

M_ctrlribbon.itemclick +=new DevExpress.XtraBars.ItemClickEventHandler (M_ctrlribbon_itemclick);

M_platmapcontrol.onmousedown +=new Imapcontrolevents2_ax_onmousedowneventhandler (M_platMapControl_OnMouseDown);
M_platmapcontrol.onmousemove +=new Imapcontrolevents2_ax_onmousemoveeventhandler (m_platMapControl_OnMouseMove);
M_platmapcontrol.onmouseup +=new Imapcontrolevents2_ax_onmouseupeventhandler (m_platmapcontrol_onmouseup);
M_platmapcontrol.ondoubleclick +=new Imapcontrolevents2_ax_ondoubleclickeventhandler (M_platMapControl_ OnDoubleClick);
M_platmapcontrol.onkeydown +=new Imapcontrolevents2_ax_onkeydowneventhandler (M_platmapcontrol_onkeydown);
M_platmapcontrol.onkeyup +=new Imapcontrolevents2_ax_onkeyupeventhandler (m_platmapcontrol_onkeyup);
m_platmapcontrol.onextentupdated +=new Imapcontrolevents2_ax_onextentupdatedeventhandler (M_platMapControl_ onextentupdated);
m_platmapcontrol.onfullextentupdated +=new Imapcontrolevents2_ax_onfullextentupdatedeventhandler (m_ platmapcontrol_onfullextentupdated);
m_platmapcontrol.onmapreplaced +=new Imapcontrolevents2_ax_onmapreplacedeventhandler (M_platMapControl_ onmapreplaced);
M_platmapcontrol.onselectionchanged +=new EventHandler (m_platmapcontrol_onselectionchanged);
M_platmapcontrol.onafterdraw +=new Imapcontrolevents2_ax_onafterdraweventhandler (M_platMapControl_OnAfterDraw);
m_platmapcontrol.onviewrefreshed +=new Imapcontrolevents2_ax_onviewrefreshedeventhandler (M_platMapControl_ onviewrefreshed);

M_plattoccontrol.onmousedown +=new Itoccontrolevents_ax_onmousedowneventhandler (M_platTOCControl_OnMouseDown) ;
}

<summary>
Initializing the host program portal
</summary>
<param name= "PlatForm" > Main interface </param>
<param name= "Platdock" >DockManager</param>
<param name= "Plattabbedview" > Multi-Document Form </param>
<param name= "Platmapcontrol" > Map Controls </param>
<param name= "Plattoccontrol" >toc controls </param>
<param name= "imageList" > Icon set </param>
public static void Initappcontext (Ribbonform platForm, Dockmanager platdock, Tabbedview Plattabbedview, Axmapcontrol Platmapcontrol, Axtoccontrol plattoccontrol,imagelist ImageList)
{
if (!m_isinitappcontext)
{
if (PlatForm = = NULL | | platdock = = NULL | | plattabbedview = NULL | | platmapcontrol = NULL)
{
Return
}
M_appcontext = new Sbapplication (PlatForm, Platdock, Plattabbedview, Platmapcontrol, plattoccontrol,imagelist);
M_isinitappcontext = true;
}
}

Getting the host program through a static method

Sbapplication.initappcontext (This, DockManager1, Tabbedview, AxMapControl1, AxTOCControl1, ImageList1);
SBApplication.AppContext.Version = m_systemmenuadmin.version;
SBApplication.AppContext.LoadMenuPlugins (m_systemmenuadmin);

M_appcontext = Sbapplication.appcontext;

It probably contains all the patterns of creating objects in the design pattern, and the ARCGIS engine contains a lot of design patterns, which are described later.

Design patterns in the ArcGIS engine-Factory mode

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.