连接workspace的几种方法
1.Connecting to a personal geodatabase workspace stored in Access
The workspace factory required to connect to a personal geodatabase is an AccessWorkspaceFactory.
For local database workspaces, the IWorkspaceFactory.Open method usually requires a property set with a single property named DATABASE, the value of which should be the path to the workspace (including the filename).
例:
// For example, database = "C:\\myData\\mypGDB.mdb". public IWorkspace AccessWorkspaceFromPropertySet(string database)
{ IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("DATABASE", database); IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); return workspaceFactory.Open(propertySet, 0);
}
The OpenFromFile method for personal geodatabases requires the path name of the .mdb file that stores the Access database.
// For example, path = "C:\\myData\\mypGDB.mdb". public IWorkspace AccessWorkspaceFromPath(string path) { IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); return workspaceFactory.OpenFromFile(path, 0); }
2.Connecting to a file geodatabase workspace
// For example, database = "C:\\myData\\myfGDB.gdb". public IWorkspace FileGdbWorkspaceFromPropertySet(string database) { IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("DATABASE", database); IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); return workspaceFactory.Open(propertySet, 0); }
// For example, path = "C:\\myData\\myfGDB.gdb". public IWorkspace FileGdbWorkspaceFromPath(String path) { IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); return workspaceFactory.OpenFromFile(path, 0); }
3.Connecting to an enterprise ArcSDE geodatabase workspace
- SERVER—The SDE server being connected to.
- INSTANCE—The instance being connected to.
- DATABASE—The database being connected to. The DATABASE property is optional and is required for ArcSDE instances that manage multiple databases (for example, SQL Server).
- USER—The connected user.
- PASSWORD—The connected user's password.
- VERSION—The transactional version to connect to. The acceptable value is a string that represents a transaction version name.
In the following code example, a property set is populated from supplied strings to make a connection to an ArcSDE geodatabase workspace with a transactional version.
The property set is then used by the Open method to return a workspace. This approach involves the most code; however, it can be customized into a general function for connecting to ArcSDE databases based on supplied parameters rom the user.
// For example, server = "Kona". // Database = "SDE" or "" if Oracle. // Instance = "5151". // User = "vtest". // Password = "go". // Version = "SDE.DEFAULT". public IWorkspace VersionedArcSdeWorkspace(string server, string instance, string user, string password, string database, string version) { IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("SERVER", server); propertySet.SetProperty("INSTANCE", instance); propertySet.SetProperty("DATABASE", database); propertySet.SetProperty("USER", user); propertySet.SetProperty("PASSWORD", password); propertySet.SetProperty("VERSION", version);
IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); return workspaceFactory.Open(propertySet, 0); }
Resource:ms-help://ESRI.EDNv9.3/NET_Engine/c778d2bb-eb36-4793-9c89-20795811c5eb.htm
浙公网安备 33010602011771号