Open connections to various data sources (workspace) in arcengine

Source: Internet
Author: User
Tags polyline
(SDE, personal/file, shapefile, CAD data, image and image dataset)

From: http://www.byywee.com/page/M0/S578/578771.html

Arcengine can take over multiple data sources. During the development process, we applied the following data sources:

1. enterprise database (SDE)

Enterprise databases need to be managed by SDE, so the workspace of Sde must be used to implicitly connect. In the AE interface, the workspace is opened by the factory. The Code is as follows: // configure the connection Parameters

ESRI. ArcGIS. esrisystem. ipropertyset ppropset = new
Propertysetclass ();

Ppropset. setproperty ("server", "server mechanical name ");

Ppropset. setproperty ("instance", "SDE running Terminal slogan ");

Ppropset. setproperty ("user", "User Name ");

Ppropset. setproperty ("password", "password ");

Ppropset. setproperty ("version", "version ");

Sdeworkspacefactory sdewkspfact = new
Sdeworkspacefactoryclass ();

Ifeatureworkspace
Pfeawksp = (ifeatureworkspace) sdewkspfact. Open (ppropset, 0 );

The only thing that needs to be affirmed in this article may be the version. For no application version or the first connection (no space database creation, of course no version), the SDE. Default version is applied here. This is the default version.

Ipropertyset: setproperty

Public void setproperty (string name, object value)

2. Personal Database (personalgeodatabase, filegeodatabase)

In arcengine, access is used for small and medium-sized databases.

String filepath = "E: \ TT. mdb ";

Accessworkspacefactory FAC = new
Accessworkspacefactoryclass ();

Ifeatureworkspace
Space = (ifeatureworkspace) FAC. openfromfile (filepath, 0); this is the most commonly used style.

If it is filegeodatabasse

Filegdbworkspacefactory pwsf =
New filegdbworkspacefactory;

Ifeatureworkspace pws1 =
Pwsf. openfromfile (Spath, 0 );

 

If ipropertyset is used. As follows:

// Personal Geodatabase e.g., database =
"C: \ mydata \ mypgdb. mdb"

Public iworkspace open_pgdb_workspace (string database)

{

Ipropertyset propertyset = new propertysetclass ();

Propertyset. setproperty ("Database", database );

Iworkspacefactory workspacefactory = new
Accessworkspacefactoryclass ();

Return workspacefactory. Open (propertyset, 0 );

}

3. shapefile

The open format of shapefile and access is a bit similar. There are also differences.

// This is the directory of the Shape location (importance: Directory)

String spacepath = "E: \ shapefile ";

Ishapefileworkspacefactory FAC = new
Shapefileworkspacefactoryclass (); ifeatureworkspace
Space = (ifeatureworkspace) FAC. openfromfile (spacepath, 0 );

Ifeatureclass fc = space. openfeatureclass ("China ");

4. AutoCAD DWG File

The AutoCAD file and general ESRI pattern are inconsistent. So the code is a little fresh. Assume that a DWG file is E: \ CAD \ 107.dwg.
The opening code is as follows:

Cadworkspacefactoryclass FAC = new cadworkspacefactoryclass
();

String filepath = "E: \ CAD ";

Ifeatureworkspace Space = FAC. openfromfile (filepath, 0)
Ifeatureworkspace;

The following code opens featureclass:

// Line

Ifeatureclass polyline
= Space. openfeatureclass ("107.dwg: polyline ");

Ifeaturelayer layer = new cadfeaturelayerclass ();

Layer. featureclass = polyline;

// Point

Ifeatureclass point = space. openfeatureclass ("107.dwg: point ");

Layer = new cadfeaturelayerclass ();

Layer. featureclass = point;

// Plane

Ifeatureclass polygon = space. openfeatureclass
("107.dwg: polygon ");

Layer = new cadfeaturelayerclass ();

Layer. featureclass = polygon;

// Note

Ifeatureclass Anno = space. openfeatureclass
("107.dwg: annotation"); layer = new cadannotationlayerclass ();

Layer. featureclass = Anno;

5. image files

// File path

String filepath = "E: \ image \ 117.tif ";

Irasterlayer rasterlayer = new rasterlayerclass ();

Rasterlayer. createfromfilepath (filepath );

6. image dataset in the database.

// Database connection

Iworkspace Space = Openspace ();

// Open the format of the database.

Irasterworkspaceex rasterspace = (irasterworkspaceex) space;

Irasterdataset rasterdataset = rasterspace. openrasterdataset
(Setname. Name );

Irasterlayer raslayer = new rasterlayerclass ();

Raslayer. createfromdataset (rasterdataset );

Irasterworkspaceex: provides a way to create and open a grid directory or a grid dataset.

