From: http://www.cnblogs.com/caodajieup/archive/2010/07/01/1768831.html
Data is the basis of GIS, and data access is also the prerequisite for any complex spatial analysis and spatial visualization. ArcGIS supports a wide range of data formats, and supports a wide range of data formats. This article describes how to access the following eight data formats in ArcGIS Engine. Readers who have some knowledge about ArcGIS desktop applications are more suitable for reading this article. The sample code in this article is written in C.
1. shapefile
2. Coverage
3. Personal Geodatabase
4. Enterprise Geodatabase
5. Tin
6. Raster
7. CAD
8. RDBMS
Before accessing data through ArcGIS, you must first clarify what is a "workspace ". In ArcGIS, a workspace refers to the location where data is stored. The data access mechanism of ArcGIS is to first open the workspace corresponding to the data and then access the data using the workspace. For different data formats, the details of the workspace are also different.
Shapefile
Shapefile is a file-type space data format. It stores space data and attribute data on disks as files. The following sample code opens the shapefile element class named cities in the D: "data folder. For a shapefile, the workspace is the folder where it is located. To open the workspace, you need to use the corresponding workspace factory, that is, shapefileworkspacefactoryclass, and then call the openfromfile method of iworkspacefactory to get a workspace, this is also the embodiment of the factory method in the design model. The open method of the workspace factory returns a normal workspace. Interface Conversion is also required based on the specific data. Because the shapefile is vector data, the workspace interface is redirected to ifeatureworkspace, to read the element classes, this is the same way for the following data formats.
Iworkspacefactory pworkspacefactory;
Pworkspacefactory =
New shapefileworkspacefactoryclass ();
Ifeatureworkspace pfeatws;
Pfeatws = pworkspacefactory. openfromfile (@ "D:" data "",
0)
As ifeatureworkspace;
// Open a feature class
Ifeatureclass pfeatureclass = pfeatws. openfeatureclass ("Cities ");
Coverage
Coverage is the native data format of ArcInfo Workstation. This format is based on folder storage, because in Windows Resource Manager, its space information and attribute information are stored in two folders respectively. Coverage is a very successful early geographic data model that has been well received by users for more than 20 years. Many of the early data is in the coverage format. ESRI does not disclose the coverage data format, but provides an interchange file (e00) for coverage format conversion, and discloses the data format. However, to promote its third-generation data model Geodatabase, ESRI
The coverage editing function is blocked starting with version 8.3. To use data in the coverage format, you can install ArcInfo Workstation or convert the coverage data to another editable data format. Coverage is a set that can contain one or more element classes. The workspace of coverage data is also its folder. Because coverage can contain multiple element classes, you can use "coverage Name: element class name, for example, "Basin: polygon" in the following code ".
Iworkspacefactory pfactory =
New arcinfoworkspacefactoryclass ();
Iworkspace pworkspace = pfactory. openfromfile (@ "D:" arctutor "topologydata ",
0 );
Ifeatureworkspace pfeatworkspace = pworkspace
As ifeatureworkspace;
Ifeatureclass pfeatureclass = pfeatworkspace. openfeatureclass ("Basin: polygon ");
Personal Geodatabase
Geodatabase, as the native data format of ArcGIS, reflects the advantages of many third-generation geographic data models. Personal geodatabase is based on Microsoft Access integrated storage space data and attribute data. Enterprise geodatabase is implemented through large-scale relational databases + ArcSDE. As a middleware, ArcSDE converts normal tables in relational databases into spatial objects. The workspace of the personal Geodatabase data refers to the file with the MDB extension. The following code opens the Water element class in Monto. MDB.
Iworkspacefactory pfactory =
New accessworkspacefactoryclass ();
Iworkspace pworkspace = pfactory. openfromfile (@ "D:" arctutor "Monto. mdb ",
0 );
Ifeatureworkspace pfeatworkspace = pworkspace
As ifeatureworkspace;
Ifeatureclass pfeatureclass = pfeatworkspace. openfeatureclass ("water ")
Enterprise Geodatabase
The workspace corresponding to ArcSDE (Enterprise Geodatabase) is a database connection. When a relational database is an Oracle database, five connection parameters are required: Server, instance, user, password, and version. Server refers to the Host Name of the server, instance refers to the service name or port number, user is the username of the database, password database corresponds to the password of the user, version refers to a version in the enterprise Geodatabase multi-version mechanism, the default version is "SDE. default ", if the relational database is SQL
The database parameter is also required for the connection parameters. The following code opens the controlpoint element class in enterprise Geodatabase. The relational database is Oracle9i.
Iworkspacefactory pworkspacefactory =
New sdeworkspacefactoryclass ();
Ipropertyset propset =
New propertysetclass (); propset. setproperty ("server ",
"ACTC ");
Propset. setproperty ("instance ",
"5151"); propset. setproperty ("user ",
"Apdm ");
Propset. setproperty ("password ",
"Apdm"); propset. setproperty ("version ",
"SDE. Default ");
Iworkspace pworkspace = pworkspacefactory. Open (propset,
0 );
Ifeatureworkspace pfeatws = pworkspace
As ifeatureworkspace;
Ifeatureclass pfeatureclass = pfeatws. openfeatureclass ("controlpoint ");
Tin
Tin, also known as irregular triangle surface, uses a series of irregular triangle points to build the surface. For example, each sampling point has a pair of X, Y coordinates and a surface value (z value). These points are connected by the edges of a group of non-overlapping triangles to form a surface. Tin data is an important data format for spatial analysis and 3D analysis. It is stored on disks as files. The workspace of tin is located in the folder. The code below is to open the tin named Mal in the D: "arctutor" 3danalyst folder.
Iworkspacefactory pwsfact =
New tinworkspacefactoryclass ();
Iworkspace PWS = pwsfact. openfromfile (@ "D:" arctutor "3 danalyst "",
0 );
Itinworkspace ptinws = PWS as itinworkspace; itin ptin = ptinws. opentin ("Mal ");
Raster
Raster data is also an important part of GIS data. The most common file types in ArcGIS include grid, Tiff, and ERDAS image. The workspace of these raster data is also the folder. When you open raster data, you need to use the raster workspace factory, and then use the open raster dataset method of the irasterworkspace interface to open a raster dataset. When you enable the grid dataset, if the data format is ESRI grid, the parameter of the openrasterdataset () method is the name of the grid element set. If the data format is Tiff, the parameter of this method is the complete file name. TIF extension, such as openrasterdataset ("hillshade. TIF "). The following code opens grid-formatted raster data.
Iworkspacefactory rasterworkspacefactory =
New rasterworkspacefactoryclass ();
Irasterworkspace rasterworkspace = rasterworkspacefactory. openfromfile (@ "D:" data "Grid ",
0)
As irasterworkspace;
Irasterdataset rasterdataset = rasterworkspace. openrasterdataset ("ca_hillshade ");
CAD
CAD data can also be directly accessed through ao. The way to access CAD data is similar to coverage, but note that you need to use the CAD workspace factory. Below is a CAD data for opening a DXF, use "CAD file name: Element class name" when opening the element class. Note that the CAD file name must contain the extension. Otherwise, an error is returned. Run the following code to open the polygon element class in buildings. dxf in the d: "arctutor" Editor "exercisedata" editingfeatures folder.
Iworkspacefactory pcadwf =
New cadworkspacefactoryclass ();
Iworkspace PWS = pcadwf. openfromfile (@ "D:" arctutor "Editor" exercisedata "editingfeatures ",
0 );
Ifeatureworkspace pcadfws = PWS as ifeatureworkspace;
Ifeatureclass pfeatclass = pcadfws. openfeatureclass ("buildings. DXF: polygon ");
RDBMS
Generally, data in a relational table can be directly read through ArcGIS, which greatly facilitates data sharing. For non-spatial data in some businesses, by using OLE, you can easily access data. business data can be stored in various relational databases. The following code accesses the custom table in Microsoft Access, of course, you can also access data in oralce or SQL Server, as long as you change the following connection string (connectstring.
// Create a connection
Ipropertyset ppropset; ppropset =
New propertysetclass ();
Ppropset. setproperty ("connectstring ",
@ "Provider = Microsoft. Jet. oledb.4.0; Data Source = E:" company. mdb; persist Security info = false ");
// Create a new oledb workspace and open it
Iworkspacefactory pworkspacefact;
Ifeatureworkspace pfeatworkspace;
Pworkspacefact =
New oledbworkspacefactoryclass ();
Pfeatworkspace = pworkspacefact. Open (ppropset,
0)
As ifeatureworkspace;
Itable pttable = pfeatworkspace. OpenTable ("Custom ");
These are the most common data access methods for ArcGIS. when accessing data for GIS analysis, data processing, and spatial visualization, you can add the data to the layer after obtaining the data, you can also search or maintain data.