实现根据字符串获取InMemory内存工作空间
private static InMemoryDataSource _instance = null;
// 获取实例互斥锁
private static readonly object _getInstanceMutexLocker = new object();
private InMemoryDataSource() { }
public static InMemoryDataSource CreateSingleton() {
if (_instance != null) return _instance;
lock (_getInstanceMutexLocker) {
if (_instance == null) _instance = new InMemoryDataSource();
}
return _instance;
}
public IWorkspace OpenWorkspace(string workspaceDataSourceString) {
IWorkspace workspace = null;
IWorkspaceFactory2 workspaceFactory = WorkspaceFactoryWrapper.GetWorkspaceFactory(
"esriDataSourcesGDB.InMemoryWorkspaceFactory") as IWorkspaceFactory2;
try {
IWorkspaceName workspaceName = workspaceFactory.Create("", "InMemoryWorkspace", null, 0);
workspace = (workspaceName as IName).Open() as IWorkspace;
}
catch (Exception ex) {
throw ex;
}
return workspace;
}
public IWorkspace OpenWorkspace(string workspaceDataSourceString, bool createIfNotExist) {
return OpenWorkspace(workspaceDataSourceString);
}
public IWorkspace CreateWorkspace(string workspaceDataSourceString) {
return OpenWorkspace(workspaceDataSourceString);
}