However, irasterworkspaceex, irasterworkspace, irasterworkspace2 all have openrasterdataset. Irasterworkspace is often used to open raster data, such as pworkspacefactory = new rasterworkspacefactoryclass ();

Prasterworkspace = (irasterworkspace) pworkspacefactory. openfromfile (filepath, 0 );

Irasterdataset prasterdataset = (irasterdataset) prasterworkspace. openrasterdataset (filename );

Irasterlayer prasterlayer = new rasterlayerclass ();

Prasterlayer. createfromdataset (prasterdataset );

 

 

From: http://www.cnblogs.com/caodajieup/archive/2011/10/15/2212839.html

Arcengine supports multiple data sources. In the development process, we use the following data sources:
1. enterprise database 2. Personal Database 3. shapefile 4. AutoCAD DWG File 5. Image File
6. image dataset in the database.
The following describes how to open the above data source:
1. enterprise database.
Enterprise databases must be managed using SDE. Therefore, the workspace of Sde is used to represent connections.
In the AE interface, the workspace is opened by the factory.
The Code is as follows:
//
// Prepare the connection parameter ESRI. ArcGIS. esrisystem. ipropertyset ppropset = new propertysetclass ();
Ppropset. setproperty ("server", "server machine name ");
Ppropset. setproperty ("instance", "SDE running port number ");
Ppropset. setproperty ("user", "User Name ");
Ppropset. setproperty ("password", "password ");
Ppropset. setproperty ("version", "version ");
ESRI. ArcGIS. datasourcesgdb. sdeworkspacefactory sdewkspfact = new
Sdeworkspacefactoryclass ();
Ifeatureworkspace
Pfeawksp = (ifeatureworkspace) sdewkspfact. Open (ppropset, 0 );
The only thing that needs to be explained is the version.
(No space database is created, of course no version is available ).
SDE. Default is used here. This is the default version.
2. Personal Database
In arcengine, the personal database is access.
String filepath = "E: TT. mdb ";
Accessworkspacefactory FAC = new accessworkspacefactoryclass ();
Ifeatureworkspace Space = (ifeatureworkspace) FAC. openfromfile (filepath, 0 );
This is the most commonly used method. Because access has no user or password set on the local machine. Unknown Addition
Encrypted
How access is connected. It is estimated that ipropset is also used. We don't need it, so we didn't test it.
3. shapefile
Shapefile and access are opened in the same way. There are also differences.
// This is the directory where the shape is located (Note: it is a directory );
String spacepath = "E: \ shapefile ";
Shapefileworkspacefactory FAC = new
ESRI. ArcGIS. datasourcesfile. shapefileworkspacefactoryclass ();
Ifeatureworkspace Space = (ifeatureworkspace) FAC. openfromfile (spacepath, 0 );
4. AutoCAD.
The AutoCAD file format is different from the general ESRI format. So the code is a little strange.
Assume that a DWG file is E: \ CAD \ 107.dwg.
The opening code is as follows:
Cadworkspacefactoryclass FAC = new cadworkspacefactoryclass ();
String filepath = "E: \ CAD ";
Ifeatureworkspace Space = FAC. openfromfile (filepath, 0) as ifeatureworkspace;
The following code opens featureclass:
// Line
Ifeatureclass polyline = space. openfeatureclass ("107.dwg: polyline ");
Ifeaturelayer layer = new cadfeaturelayerclass ();
Layer. featureclass = polyline;
// Point
Ifeatureclass point = space. openfeatureclass ("107.dwg: point ");
Layer = new cadfeaturelayerclass (); layer. featureclass = point;
// Plane
Ifeatureclass polygon = space. openfeatureclass ("107.dwg: polygon ");
Ayer = new cadfeaturelayerclass ();
Layer. featureclass = polygon;
// Note
Ifeatureclass Anno = space. openfeatureclass ("107.dwg: annotation ");
Layer = new cadannotationlayerclass ();
Layer. featureclass = Anno;
// There is also multipatch. No.
5. image files in the file system:
// File path
String filepath = "E: \ image \ 117.tif ";
ESRI. ArcGIS. Carto. irasterlayer
ESRI. ArcGIS. Carto. rasterlayerclass ();
PRS = new PRS. createfromfilepath (filepath );
This method is a bit strange. I don't know if there is any heh.
6. Image in the database
// Database connection
Iworkspace Space = Openspace (); // for how to open a database, see 1 and 2.
Irasterworkspaceex rasterspace = (irasterworkspaceex) space;
Irasterdataset rasterdataset = rasterspace. openrasterdataset (setname. Name );
Irasterlayer raslayer = new rasterlayerclass ();
Raslayer. createfromdataset (rasterdataset );
This is also strange, huh, huh.

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.