AE data loading

Source: Internet
Author: User
Tags informix

1,Data Loading Problems:

Any system cannot do without data loading. Below we will list several common data loading methods in AE. For reference:

1Load the personal database

A personal database is a database stored in Access. There are two ways to load data: by name and by attribute (maybe more than these two ways, AE can implement the same function in multiple ways ).

AAnd load the personal database by setting properties.

First passIPropertySetThe interface defines the relevant attributes of the database to be connected. In the personal database, it is the database path, for example:

 IPropertySet Propset = new PropertySetClass ();

Propset. SetProperty ("DATABASE", @ "D: \ test \ Ao \ data \ sh \ MapData. mdb ");

 After defining the attributes and setting the attributes, you can open the database. It exists in ArcEngine development.IWorkspaceFactory, IFeatureWorkspace, IFeatureClass, IFeatureLayerAnd so on.IWorkspaceFactoryIs an interface used to create and open a workspace. It is an abstract interface. We need to instantiate it with the corresponding workspace when using a specific application, as shown below:

IWorkspaceFactory Fact = new AccessWorkspaceFactoryClass ();

If we open the SDE database, we need to useSdeWorkspaceFactoryClassInstantiationFact. After the workspace is instantiated, you can open the corresponding Access database based on the properties set above. The method is as follows:

IFeatureWorkspace Workspace = Fact. Open (Propset, 0) as IFeatureWorkspace;

 

What to do next after opening the Access workspace is very simple. Find the corresponding feature class, assign it to the corresponding layer, add the corresponding layer through the MapControl control, and then refresh the map. The following code adds a layer:

IFeatureClass Fcls = Workspace. OpenFeatureClass ("District ");

IFeatureLayer Fly = new FeatureLayerClass ();

 Fly. FeatureClass = Fcls;

 MapCtr. Map. AddLayer (Fly );

MapCtr. ActiveView. Refresh ();

WhereDistrictIs the name of the Ground Object Class,MapCtrIsAE. The above method of loading data space through attribute settings can also be used in the SDE database, which will be introduced during the loading of the SDE database.

The complete C # code for loading the Access database by setting properties is as follows:

Public void AddAccessDBByPro (){

 IPropertySet Propset = new PropertySetClass ();

Propset. SetProperty ("DATABASE", @ "D: \ test \ Ao \ data \ sh \ MapData. mdb ");

 IWorkspaceFactory Fact = new AccessWorkspaceFactoryClass ();

IFeatureWorkspace Workspace = Fact. Open (Propset, 0) as IFeatureWorkspace;

 IFeatureClass Fcls = Workspace. OpenFeatureClass ("District ");

 IFeatureLayer Fly = new FeatureLayerClass ();

 Fly. FeatureClass = Fcls;

MapCtr. Map. AddLayer (Fly );

MapCtr. ActiveView. Refresh ();

}

 BLoad a personal database by database name

Here I will first write the complete code so that you can first compare it with the above Code. The complete code is as follows:

Public void AddAccessDBByName (){

IWorkspaceName pWorkspaceName = new WorkspaceNameClass ();

PWorkspaceName. WorkspaceFactoryProgID = "esrisponcesgdb. AccessWorkspaceFactory ";

PWorkspaceName. PathName = @ "D: \ test \ Ao \ data \ sh \ MapData. mdb ";

IName n = pWorkspaceName as IName;

IFeatureWorkspace Workspace = n. Open () as IFeatureWorkspace;

 IFeatureClass Fcls = Workspace. OpenFeatureClass ("District ");

IFeatureLayer Fly = new FeatureLayerClass ();

Fly. FeatureClass = Fcls;

MapCtr. Map. AddLayer (Fly );

MapCtr. ActiveView. Refresh ();

}

Careful people have noticed that the following code is the same after opening the Access workspace. They all find the corresponding feature class, assign it to the corresponding layer, and add the corresponding layer through the MapControl control, then refresh the map. Now I will explain the above Code. First, I will create a personal database workspace name and specify the ProgID of the workspace name to determine what type of workspace is opened, for example, the following code is used when accessing the personal database:

IWorkspaceName pWorkspaceName = new WorkspaceNameClass ();

