|
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. • Shapefile • Coverage • Personal Geodatabase • Enterprise Geodatabase • Tin • Raster • CAD • 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 has shielded the coverage editing function since ArcGIS 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 the 'coverage name when opening a specific element class: 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 Server, the Database parameter is required for the connection parameter. 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', '123 '); 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 following code opens the TIN named mal in the D: \ ArcTutor \ 3DAnalyst folder. IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass (); IWorkspace pWS = pWSFact. OpenFromFile (@ 'd: \ ArcTutor \ 3DAnalyst \ ', 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, when you open a feature class, use 'cad file name: feature class name'. 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 ('string string', @ 'provider = Microsoft. Jet. OLEDB.4.0; Data Source = E: \ Company. mdbl \ ersist 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. |