How to create new geodatabases-workspace

This article explains how to create several types of geodatabases, including personal, file, personal and workgroup ArcSDE, scratch (two types), and in-memory. It also describes how to create a connection file to an ArcSDE geodatabase, and how to create a shapefile workspace.

 

About workspaces
A workspace is a container of spatial and nonspatial datasets such as feature classes, raster datasets, and tables. It provides methods to instantiate existing datasets and to create new datasets. The following are the three types of workspaces:

  • Shapefiles and ArcInfo workspaces are examples of esriFileSystemWorkspaces.
  • A personal geodatabase stored in a Microsoft® Access or a file geodatabase is an example of esriLocalDatabaseWorkspace.
  • An ArcSDE geodatabase stored in a relational database management system (RDBMS), such as Oracle®, DB2®, SQL Server™, or Informix® is an example of an esriRemoteDatabaseWorkspace. 

To create a workspace, an appropriate workspace factory must be created. Each workspace type has its own workspace factory. A workspace factory is a dispenser of workspaces and allows a client to create a workspace specified by the directory, file name, and connection properties. A workspace factory is a cocreatable singleton object—a singleton object can only be instantiated once in a process. The workspace factory classes for geodatabase workspaces are found in the DataSourcesGDB library.
 
The Create method can be used to create a new esriFileSystemWorkspace, esriLocalDatabaseWorkspace, or a connection file to an esriRemoteDatabaseWorkspace. The optional connectionProperties parameter specifies any additional connection properties needed, such as the server, instance, and so on.

In the case where a connection file to an ArcSDE geodatabase is being created—if no connection properties are specified—a dialog box appears prompting the user for the required properties. The hWnd parameter tells the Create method the control or dialog box to use.
 
The Create method returns an IWorkspaceName object that can be used to open or return certain information about the workspace. The Create method cannot be used to create new geodatabases in an Enterprise, Personal, or Workgroup ArcSDE.

 (在GeoDatabase中Workspace對象就相當于一個地理數據庫,它里面包含著數據集對象,要素類,要素數據集,屬性表等等。由于GeoDatabase模型是使用統一方法來管理數據的,因此,對于不同方式的存儲的數據,除了獲得Workspace的方法不同外,其他操作方式是一樣的。

 

Creating a personal geodatabase workspace stored in Access

The workspace factory required to create a personal geodatabase is an AccessWorkspaceFactory. The following code example creates a new personal geodatabase in the specified directory with the supplied name. The connectionProperties parameter is null as it is not required for the creation of a personal geodatabase.
Code

 

Creating a file geodatabase workspace
The code required to create a file geodatabase is almost identical to the code for creating a personal geodatabase. Both are local database workspaces, but as stated previously, a different type of workspace factory - the FileGDBWorkspaceFactory - is required. Additionally, the extension used on the database will be different; for a file geodatabase, the extension is .gdb.
 
The following code example creates a new file geodatabase in the specified directory with the supplied name, then shows how to connect to it. The connectionProperties parameter is null as it is not required for the creation of a file geodatabase.

Code

 

Creating a connection file (.sde) to an Enterprise ArcSDE workspace
When used in conjunction with an ArcSDE workspace, the Create method does not create the geodatabase. Instead, it creates an SDE connection file.
 
There are two different procedures used to create an ArcSDE geodatabase. One is used for creating ArcSDE personal and workgroup geodatabases. The other is used to create ArcSDE Enterprise geodatabases. ArcSDE Enterprise geodatabases are stored using separate database management system (DBMS) products. Therefore, before creating the ArcSDE geodatabase system tables and your data tables, the underlying DBMS must be set up. The specifics of this vary based on the type of DBMS being used; consult the DBMS documentation for setup information.
 
The following code example demonstrates how to use the Create method to make an ArcSDE connection file to an ArcSDE geodatabase:

Code

 

Creating a geodatabase in a personal or workgroup ArcSDE workspace
The DataServerManager is used to access and administer one or more geodatabases stored on a data server. A connection can also be opened to each geodatabase in a data server by using the IWorkspaceName and IName interfaces. The following code example shows how to connect to a geodatabase stored in a data server for a personal or workgroup ArcSDE using the DataServerManager.
 
Creating a geodatabase in a personal or workgroup ArcSDE workspace creates new databases on a SQL Server Express database instance. Only ArcSDE database server administrators can create new ArcSDE Personal or Workgroup geodatabases.

Code

 

 Creating a shapefile workspace
A ShapefileWorkspaceFactory is used to create a folder in which shapefiles can be created.  As opposed to the geodatabase workspace factories, which create geodatabases or connection files, the ShapefileWorkspaceFactory does not create a shapefile. Instead, it creates a folder or workspace for shapefiles. The following code example demonstrates how to create a shapefile workspace:

Code

 

Creating a scratch workspace
The ScratchWorkspaceFactory and FileGDBScratchWorkspaceFactory classes are used to connect to a temporary database stored in Microsoft Access or in a file geodatabase, known as a scratch workspace. These workspaces are commonly used to hold the results of a selection set or to hold the results of an analysis operation. These factories are fundamentally different from the AccessWorkspaceFactory or FileGDBWorkspaceFactory classes, and the manner in they are used is different:
First, the factories implement scratch workspace-specific interfaces (IScratchWorkspaceFactory and IScratchWorkspaceFactory2) for creating new temporary workspaces or connect to existing temporary workspaces.
Second, when the last reference to a scratch workspace is released, the workspace is automatically deleted from the disk. Whereas personal and file geodatabase workspaces are created much less often than they're connected to, scratch workspaces are created and connected to in the same session.
 
The FileGDBScratchWorkspaceFactory and ScratchWorkspaceFactory classes are used in a similar fashion, but scratch workspaces based on file geodatabases can take advantage of their cross-platform nature and can handle larger amounts of data.
 
The following code example shows how to use the current scratch workspace to store a selection set (this example uses an Access-based scratch workspace):

Code

 

The following code example shows how to get the current scratch workspace to use as part of a selection, using a file geodatabase:
Code

 

 Creating an InMemory workspace
An InMemoryWorkspaceFactoryis used to create a temporary workspace that is stored in memory. These workspaces are commonly used to hold the results of an analysis operation or to hold objects in memory before persisting them to disk. When the last reference to the workspace is released, the workspace is destroyed and the memory released.
 
Feature classes contained in InMemory workspaces support the full geodatabase model. They can be used in conjunction with cursors, selections, and so on.  However, InMemory workspaces do not support all aspects of the geodatabase model; advanced datasets such as topology and geometric networks are not supported. The following code example shows how to create and open an InMemory workspace:

Code

 

posted on 2009-06-22 12:37  炜升  阅读(615)  评论(0编辑  收藏  举报