PWorkspaceName. WorkspaceFactoryProgID = "esrisponcesgdb. AccessWorkspaceFactory ";

 PWorkspaceName. PathName = @ "D: \ test \ Ao \ data \ sh \ MapData. mdb ";

The WorkspaceFactoryProgID attribute ensures that the workspace is AccessWorkspaceFactory, that is, a personal database, and specifies the path to open the database. In order to open the database, we can use the AE class diagram to find that the IName interface must be used to open the workspace (I think it is not necessarily correct. You can think about other methods ), therefore, define the IName object, convert the workspace name to the IName type, assign a value to the IName object, and Open the corresponding workspace through the Open () method of the IName object. The Code is as follows:

 IName n = pWorkspaceName as IName;

IFeatureWorkspace Workspace = n. Open () as IFeatureWorkspace;

The next thing is mentioned above.

 2, LoadSDEDatabase

What is an SDE database? It takes a lot of time to explain this question in detail, but I can tell you that SDE can be any relational database. ESRI is a middleware developed by ESRI to ensure that spatial data can be stored in relational databases and to query related spatial attributes, using SDE can store space data in relational databases. Such as Orcale SQL Server. For details about SDE, please refer to the relevant information. Here we only show you how to connect to the SDE database. The SDE database can be connected directly or through SDE. When the server performance is good, you can use SDE connection. Otherwise, you can use direct connection to reduce server tasks. Direct Connection is recommended. In fact, the SDE connection method and direct connection method are only a problem of attribute parameter settings. Like using the property connection method in a personal database, first define an attribute object, then set the attribute parameter, then define a workspace and instantiate it with SdeWorkspaceFactoryClass (), and then add it to the loading layer, as for the code for loading layers, the method for loading layers in the personal database is the same. In fact, not only are these two data types loaded, but the method for loading other data types is also the same, it's just that different instances are used in the workspace. Which of the following statements is true:

 Public void AddSDELayer (bool ChkSdeLinkModle){

//Define an attribute

 IPropertySet Propset = new PropertySetClass ();

If (ChkSdeLinkModle = true)//Connect using SDE

{

 //Set database server name

Propset. SetProperty ("SERVER", "zhpzh ");

 //Set the SDE port, which is specified during installation. The default port is "port: 5151"

 Propset. SetProperty ("INSTANCE", "port: 5151 ");

 // SDEUser Name

 Propset. SetProperty ("USER", "sa ");

 //Password

 Propset. SetProperty ("PASSWORD", "sa ");

//Set the database name. Only the SQL Server Informix database needs to be set

 Propset. SetProperty ("DATABASE", "sde ");

// SDEIs the default version.

 Propset. SetProperty ("VERSION", "SDE. DEFAULT ");

 }Else //Direct Connection

 {

//Set the database server name. If it is a local machine, you can use "sde: sqlserver :."

 Propset. SetProperty ("INSTANCE", "sde: sqlserver: zhpzh ");

 // SDEUser Name

 Propset. SetProperty ("USER", "sa ");

 //Password

 Propset. SetProperty ("PASSWORD", "sa ");

//Set the DATABASE name. Only the SQL Server Informix DATABASE needs to set Propset. SetProperty ("DATABASE", "sde ");

// SDEIs the default version.

 Propset. SetProperty ("VERSION", "SDE. DEFAULT ");

}

//Define a workspace and convert it into an SDE Workspace

 IWorkspaceFactory Fact = new SdeWorkspaceFactoryClass ();

 //Open the SDE workspace and convert it to a map workspace.

 IFeatureWorkspace Workspace = (IFeatureWorkspace) Fact. Open (Propset, 0 );

 /*Define a ry class and open the ry class in SDE. Make sure to write it fully when writing it. for example, if SDE has a pipe point layer, you cannot write it as IFeatureClass Fcls = Workspace. openFeatureClass ("pipe point"); in this way, it must be written as below. */

 IFeatureClass Fcls = Workspace. OpenFeatureClass ("sde. dbo.Management point ");

 IFeatureLayer Fly = new FeatureLayerClass ();

 Fly. FeatureClass = Fcls;

MapCtr. Map. AddLayer (Fly );

 

MapCtr. ActiveView. Refresh ();

 }

 

