/// <summary> /// deletes a given version /// </summary> /// <param name="versname">version name</param> /// <param name="sdeConn">parent sde connection</param> /// <returns>true if success otherwise false</returns> public bool deleteSDEVersion(string versname, string sdeConn) { bool x = true; try { IWorkspace wks; IWorkspaceFactory wsFact; IPropertySet propSet; string parentVersion = null; if (sdeConn == null) { propSet = getProjectPS(); wsFact = new SdeWorkspaceFactoryClass(); wks = wsFact.Open(propSet, 0); } else { wks = OpenWorkSpace(sdeConn); propSet = wks.ConnectionProperties; wsFact = wks.WorkspaceFactory; } IVersionedWorkspace3 vwks = wks as IVersionedWorkspace3; IEnumVersionInfo eVinfo = vwks.Versions; IVersionInfo vinfo = eVinfo.Next(); IVersion version = null; while (vinfo != null) { string vName = vinfo.VersionName; if (vName.ToLower().EndsWith(versname.ToLower())) { parentVersion = vName; version = vwks.FindVersion(vName); break; } vinfo = eVinfo.Next(); } if (version != null) { version.Delete(); } else { Console.WriteLine("Error: Could not find Version"); x = false; } } catch(Exception e) { x = false; Console.WriteLine("Error: " + e.ToString()); } return x; }
// Handle exception and continue // executing. //*************************Raster Create End*************************** //**************************Raster Open Begin************************** //函数名: OpenRasterDatasetFromSDE //函数功能:在SDE中获得RasterDataset //参数: rasterDatasetName函数名。 //备注: //Libraries needed to run this code: //ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesGDB public IRasterDataset OpenRasterDatasetFromSDE(string server, string instance, string database, string user, string password, string rasterDatasetName, string version) { // Open an ArcSDE raster dataset with the given name // server, instance, database, user, password, version are database connection info // rasterDatasetName is the name of the raster dataset to be opened//Open the ArcSDE workspace 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); // cocreate the workspace factory IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); // Open the raster workspace using the previously defined porperty set and // QI to the desired IRasterWorkspaceEx interface to access the existing dataset IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.Open(propertySet, 0) as IRasterWorkspaceEx; //Open the ArcSDE raster dataset IRasterDataset rasterDataset = null; rasterDataset = rasterWorkspaceEx.OpenRasterDataset(rasterDatasetName); return(rasterDataset); }
//函数名:openSDEWorkspace //函数功能:create and open the sde workspace based on the provided information // public IWorkspace openSDEWorkspace(string Server, string Instance, string User, string Password, string Database, string version) { IWorkspace ws = null; try { IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", Server); pPropSet.SetProperty("INSTANCE", Instance); pPropSet.SetProperty("DATABASE", Database); pPropSet.SetProperty("USER", User); pPropSet.SetProperty("PASSWORD", Password); pPropSet.SetProperty("VERSION", version); ws = pSdeFact.Open(pPropSet, 0); return(ws); } catch { return(ws); //if (e is StackOverflowException || // e is OutOfMemoryException) // throw; } }
//直连 private void directConnect() { IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.Open(CreatePropertySet("", "sde:postgresql:192.168.0.40", "sde", "hy@123456", "sde.DEFAULT", "sde", true), 0); DebugInfo(pWorkspace); }
private IWorkspace CreateWorkspace() { try { IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("SERVER", this.Server); propertySet.SetProperty("INSTANCE", this.Instance); propertySet.SetProperty("DATABASE", this.Database); propertySet.SetProperty("USER", this.User); propertySet.SetProperty("PASSWORD", this.PassWord); propertySet.SetProperty("VERSION", this.Version); propertySet.SetProperty("AUTHENTICATION_MODE", this.Authentication_Mode); IWorkspace workspace = workspaceFactory.Open(propertySet, 0); return(workspace); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); } return(null); }
//根据连接字符串获取工作空间 //此处连接字符串是固定格式的连接串 Server|Service|Database|User|Password|Version private static IWorkspace GetWorkSpacefromConninfo(string conninfostr, int type) { if (conninfostr == "") { return(null); } if (type < 0) { return(null); } int index1 = conninfostr.IndexOf("|"); int index2 = conninfostr.IndexOf("|", index1 + 1); int index3 = conninfostr.IndexOf("|", index2 + 1); int index4 = conninfostr.IndexOf("|", index3 + 1); int index5 = conninfostr.IndexOf("|", index4 + 1); int index6 = conninfostr.IndexOf("|", index5 + 1); IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pWSFact = null; string sServer = ""; string sService = ""; string sDatabase = ""; string sUser = ""; string sPassword = ""; string strVersion = ""; switch (type) { case 1: //mdb pWSFact = new AccessWorkspaceFactoryClass(); sDatabase = conninfostr.Substring(index2 + 1, index3 - index2 - 1); break; case 2: //gdb pWSFact = new FileGDBWorkspaceFactoryClass(); sDatabase = conninfostr.Substring(index2 + 1, index3 - index2 - 1); break; case 3: //sde pWSFact = new SdeWorkspaceFactoryClass(); sServer = conninfostr.Substring(0, index1); sService = conninfostr.Substring(index1 + 1, index2 - index1 - 1); sDatabase = conninfostr.Substring(index2 + 1, index3 - index2 - 1); sUser = conninfostr.Substring(index3 + 1, index4 - index3 - 1); sPassword = conninfostr.Substring(index4 + 1, index5 - index4 - 1); strVersion = conninfostr.Substring(index5 + 1, index6 - index5 - 1); break; } pPropSet.SetProperty("SERVER", sServer); pPropSet.SetProperty("INSTANCE", sService); pPropSet.SetProperty("DATABASE", sDatabase); pPropSet.SetProperty("USER", sUser); pPropSet.SetProperty("PASSWORD", sPassword); pPropSet.SetProperty("VERSION", strVersion); try { IWorkspace pWorkspace = pWSFact.Open(pPropSet, 0); return(pWorkspace); } catch { return(null); } }
public object GetWorkspace(string strType, string strArgs) { IWorkspaceFactory wsf = null; IWorkspace m_SystemWorkspace = null; switch (strType) { case "PGDB": wsf = new AccessWorkspaceFactoryClass(); m_SystemWorkspace = wsf.OpenFromFile(strArgs, 0); break; case "FILEGDB": wsf = new ShapefileWorkspaceFactoryClass(); m_SystemWorkspace = wsf.OpenFromFile(strArgs, 0); break; case "SDE": IPropertySet pSet = new PropertySetClass(); string[] argList = strArgs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string strArg in argList) { string[] argPair = strArg.Split(new char[] { ':' }); pSet.SetProperty(argPair[0], argPair[1]); } wsf = new SdeWorkspaceFactoryClass(); m_SystemWorkspace = wsf.Open(pSet, 0); break; default: throw new Exception("系统Workspace配置了无法识别的数据库:Workspace类型应该在PGDB、FILEGDB和SDE之内"); } return(m_SystemWorkspace); }
private IWorkspace OpenSDEWorkspace(string server, string instance, string database, string user, string password, string version) { try { IPropertySet propSet = new PropertySetClass(); if (server.Trim() != string.Empty) { propSet.SetProperty("SERVER", server); } propSet.SetProperty("INSTANCE", instance); propSet.SetProperty("DATABASE", database); propSet.SetProperty("USER", user); propSet.SetProperty("PASSWORD", password); propSet.SetProperty("VERSION", version); IWorkspaceFactory wsf = new SdeWorkspaceFactoryClass(); return(wsf.Open(propSet, 0)); } catch (Exception e) { MessageBox.Show(e.Message); return(null); } }
/// <summary> /// 设置SDE工作区 /// </summary> /// <param name="sServer">服务器名</param> /// <param name="sService">服务名</param> /// <param name="sDatabase">数据库名(SQLServer)</param> /// <param name="sUser">用户名</param> /// <param name="sPassword">密码</param> /// <param name="strVersion">SDE版本</param> /// <returns>输出错误Exception</returns> public bool SetWorkspace(string sServer, string sService, string sDatabase, string sUser, string sPassword, string strVersion, out Exception eError) { eError = null; IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", sServer); pPropSet.SetProperty("INSTANCE", sService); pPropSet.SetProperty("DATABASE", sDatabase); pPropSet.SetProperty("USER", sUser); pPropSet.SetProperty("PASSWORD", sPassword); pPropSet.SetProperty("VERSION", strVersion); try { m_Workspace = pSdeFact.Open(pPropSet, 0); pPropSet = null; pSdeFact = null; m_connset = "SDE;" + sServer + "|" + sService + "|" + sDatabase + "|" + sUser + "|" + sPassword + "|" + strVersion; return(true); } catch (Exception eX) { return(false); } }
private void btnTestConnection_Click(object sender, EventArgs e) { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; IPropertySet connectionProperties = new PropertySetClass(); string str = this.txtServer.Text.Trim(); connectionProperties.SetProperty("SERVER", str); str = this.txtInstance.Text.Trim(); connectionProperties.SetProperty("INSTANCE", str); str = this.txtDatabase.Text.Trim(); if (str.Length >= 0) { connectionProperties.SetProperty("DATABASE", str); } str = this.txtUser.Text.Trim(); connectionProperties.SetProperty("USER", str); str = this.txtPassword.Text.Trim(); connectionProperties.SetProperty("PASSWORD", str); connectionProperties.SetProperty("VERSION", this.string_1); IWorkspaceFactory factory = new SdeWorkspaceFactoryClass(); try { factory.Open(connectionProperties, 0); this.bool_0 = true; this.btnTestConnection.Enabled = false; } catch (Exception exception) { MessageBox.Show(exception.Message); } System.Windows.Forms.Cursor.Current = Cursors.Default; }
private IWorkspace open_ArcSDE_Workspace(string server, string instance, string user, string password, string database, string version, out string serr) { try { ///IPropertySet接口提供对用于管理PropertySet的成员的访问。IPropertySet接口包含在PropertySet中设置和检索命名值对集合的方法。 ///PropertySet是一个通用类,用于保存任何东西的一组属性。使用属性集的一个示例是保存打开SDE工作空间所需的属性,如示例代码所示。 ///通常,属性集可以被认为是一组键(字符串)和值(变体/对象)。一个值得注意的例外是在XmlPropertySet对象上使用IPropertySet接口。 XML文档可以包含具有相同名称的多个元素(即“属性/子”)和不同的值。因此,此接口从XmlPropertySet返回的值可能是锯齿状的二维数组(包含其他数组的数组)。有关更多详细信息和代码示例,请参阅Geodatabase库中的XmlPropertySet coclass'文档。 IPropertySet connectionProperties = new PropertySetClass(); connectionProperties.SetProperty("SERVER", server); connectionProperties.SetProperty("INSTANCE", instance); connectionProperties.SetProperty("DATABASE", database); connectionProperties.SetProperty("USER", user); connectionProperties.SetProperty("PASSWORD", password); connectionProperties.SetProperty("VERSION", version); IWorkspaceFactory factory = new SdeWorkspaceFactoryClass(); IWorkspace workspace = factory.Open(connectionProperties, 0); serr = ""; return(workspace); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.WorkspaceFun", "open_ArcSDE_Workspace", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); serr = exception.Message; return(null); } }
/// <summary> /// 设置SDE工作区 /// </summary> /// <param name="sServer">服务器名</param> /// <param name="sService">服务名</param> /// <param name="sDatabase">数据库名(SQLServer)</param> /// <param name="sUser">用户名</param> /// <param name="sPassword">密码</param> /// <param name="strVersion">SDE版本</param> /// <returns>输出错误Exception</returns> private IWorkspace SetWorkspace(string sServer, string sService, string sDatabase, string sUser, string sPassword, string strVersion, out Exception eError) { eError = null; IWorkspace pWks = null; IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", sServer); pPropSet.SetProperty("INSTANCE", sService); pPropSet.SetProperty("DATABASE", sDatabase); pPropSet.SetProperty("USER", sUser); pPropSet.SetProperty("PASSWORD", sPassword); pPropSet.SetProperty("VERSION", strVersion); try { pWks = pSdeFact.Open(pPropSet, 0); pPropSet = null; pSdeFact = null; return(pWks); } catch (Exception eX) { eError = eX; return(null); } }
/// <summary> /// 如果是SDE库体则获取工作空间 /// </summary> /// <param name="propertySet">工作空间连接属性</param> public GOFuzingTables(IPropertySet propertySet) { IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass(); this._Workspace = pWorkspaceFactory.Open(propertySet, 0); this._TempleteWorkspace = OpenTempleteWorkSpace(); }
//基于服务的连接 private void baseOnSDE() { IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.Open(CreatePropertySet("192.168.0.40", "5151", "sde", "hy@123456", "sde.DEFAULT", "sde", false), 0); DebugInfo(pWorkspace); }
/// <summary> /// 获得所有SDE图层 /// </summary> private void GetAllSDELayer() { //SDE直接连接函数 IPropertySet propset = SDEDirectConnection(); //定义一个工作空间, 并实例化为SDE的工作空间类 IWorkspaceFactory workspaceFactroy = new SdeWorkspaceFactoryClass(); //打开SDE工作空间 IWorkspace workspace = workspaceFactroy.Open(propset, 0); //通过工作空间获取要素类,并存放在List<string>的泛型类中 List <string> listFeatureClass = GetFeatureClassByWorkspace(workspace); //定义个变量i,用来获取图层 int i = 0; //使用foreach循环来遍历listFeatureClass foreach (var item in listFeatureClass) { //将工作空间强转成要素工作空间 IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; //通过要素空间打开要素类并存放在要素类中 IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(item); //新建一个要素图层 IFeatureLayer featureLayer = new FeatureLayer(); //将要素类存放在刚定义好的要素图层的要素类中 featureLayer.FeatureClass = featureClass; //设置要素图层名字 featureLayer.Name = featureClass.AliasName; //axMapControl1增加图层 axMapControl1.AddLayer(featureLayer, i); //自增i i++; } //刷新axMapControl1 axMapControl1.Refresh(); }
public object GetWorkspace(string strType, string strArgs) { IWorkspaceFactory wsf = null; IWorkspace m_SystemWorkspace = null; switch (strType) { case "PGDB": wsf = new AccessWorkspaceFactoryClass(); m_SystemWorkspace = wsf.OpenFromFile(strArgs, 0); break; case "FILEGDB": wsf = new ShapefileWorkspaceFactoryClass(); m_SystemWorkspace = wsf.OpenFromFile(strArgs, 0); break; case "SDE": IPropertySet pSet = new PropertySetClass(); string[] argList = strArgs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string strArg in argList) { string[] argPair = strArg.Split(new char[] { ':' }); pSet.SetProperty(argPair[0], argPair[1]); } wsf = new SdeWorkspaceFactoryClass(); m_SystemWorkspace = wsf.Open(pSet, 0); break; default: throw new Exception("系统Workspace配置了无法识别的数据库:Workspace类型应该在PGDB、FILEGDB和SDE之内"); } return m_SystemWorkspace; }
public static IWorkspace connectToSDE() { IPropertySet pPropSet = new PropertySetClass(); pPropSet.SetProperty("Server", "techserver"); pPropSet.SetProperty("Instance", "esri_sde"); pPropSet.SetProperty("user", "sdedata"); pPropSet.SetProperty("password", "sdedata"); pPropSet.SetProperty("version", "sde.DEFAULT"); IWorkspaceFactory pFact; IWorkspace pWorkspace; //IFeatureWorkspace pFeatureWorkspace; try { pFact = new SdeWorkspaceFactoryClass(); pWorkspace = pFact.Open(pPropSet, 0); //pFeatureWorkspace=pWorkspace as IFeatureWorkspace; //pFeatureWorkspace.CreateTable("CJTEST",pFieldsEdit as IFields,null,null,""); return pWorkspace; } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } }
/// <summary> /// 设置SDE工作区 /// </summary> /// <param name="sServer">服务器名</param> /// <param name="sService">服务名</param> /// <param name="sDatabase">数据库名(SQLServer)</param> /// <param name="sUser">用户名</param> /// <param name="sPassword">密码</param> /// <param name="strVersion">SDE版本</param> /// <returns>输出错误Exception</returns> public IWorkspace SetWorkspace(string sServer, string sService, string sDatabase, string sUser, string sPassword, string strVersion) { //eError = null; IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", sServer); pPropSet.SetProperty("INSTANCE", sService); pPropSet.SetProperty("DATABASE", sDatabase); pPropSet.SetProperty("USER", sUser); pPropSet.SetProperty("PASSWORD", sPassword); pPropSet.SetProperty("VERSION", strVersion); try { return(pSdeFact.Open(pPropSet, 0)); } catch (Exception eX) { //******************************** //guozheng added system exception log //if (SysCommon.Log.Module.SysLog == null) // SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); //SysCommon.Log.Module.SysLog.Write(eX); //******************************** return(null); } }
private IWorkspace method_4() { IWorkspaceFactory factory = new SdeWorkspaceFactoryClass(); try { return(factory.Open(this.method_2(), 0)); } catch (Exception exception) { if (exception is COMException) { switch (((uint)(exception as COMException).ErrorCode)) { case 2147751273: case 2147751169: MessageBox.Show("连接数据库失败", "连接"); return(null); case 2147751274: MessageBox.Show("连接数据库失败\r\n该服务器上的SDE没有启动", "连接"); return(null); case 2147500037: MessageBox.Show("连接数据库失败", "连接"); return(null); } } Logger.Current.Error("", exception, ""); } return(null); }
//测试 private void buttonXTest_Click(object sender, EventArgs e) { if (cboDataType.Text == "SDE") { try {//Workspace IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new SdeWorkspaceFactoryClass(); //PropertySet IPropertySet pPropertySet; pPropertySet = new PropertySetClass(); //pPropertySet.SetProperty("Service", comboBoxDsName.Text); pPropertySet.SetProperty("Server", txtServer.Text); pPropertySet.SetProperty("Database", txtDataBase.Text); pPropertySet.SetProperty("Instance", "5151");//"port:" + txtService.Text pPropertySet.SetProperty("user", txtUser.Text); pPropertySet.SetProperty("password", txtPassWord.Text); pPropertySet.SetProperty("version", "sde.DEFAULT"); IWorkspace pws = pWorkspaceFactory.Open(pPropertySet, 0); MessageBox.Show("连接成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("连接失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (cboDataType.Text == "PDB") { if (txtServer.Text == "") { MessageBox.Show("服务器名为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspace pws = pWorkspaceFactory.OpenFromFile(txtServer.Text, 0); MessageBox.Show("连接成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("连接失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (cboDataType.Text == "GDB") { if (txtServer.Text == "") { MessageBox.Show("服务器名为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); IWorkspace pws = pWorkspaceFactory.OpenFromFile(txtServer.Text, 0); MessageBox.Show("连接成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("连接失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public static IFeatureClass GetFeatureInSde(IPropertySet properties, string featureClassName) { SdeWorkspaceFactory sdeWorkspaceFactory = new SdeWorkspaceFactoryClass(); var workspace = sdeWorkspaceFactory.Open(properties, 0); var fc = ((IFeatureWorkspace)workspace).OpenFeatureClass(featureClassName); return(fc); }
//not finished public static void BurstFindValves() { // run a FindPath between 2 flags, create a polyline from the results //需要desktop,放弃 /* * INetworkAnalysisExt pNetAnalysisExt; * INetworkAnalysisExtFlags pNetAnalysisExtFlags; * INetworkAnalysisExtBarriers pNetAnalysisExtBarriers; * INetworkAnalysisExtResults pNetAnalysisExtResults; */ string valvelayername = "Water Fixtures"; string waterlinelayername = "Water Lines"; string waternetworkname = "Water_Network"; INetworkCollection pNetworkCollection; IFeatureDataset pFeatureDataSet; IWorkspaceFactory pWSF = new SdeWorkspaceFactoryClass(); IPropertySet pPropset = new PropertySetClass(); IFeatureWorkspace pFeatureWorkspace = pWSF.Open(pPropset, 0) as IFeatureWorkspace; INetwork pNetwork; IGeometricNetwork pGeometricNetwork; pFeatureDataSet = pFeatureWorkspace.OpenFeatureDataset("datasetName"); pNetworkCollection = pFeatureDataSet as INetworkCollection; pGeometricNetwork = pNetworkCollection.get_GeometricNetworkByName("networkname"); pNetwork = pGeometricNetwork.Network; IEdgeFlagDisplay pEdgeFlagDisplay; IFlagDisplay pFlagDisplay; IEdgeFlag pEdgeFlag; INetFlag pNetFlag; //创建一个flag pEdgeFlag = new EdgeFlagClass(); pNetFlag = pEdgeFlag as INetFlag; IFeatureLayer pFeatLayerValves; IFeatureLayer pFeatLayerWaterLines; UID pID = new UIDClass(); }
public void ChangeHistoricalVersionByTimeStamp(IGraphicsContainer igraphicsContainer_0, IFeatureWorkspace ifeatureWorkspace_0, object object_0) { try { if ((((igraphicsContainer_0 != null) && (ifeatureWorkspace_0 != null)) && (object_0 != null)) && (ifeatureWorkspace_0 is IHistoricalWorkspace)) { object obj2; object obj3; (ifeatureWorkspace_0 as IWorkspace).ConnectionProperties.GetAllProperties(out obj2, out obj3); IPropertySet connectionProperties = new PropertySetClass(); for (int i = 0; i < ((System.Array)obj2).Length; i++) { switch (((System.Array)obj2).GetValue(i).ToString().ToUpper()) { case "SERVER": connectionProperties.SetProperty("SERVER", ((System.Array)obj3).GetValue(i)); break; case "INSTANCE": connectionProperties.SetProperty("INSTANCE", ((System.Array)obj3).GetValue(i)); break; case "DATABASE": connectionProperties.SetProperty("DATABASE", ((System.Array)obj3).GetValue(i)); break; case "USER": connectionProperties.SetProperty("USER", ((System.Array)obj3).GetValue(i)); break; case "PASSWORD": connectionProperties.SetProperty("PASSWORD", ((System.Array)obj3).GetValue(i)); break; case "AUTHENTICATION_MODE": connectionProperties.SetProperty("AUTHENTICATION_MODE", ((System.Array)obj3).GetValue(i)); break; } } connectionProperties.SetProperty("HISTORICAL_TIMESTAMP", object_0); connectionProperties.GetAllProperties(out obj2, out obj3); IWorkspaceFactory factory = new SdeWorkspaceFactoryClass(); IWorkspace workspace = factory.Open(connectionProperties, 0); if (workspace != null) { workspace.ConnectionProperties.GetAllProperties(out obj2, out obj3); this.ChangeVersion(igraphicsContainer_0, ifeatureWorkspace_0, workspace as IFeatureWorkspace); } } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="propertySet">保存的连接设置</param> /// <param name="DBType">目标的类型(PDB、SDE、GDB)</param> /// <param name="pDesProperty">目标的连接设置</param> public GOFuzingSpatialTables(IPropertySet propertySet, string DBType, IPropertySet pDesProperty) { this._DesDBType = DBType; this._PropertySet = pDesProperty; IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass(); this._Workspace = pWorkspaceFactory.Open(propertySet, 0); this._TempleteWorkspace = OpenTempleteWorkSpace(); }
public static IWorkspace GetSdeWorkspace(object psObj) { var dic = (Dictionary <string, object>)psObj; var ps = dic.ToPropertySet(); SdeWorkspaceFactory wf = new SdeWorkspaceFactoryClass(); var ws = wf.Open(ps, 0); return(ws); }
private void listProjects_SelectedIndexChanged(object sender, EventArgs e) { // Need to clear the versions when selected this.listVersions.DataSource = null; string selectedProject = null; try { selectedProject = (string)this.listProjects.SelectedValue; } catch { return; } if (selectedProject == null) { return; } // Prompt the user to select a version. Open the database IPropertySet connectionProperties = new PropertySetClass(); connectionProperties.SetProperty("SERVER", "malachite\\azgsgeodatabases"); connectionProperties.SetProperty("INSTANCE", "sde:sqlserver:malachite\\azgsgeodatabases"); connectionProperties.SetProperty("DATABASE", selectedProject); connectionProperties.SetProperty("AUTHENTICATION_MODE", "OSA"); connectionProperties.SetProperty("VERSION", "dbo.Default"); IWorkspaceFactory wsFact = new SdeWorkspaceFactoryClass(); IVersionedWorkspace vWs = (IVersionedWorkspace)wsFact.Open(connectionProperties, 0); // Build a DataTable to bind to the listbox control DataTable verTable = new DataTable(); DataColumn verName = new DataColumn(); verName.ColumnName = "VersionName"; verName.DataType = typeof(string); verTable.Columns.Add(verName); IEnumVersionInfo theseVersions = vWs.Versions; IVersionInfo aVersion = theseVersions.Next(); while (aVersion != null) { string thisVersionName = (string)aVersion.VersionName; string[] Split = thisVersionName.Split(new char[] { '.' }); verTable.Rows.Add(Split[1]); aVersion = theseVersions.Next(); } this.listVersions.DataSource = verTable; this.listVersions.DisplayMember = "VersionName"; this.listVersions.ValueMember = "VersionName"; }
/// <summary> /// 打开Workspace /// </summary> /// <param name="wsType"></param> /// <param name="objWorkspace">当为SDE时使用IPropertySet,其余情况使用路径(string)</param> /// <returns></returns> public static IWorkspace OpenWorkspace(enumWorkspaceType wsType, object objWorkspace) { IWorkspaceFactory wsf = null; try { switch (wsType) { case enumWorkspaceType.FileGDB: wsf = new FileGDBWorkspaceFactoryClass(); return(wsf.OpenFromFile(objWorkspace as string, 0)); case enumWorkspaceType.PGDB: wsf = new AccessWorkspaceFactoryClass(); return(wsf.OpenFromFile(objWorkspace as string, 0)); case enumWorkspaceType.File: wsf = new ShapefileWorkspaceFactoryClass(); return(wsf.OpenFromFile(objWorkspace as string, 0)); case enumWorkspaceType.SDE: wsf = new SdeWorkspaceFactoryClass(); IPropertySet pSet = objWorkspace as IPropertySet; if (pSet == null) { string strArgs = objWorkspace as string; pSet = new PropertySetClass(); string[] argList = strArgs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string strArg in argList) { string[] argPair = strArg.Split(new char[] { '=' }); pSet.SetProperty(argPair[0], argPair[1]); } } return(wsf.Open(pSet, 0)); } } catch { return(null); } finally { if (wsf != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(wsf); } } return(null); }
private void ReadSDEWorkspaceFactory(string path, string server, string instance, string user, string password, string version) { IPropertySet set = new PropertySetClass(); set.SetProperty("Server", server); set.SetProperty("Instance", instance); set.SetProperty("User", user); set.SetProperty("password", password); set.SetProperty("version", version); Wsf = new SdeWorkspaceFactoryClass(); Wsf.Open(set, 0); FeatWs = Ws as IFeatureWorkspace; }
//not finished public static void BurstFindValves() { // run a FindPath between 2 flags, create a polyline from the results //��Ҫdesktop������ /* INetworkAnalysisExt pNetAnalysisExt; INetworkAnalysisExtFlags pNetAnalysisExtFlags; INetworkAnalysisExtBarriers pNetAnalysisExtBarriers; INetworkAnalysisExtResults pNetAnalysisExtResults; */ string valvelayername = "Water Fixtures"; string waterlinelayername = "Water Lines"; string waternetworkname = "Water_Network"; INetworkCollection pNetworkCollection; IFeatureDataset pFeatureDataSet; IWorkspaceFactory pWSF=new SdeWorkspaceFactoryClass(); IPropertySet pPropset=new PropertySetClass(); IFeatureWorkspace pFeatureWorkspace=pWSF.Open(pPropset,0) as IFeatureWorkspace; INetwork pNetwork; IGeometricNetwork pGeometricNetwork; pFeatureDataSet = pFeatureWorkspace.OpenFeatureDataset("datasetName"); pNetworkCollection=pFeatureDataSet as INetworkCollection; pGeometricNetwork=pNetworkCollection.get_GeometricNetworkByName("networkname"); pNetwork=pGeometricNetwork.Network; IEdgeFlagDisplay pEdgeFlagDisplay; IFlagDisplay pFlagDisplay; IEdgeFlag pEdgeFlag; INetFlag pNetFlag; //����һ��flag pEdgeFlag=new EdgeFlagClass(); pNetFlag=pEdgeFlag as INetFlag; IFeatureLayer pFeatLayerValves; IFeatureLayer pFeatLayerWaterLines; UID pID=new UIDClass(); }
/// <summary> /// 通过连接属性新建数据连接 /// </summary> /// <param name="connectionPropertySet"></param> /// <returns></returns> private IWorkspace GetWorkspace(IPropertySet connectionPropertySet) { IWorkspaceFactory pSdeWorkspaceFactory = new SdeWorkspaceFactoryClass(); try { return(pSdeWorkspaceFactory.Open(connectionPropertySet, 0)); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(null); }
private IWorkspace method_4() { IWorkspaceFactory factory = new SdeWorkspaceFactoryClass(); try { return(factory.Open(this.method_2(), 0)); } catch (Exception exception) { MessageBox.Show(exception.Message); } return(null); }
public static IWorkspace OpenFissureWorkspace() { string connectionFile = @"C:\Users\username\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\EarthFissures.sde"; // Read in the database connection properties from config.txt //string[] lines = System.IO.File.ReadAllLines(@"../../config.txt"); string path = @"C:\tmp\config.txt"; string cfg = ""; if (File.Exists(path)) { try { string[] lines = System.IO.File.ReadAllLines(path); Dictionary <string, string> dbConn = new Dictionary <string, string>(); foreach (string line in lines) { dbConn.Add(line.Split('=')[0], line.Split('=')[1]); cfg = cfg + " \n " + line; } if (dbConn["dbfile"].Length > 0) { connectionFile = dbConn["dbfile"]; IWorkspaceFactory wsFact2 = new SdeWorkspaceFactoryClass(); return(wsFact2.OpenFromFile(connectionFile, 0)); } else { IWorkspaceFactory wsFact = new SdeWorkspaceFactoryClass(); IPropertySet connectionProperties = new PropertySetClass(); connectionProperties.SetProperty("SERVER", dbConn["server"]); connectionProperties.SetProperty("INSTANCE", dbConn["instance"]); connectionProperties.SetProperty("DATABASE", dbConn["database"]); connectionProperties.SetProperty("AUTHENTICATION_MODE", dbConn["authentication_mode"]); connectionProperties.SetProperty("VERSION", dbConn["version"]); return(wsFact.Open(connectionProperties, 0)); } } catch (Exception ex) { MessageBox.Show("Cannot Connect to Fissure Database - Check your config.txt file " + cfg); return(null); } } else { return(null); } }
public IWorkspace SDEWorkspace(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)); }
public static IWorkspace openSDEWorkspace(string Server, string Instance, string User, string Password, string Database, string version) { IWorkspace ws = null; IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", Server); pPropSet.SetProperty("INSTANCE", Instance); pPropSet.SetProperty("DATABASE", Database); pPropSet.SetProperty("USER", User); pPropSet.SetProperty("PASSWORD", Password); pPropSet.SetProperty("VERSION", version); ws = pSdeFact.Open(pPropSet, 0); return(ws); }
public azgsSqlDatabaseChooser() { InitializeComponent(); // Populate the listbox // Build a DataTable to bind to the listbox control DataTable projectTable = new DataTable(); DataColumn projName = new DataColumn(); projName.ColumnName = "ProjectName"; projName.DataType = typeof(string); DataColumn dbName = new DataColumn(); dbName.ColumnName = "DatabaseName"; dbName.DataType = typeof(string); projectTable.Columns.Add(projName); projectTable.Columns.Add(dbName); // Populate the DataTable - Right now this is pinging a DB on malachite IPropertySet connectionProperties = new PropertySetClass(); connectionProperties.SetProperty("SERVER", "malachite\\azgsgeodatabases"); connectionProperties.SetProperty("INSTANCE", "sde:sqlserver:malachite\\azgsgeodatabases"); connectionProperties.SetProperty("DATABASE", "AzgsIndex"); connectionProperties.SetProperty("AUTHENTICATION_MODE", "OSA"); connectionProperties.SetProperty("VERSION", "dbo.Default"); try { IWorkspaceFactory wsFact = new SdeWorkspaceFactoryClass(); IWorkspace theWs = wsFact.Open(connectionProperties, 0); // Open the table in the repository database ITable ProjectListingsTable = commonFunctions.OpenTable(theWs, "ProjectDatabases"); // Get all the records into a sorted cursor ITableSort projSorter = new TableSortClass(); projSorter.Table = ProjectListingsTable; projSorter.QueryFilter = null; projSorter.Fields = "ProjectName"; projSorter.set_Ascending("ProjectName", true); projSorter.Sort(null); ICursor projCur = projSorter.Rows; //ProjectListingsTable.Search(null, false); // Loop through the cursor and add records to the DataTable IRow projRow = projCur.NextRow(); while (projRow != null) { projectTable.Rows.Add((String)projRow.get_Value(ProjectListingsTable.FindField("ProjectName")), (String)projRow.get_Value(ProjectListingsTable.FindField("DatabaseName"))); projRow = projCur.NextRow(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(projCur); // Bind the DataTable to the control this.listProjects.DataSource = projectTable; this.listProjects.DisplayMember = "ProjectName"; this.listProjects.ValueMember = "DatabaseName"; this.listProjects.SelectedItem = null; this.listVersions.DataSource = null; } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace); return; } }
/// <summary> /// Open a table class from an SDE Workspace /// </summary> /// <param name="conFilePath">string path to the SDE connection file</param> /// <param name="tabName">Table class name</param> /// <param name="fdsName">Optional name of feature dataset</param> /// <param name="versionName">Optional version name, defaults to the version specified by the connection file</param> /// <returns></returns> public static ITable openTableFromSDE(string conFilePath, string tabName, string fdsName = "", string versionName = "") { ITable table = null; IWorkspaceFactory factory = new SdeWorkspaceFactoryClass(); IPropertySet props = factory.ReadConnectionPropertiesFromFile(conFilePath); if (versionName != "") { props.SetProperty("VERSION", versionName); } IWorkspace workspace = factory.Open(props, 0); IFeatureWorkspace featWorkspace = (IFeatureWorkspace)workspace; if (fdsName != "") { IFeatureDataset featdataset = featWorkspace.OpenFeatureDataset(fdsName); IFeatureWorkspace datasetWorkspace = (IFeatureWorkspace)featdataset.Workspace; table = datasetWorkspace.OpenTable(tabName); } else { table = featWorkspace.OpenTable(tabName); } return table; }
//Open SDE RasterCatalog // Libraries needed to run the code: // ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, and ESRI.ArcGIS.DataSourcesGDB public IRasterCatalog OpenSDERasCata(string server, string instance, string database, string user, string password, string rasterCatalogName, string version) { // Open an ArcSDE raster Catalog with the given name // server, instance, database, user, password, version are database connection info // rasterCatalogName is the name of the raster Catalog //Open the ArcSDE workspace 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); // cocreate the workspace factory IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); // Open the raster workspace using the previously defined porperty set // and QI to the desired IRasterWorkspaceEx interface to access the existing catalog IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.Open(propertySet, 0) as IRasterWorkspaceEx; //Open the ArcSDE raster Catalog IRasterCatalog rasterCatalog = null; rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName); return rasterCatalog; }
public static IWorkspace GetSDEWorkspace(string sServerName, string sInstancePort, string sUserName, string sPassword, string sVersionName) { IPropertySet set = new PropertySetClass(); set.SetProperty("Server", sServerName); set.SetProperty("Instance", sInstancePort); set.SetProperty("User", sUserName); set.SetProperty("password", sPassword); set.SetProperty("version", sVersionName); SdeWorkspaceFactoryClass class2 = new SdeWorkspaceFactoryClass(); try { return class2.Open(set, 0); } catch (Exception ex) { return null; } }
/// <summary> /// Conecta a uma workspace SDE /// </summary> private void OpenSdeWorkspace() { var factory = new SdeWorkspaceFactoryClass(); IPropertySet set = new PropertySet(); set.SetProperty("server", _server); set.SetProperty("instance", _instance); set.SetProperty("user", _user); set.SetProperty("version", _version); set.SetProperty("password", _password); try { workspace = factory.Open(set, 0); isOpened = true; } catch (Exception e) { isOpened = false; throw new InvalidOperationException(string.Format("Error to connected in SDE: {0}", e.Message), e); } }
void Button5Click(object sender, EventArgs e) { string waarde, SQL, naam, status, map; int nummer; IEnvelope env; IActiveView pActiveView; IPoint punt; IMap pMap; PropertySet pPropertySet; IWorkspaceFactory pSdeFact; IWorkspace pWorkspace; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; IFeatureClass pFeatureClass; ESRI.ArcGIS.Catalog.IGxLayer pGxLayer; ESRI.ArcGIS.Catalog.IGxFile pGxFile; double minx, miny, maxx, maxy; if (listBox1.SelectedIndex == -1) { MessageBox.Show("Selecteer eerst een dataset uit de lijst.", "Foutmelding"); return; } try { this.Cursor = Cursors.WaitCursor; naam = ""; status = ""; nummer = listBox1.SelectedIndex; waarde = listBox1.Items[nummer].ToString(); SQL = "SELECT NAAM, FYSIEKE_LOCATIE FROM DATASET WHERE DATASET_TITEL = '" + waarde + "'"; mycommand = new OleDbCommand (SQL, mydb); OleDbDataReader myreader = mycommand.ExecuteReader(); try { while (myreader.Read()) { naam = myreader.GetString(0).ToString(); status = myreader.GetString(1).ToString(); } } catch (Exception ex){ MessageBox.Show (ex.ToString(), "Foutmelding"); this.Cursor = Cursors.Default; } finally { myreader.Close(); } map = layer + status + "\\" + naam + ".lyr"; try{ if (System.IO.File.Exists(@map)) { pActiveView = hookHelper.ActiveView; env = pActiveView.Extent; punt = env.LowerLeft; minx = punt.X; miny = punt.Y; punt = env.UpperRight; maxx = punt.X; maxy = punt.Y; pGxLayer = new ESRI.ArcGIS.Catalog.GxLayerClass(); pGxFile = (ESRI.ArcGIS.Catalog.IGxFile)pGxLayer; pGxFile.Path = map; pMap = hookHelper.FocusMap; pMap.AddLayer(pGxLayer.Layer); pActiveView.Extent.XMin = minx; pActiveView.Extent.XMax = maxx; pActiveView.Extent.YMin = miny; pActiveView.Extent.YMax = maxy; pActiveView.Refresh(); this.Cursor = Cursors.Default; } else { MessageBox.Show("Er is geen opmaakbestand van de geselecteerde dataset aanwezig. De dataset wordt nu zonder opmaak uit de geo-database gehaald.","Informatie"); SQL = "SELECT ALT_TITEL FROM DATASET WHERE DATASET_TITEL = '" + waarde + "'"; mycommand = new OleDbCommand (SQL, mydb); OleDbDataReader myreader1 = mycommand.ExecuteReader(); try { while (myreader1.Read()) { pActiveView = hookHelper.ActiveView; pPropertySet = new PropertySetClass(); pPropertySet.SetProperty("SERVER", "chios"); pPropertySet.SetProperty("INSTANCE", "5151"); pPropertySet.SetProperty("DATABASE", ""); pPropertySet.SetProperty("USER", "gisuser"); pPropertySet.SetProperty("PASSWORD", "zonnetje"); pPropertySet.SetProperty("VERSION", "SDE.DEFAULT"); env = pActiveView.Extent; punt = env.LowerLeft; minx = punt.X; miny = punt.Y; punt = env.UpperRight; maxx = punt.X; maxy = punt.Y; pSdeFact = new SdeWorkspaceFactoryClass(); pWorkspace = pSdeFact.Open(pPropertySet, 0); pFeatureWorkspace = pWorkspace as IFeatureWorkspace; pFeatureClass = pFeatureWorkspace.OpenFeatureClass(myreader1.GetString(0).ToString()); pMap = hookHelper.FocusMap; pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureClass; pFeatureLayer.Name = pFeatureClass.AliasName; pFeatureLayer.Visible = true; pFeatureLayer.Selectable = true; pMap.AddLayer(pFeatureLayer); pActiveView.Extent.XMin = minx; pActiveView.Extent.XMax = maxx; pActiveView.Extent.YMin = miny; pActiveView.Extent.YMax = maxy; pActiveView.Refresh(); this.Cursor = Cursors.Default; } } catch (Exception ex){ MessageBox.Show (ex.ToString(), "Foutmelding"); this.Cursor = Cursors.Default; } finally { myreader.Close(); } } } catch (Exception ex) { MessageBox.Show (ex.ToString(), "Foutmelding"); this.Cursor = Cursors.Default; } } catch { MessageBox.Show("Er is geen PDF voor deze dataset aanwezig.", "Foutmelding"); this.Cursor = Cursors.Default; } }
/// <summary> /// gets all version on a sde database /// </summary> /// <param name="sdeConn">sde connection</param> /// <returns>array of version info</returns> public IVersionInfo[] getVersionsInfo(string sdeConn) { List<IVersionInfo> vers = new List<IVersionInfo>(); IWorkspace wks; if (sdeConn != null) { wks = OpenWorkSpace(sdeConn); } else { IPropertySet propSet = getProjectPS(); IWorkspaceFactory wkFact = new SdeWorkspaceFactoryClass(); wks = wkFact.Open(propSet, 0); } IVersionedWorkspace3 vwks = wks as IVersionedWorkspace3; IEnumVersionInfo vEnumInfo = vwks.Versions; IVersionInfo vInfo = vEnumInfo.Next(); while (vInfo != null) { vers.Add(vInfo); vInfo = vEnumInfo.Next(); } return vers.ToArray(); }
/// <summary> /// Creates a SDE version on production database partent version is Project /// </summary> /// <param name="outfl">connection file</param> /// <param name="versname">verison name</param> /// <param name="sdeConn">sdeConneciton</param> /// <returns>new conneciton file</returns> public string createSDEVersion(string outfl,string versname,string sdeConn) { string x = null; try { IWorkspace wks; IWorkspaceFactory wsFact; IPropertySet propSet; string parentVersion = null; if (sdeConn == null) { propSet = getProjectPS(); wsFact = new SdeWorkspaceFactoryClass(); wks = wsFact.Open(propSet, 0); } else { Console.WriteLine("Creating version connection location = " + sdeConn); wks = OpenWorkSpace(sdeConn); propSet = wks.ConnectionProperties; wsFact = wks.WorkspaceFactory; } IVersionedWorkspace3 vwks = wks as IVersionedWorkspace3; IEnumVersionInfo eVinfo = vwks.Versions; IVersionInfo vinfo = eVinfo.Next(); IVersion version = null; while (vinfo != null) { string vName = vinfo.VersionName; if (vName.ToLower().EndsWith(propSet.GetProperty("VERSION").ToString().ToLower())) { parentVersion = vName; version = vwks.FindVersion(vName); break; } vinfo = eVinfo.Next(); } if (versionExist(versname, sdeConn)) { Console.WriteLine("Error: Version " + versname + " already exists"); return null; } IVersion cversion = version.CreateVersion(versname); IWorkspace wks2 = (IWorkspace)cversion; wsFact.Create(System.IO.Path.GetDirectoryName(outfl), System.IO.Path.GetFileName(outfl), wks2.ConnectionProperties,0); x = outfl; } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); x = null; } return x; }
/// <summary> /// 打开Workspace /// </summary> /// <param name="wsType"></param> /// <param name="objWorkspace">当为SDE时使用IPropertySet,其余情况使用路径(string)</param> /// <returns></returns> public static IWorkspace OpenWorkspace(enumWorkspaceType wsType, object objWorkspace) { IWorkspaceFactory wsf = null; try { switch (wsType) { case enumWorkspaceType.FileGDB: wsf = new FileGDBWorkspaceFactoryClass(); return wsf.OpenFromFile(objWorkspace as string, 0); case enumWorkspaceType.PGDB: wsf = new AccessWorkspaceFactoryClass(); return wsf.OpenFromFile(objWorkspace as string, 0); case enumWorkspaceType.File: wsf = new ShapefileWorkspaceFactoryClass(); return wsf.OpenFromFile(objWorkspace as string, 0); case enumWorkspaceType.SDE: wsf = new SdeWorkspaceFactoryClass(); IPropertySet pSet = objWorkspace as IPropertySet; if (pSet == null) { string strArgs = objWorkspace as string; pSet = new PropertySetClass(); string[] argList = strArgs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string strArg in argList) { string[] argPair = strArg.Split(new char[] { '=' }); pSet.SetProperty(argPair[0], argPair[1]); } } return wsf.Open(pSet, 0); } } catch { return null; } finally { if (wsf != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(wsf); } return null; }
//添加字段end public void connectSDE() { ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("server", "42.96.131.137"); propertySet.SetProperty("instance", "sde:oracle11g:orcl");//这个隐藏的很深 propertySet.SetProperty("database", "orcl");//数据库名称 propertySet.SetProperty("user", "sys"); propertySet.SetProperty("password", "iswift638187"); propertySet.SetProperty("version", "SDE.DEFAULT"); SdeWorkspaceFactory sdeWkspFact = new SdeWorkspaceFactoryClass(); IFeatureWorkspace pFeaWksp = (IFeatureWorkspace)sdeWkspFact.Open(propertySet, 0); IFeatureClass pFCRoads = pFeaWksp.OpenFeatureClass("point"); IFeatureLayer pFLRoads = new FeatureLayer(); pFLRoads.FeatureClass = pFCRoads; pFLRoads.Name = "点"; ILayer pLayerRoads = pFLRoads as ILayer; Global.mainmap.AddLayer(pLayerRoads); }
public IWorkspace CreateWorkspaceSDE(string server, string instance, string database, string version, string user, string password) { IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); IPropertySet propertySet = new PropertySetClass(); //create version for editting //TnUtilities utilities = new TnUtilities(); IWorkspace workspace = null; //utilities.StartService("esri_sde", 2000); propertySet.SetProperty("SERVER", server); propertySet.SetProperty("INSTANCE", instance); propertySet.SetProperty("DATABASE", database); propertySet.SetProperty("VERSION", version); propertySet.SetProperty("USER", user); propertySet.SetProperty("PASSWORD", password); //if (authentication_mode != "OSA" && authentication_mode != "osa") //{ // propertySet.SetProperty("USER", user); // propertySet.SetProperty("PASSWORD", password); //} //else if (authentication_mode == "OSA" || authentication_mode == "osa") //{ // propertySet.SetProperty("AUTHENTICATION_MODE", authentication_mode); //} //else //{ // MessageBox.Show("Chua xac dinh duoc Authentication_mode"); //} //if (version == "sde.DEFAULT") //{ // Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"); // workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); //} //if (version == "dbo.DEFAULT") //{ // propertySet.SetProperty("VERSION", version); //} //else //{ Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"); workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); //} try { workspace = workspaceFactory.Open(propertySet, 0); } catch (Exception ex){MessageBox.Show(string.Format("line 94 WorkspaceManagement:\n {0}",ex)); } //if (workspace.IsBeingEdited() != true) //{ // workspaceEdit.StartEditing(true); // workspaceEdit.StartEditOperation(); //} return workspace; }
//��������openSDEWorkspace //�������ܣ�create and open the sde workspace based on the provided information // public IWorkspace openSDEWorkspace(string Server, string Instance, string User, string Password, string Database, string version) { IWorkspace ws = null; try { IPropertySet pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", Server); pPropSet.SetProperty("INSTANCE", Instance); pPropSet.SetProperty("DATABASE", Database); pPropSet.SetProperty("USER", User); pPropSet.SetProperty("PASSWORD", Password); pPropSet.SetProperty("VERSION", version); ws = pSdeFact.Open(pPropSet, 0); return ws; } catch { return ws; //if (e is StackOverflowException || // e is OutOfMemoryException) // throw; } }
//点选查询 /* public static void PointQuery(int x,int y) { AxMapControl axMap=pMainFrm.getMapControl(); IIdentify pIdentify=null; IArray pIDArray=null; IFeatureIdentifyObj pFeatIdObj=null; IIdentifyObj pIdObj=null; IDisplayTransformation pDT=axMap.ActiveView.ScreenDisplay.DisplayTransformation; IPoint pPoint=pDT.ToMapPoint(x,y); IEnvelope pEnv=pPoint.Envelope; pEnv.Expand((pDT.VisibleBounds.Width/(4*Screen.FromPoint(pPoint as IPoint))), (pDT.VisibleBounds.Height/(4*Screen.FromPoint(pPoint as IPoint))),false); for(int i=0;i<axMap.LayerCount-1;i++) { pIdentify=axMap.get_Layer(i); pIDArray=pIdentify.Identify(pEnv); if(pIDArray!=null) { for(int j=0;j<pIDArray.Count-1;j++) { pFeatIdObj=pIDArray.get_Element(j); pIdObj=pFeatIdObj as IIdentifyObj; IRowIdentifyObject pRowObj=pFeatIdObj as IRowIdentifyObject; IFeature pFeature=pRowObj.Row; } } } SelectedFeature[] pSelectedFeature=new SelectedFeature[i]; } */ public static IWorkspace connectToSDE(){ IPropertySet pPropSet=new PropertySetClass(); pPropSet.SetProperty("Server","techserver" ); pPropSet.SetProperty("Instance","esri_sde" ); pPropSet.SetProperty("user","sdedata" ); pPropSet.SetProperty("password","sdedata" ); pPropSet.SetProperty("version","sde.DEFAULT" ); IWorkspaceFactory pFact; IWorkspace pWorkspace; IFeatureWorkspace pFeatureWorkspace; /* IFields pFields=new FieldsClass(); IFieldsEdit pFieldsEdit=pFields as IFieldsEdit; IField pField1=new FieldClass(); IFieldEdit pFieldEdit=pField1 as IFieldEdit; pFieldEdit.Name_2="test1"; pFieldEdit.Type_2=esriFieldType.esriFieldTypeInteger; pFieldsEdit.AddField(pFieldEdit); */ try { pFact=new SdeWorkspaceFactoryClass(); pWorkspace=pFact.Open(pPropSet,0); //pFeatureWorkspace=pWorkspace as IFeatureWorkspace; //pFeatureWorkspace.CreateTable("CJTEST",pFieldsEdit as IFields,null,null,""); return pWorkspace; } catch(Exception ex){ Console.WriteLine(ex.Message); return null; } }
private static IWorkspace arcSDEWorkspaceOpen(string server, string instance, string user, string password, string database, string version) { IPropertySet pPropertySet = new PropertySetClass(); pPropertySet.SetProperty("SERVER", server); pPropertySet.SetProperty("INSTANCE", instance); pPropertySet.SetProperty("USER", user); pPropertySet.SetProperty("PASSWORD", password); pPropertySet.SetProperty("DATABASE", database); pPropertySet.SetProperty("VERSION", version); IWorkspaceFactory2 pWorkspaceFactory = new SdeWorkspaceFactoryClass(); IWorkspace workspace = null; try { workspace = pWorkspaceFactory.Open(pPropertySet, 0); } catch (Exception ex) { Console.WriteLine("连接Sde时发生错误:" + ex.Message); return null; } return workspace; }