IWorkspaceFactory Create Example创建个人mdb、file_mdb、sde

来源:互联网 发布:淘宝情侣链接是什么 编辑:程序博客网 时间:2024/06/13 19:47
ArcObjects Library Reference  (GeoDatabase) 

IWorkspaceFactory Create Example

[C#]

    //IWorkspaceFactory Create Example

    public void IWorkspaceFactory_Create_Example_Access()    {        // create a new Access workspace factory        IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();        // Create a workspacename with the workspace factory        IWorkspaceName workspaceName = workspaceFactory.Create("C:\\temp\\", "MyNewpGDB.mdb", null, 0);        // Cast for IName        ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)workspaceName;        //Open a reference to the access workspace through the name object        IWorkspace pGDB_workspace = (IWorkspace)name.Open();

        Console.WriteLine("Current path of the {0} is {1}", pGDB_workspace.Type, pGDB_workspace.PathName);         }

    public void IWorkspaceFactory_Create_Example_FileGDB()    {        // create a new FileGDB workspace factory        IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();        // Create a workspacename with the workspace factory        IWorkspaceName workspaceName = workspaceFactory.Create("C:\\temp\\", "MyNewFileGDB.gdb", null, 0);        // Cast for IName        ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)workspaceName;        //Open a reference to the FileGDB workspace through the name object        IWorkspace fileGDB_workspace = (IWorkspace)name.Open();

        Console.WriteLine("Current path of the {0} is {1}", fileGDB_workspace.Type, fileGDB_workspace.PathName);    }

 

    public void IWorkspaceFactory_Create_Example_ArcSDE()    {        ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();        propertySet.SetProperty("Server", "testserver");        propertySet.SetProperty("Instance", "5151");        propertySet.SetProperty("Database", "sde"); //Ignored with ArcSDE for Oracle        propertySet.SetProperty("user", "sde");        propertySet.SetProperty("password", "go");        propertySet.SetProperty("version", "sde.DEFAULT");

        // create a new ArcSDE workspace factory        IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();        // Create a workspacename with the workspace factory        IWorkspaceName workspaceName = workspaceFactory.Create("C:\\temp\\", "MyNewArcSDE_Connection.sde",propertySet, 0);        // Cast for IName        ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)workspaceName;        //Open a reference to the FileGDB workspace through the name object        IWorkspace sde_workspace = (IWorkspace)name.Open();        //the path returned in this case will be for the sde connection        Console.WriteLine("Current path of the {0} is {1}", sde_workspace.Type, sde_workspace.PathName);    }

 转自:http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabase/IWorkspaceFactory_Create_Example.htm
原创粉丝点击