I don't know. The biggest difference between direct connection and SDE is that do not set ports for direct connection, and their parameter settings are different. Pay attention to parameter settings.

3. LoadCADLayer

The loading of CAD layers can be divided into: layer-based loading and full graph loading.

 A,Layer-based loading

We can load a CAD chart into MapControl by dividing it into point/line labels. Just like loading other data, we must first define a workspace and instantiate it with CadWorkspaceFactoryClass, after obtaining the workspace, you can open the corresponding workspace and then open the specified layer type. The complete code is as follows:

  Public void AddCADByLayer ()
{

 // Define the workspace and instantiate it with CadWorkspaceFactoryClass ()

 IWorkspaceFactory Fact = new CadWorkspaceFactoryClass ();

 

// Open the corresponding workspace and assign it to the element space, OpenFromFile ()

 

// The parameter in is the path of the CAD folder

 

IFeatureWorkspace Workspace = Fact. OpenFromFile (@ "I: \ test \", 0) as IFeatureWorkspace;

/*Open the line element class. To open the element of the point type, you need to convert the following code:

 

IFeatureClass Fcls = Workspace. OpenFeatureClass ("modle. dwg: point ");

 

It can be seen that modle. dwg is the name of the CAD chart, followed by the type of the element class to be opened, separated by a colon in the middle, you can think about how the polygon and annotation are opened. */

 

IFeatureClass Fcls = Workspace. OpenFeatureClass ("modle. dwg: polyline ");

IFeatureLayer Fly = new FeatureLayerClass ();

 

Fly. FeatureClass = Fcls;

 

MapCtr. Map. AddLayer (Fly );

 

MapCtr. ActiveView. Refresh ();}

 

B,Loading of the whole CAD chart

When we want to load the entire CAD image, we need to use the following code, which is different from loading the Ground Object Class. For details, see the analysis in the Code:

 

Public void AddWholeCAD ()
{

 

/* The following two lines of code define a CAD workspace and open it, but this time it is not assigned

 

IFeatureWorkspace object, which is assigned to the IWorkspace Defined Object */

 

IWorkspaceFactory Fact = new CadWorkspaceFactoryClass ();

 

IWorkspace Workspace = Fact. OpenFromFile (@ "I: \ test \", 0 );    

 

// Define a CAD Drawing space and assign the workspace opened above to it

 

ICadDrawingWorkspace dw = Workspace as ICadDrawingWorkspace;

 

// Define a CAD Drawing dataset and open a CAD diagram in the specified workspace above

 

// Assign the value to the CAD Dataset

 

ICadDrawingDataset ds = dw. OpenCadDrawingDataset ("modle. DWG ");

 

// Assign the CAD data obtained above to

 

// CadDrawingDataset attributes

 

ICadLayer CadLayer = new CadLayerClass ();

 

CadLayer. CadDrawingDataset = ds;

 

//Use MapControl to load the CAD Layer

 

MapCtr. Map. AddLayer (CadLayer );

 

MapCtr. ActiveView. Refresh ();

 

}

 

Through the above Code and related analysis, you may have an understanding of the loading of the whole CAD chart, but it is not so easy to understand its meaning. This is for everyone to understand. Here I will talk about my own experiences, but it is not necessarily correct. To open a dataset, you must first open its workspace. As for what is a workspace, I do not quite understand it, but I understand that if the data is saved in a file, the workspace is probably the corresponding folder. If it is the data in the database, I think it is probably the corresponding database. After opening the data space, the whole CAD image is loaded, so it is a little different from the previous one. This means that the entire CAD image is a dataset, so we need to go to the workspace of the CAD drawing, and then open the CAD drawing as the CAD dataset. To load the CAD layer in MapControl, you must use the ICadLayer control object because the MapCtr. Map. AddLayer () method can only be an object of ICadLayer.

 

You are welcome to repost it. The copyright is shared by the author and the blog.

Author: Wen jingliang

Article Source: http://wenjl520.cnblogs.com/or http://www.cnblogs.com/

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.