生成sde
Posted 随笔`
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成sde相关的知识,希望对你有一定的参考价值。
/// <summary> ///获取保存的SDE文件 /// </summary> /// <param name="sdePath"></param> /// <returns></returns> public static bool SaveSdeConnectionFile(string sdePath) { try { // 如果已经存在了,则删除了重新创建 if (File.Exists(sdePath)) { File.Delete(sdePath); } IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); // 创建.sde文件 IWorkspaceName workspaceName = workspaceFactory.Create(Path.GetDirectoryName(sdePath), Path.GetFileNameWithoutExtension(sdePath), InitFromSdeConfig(), 0); // 使用.sde文件,通过.sde文件获取IWorkspace,之后就可以对数据库中的数据进行操作了 // IWorkspace pWorkspace = workspaceFactory.OpenFromFile(sdePath, 0); return true; } catch (Exception e) { Console.WriteLine(e); } return false; } //获取sde连接串 private static IPropertySet InitFromSdeConfig() { string strFilePath = AppConfig.SdeConfig; if (!File.Exists(strFilePath)) return null; //读XML XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(strFilePath); string txtServer = "", txtService = "", txtUserId = "", txtPassword = ""; string type = ""; try { XmlNode nodeSde = xmldoc.SelectSingleNode("SDE"); //SDE信息 txtServer = nodeSde.SelectSingleNode("Server").InnerText; txtService = nodeSde.SelectSingleNode("Service").InnerText; type = nodeSde.SelectSingleNode("Type").InnerText; txtUserId = nodeSde.SelectSingleNode("User").InnerText; txtPassword = nodeSde.SelectSingleNode("Pass").InnerText; } catch { } IPropertySet mPPropSet = new PropertySetClass(); //string strIsDerect = comboBoxEditType.SelectedIndex.ToString(); //设置SDE连接属性信息:直连或非直连 if (type == "0") { mPPropSet.SetProperty("SERVER", txtServer); mPPropSet.SetProperty("INSTANCE", txtService); //mPPropSet.SetProperty("Database", ""); mPPropSet.SetProperty("AUTHENTICATION_MODE", "DBMS"); mPPropSet.SetProperty("User", txtUserId); mPPropSet.SetProperty("password", txtPassword); mPPropSet.SetProperty("version", "SDE.DEFAULT"); } else if (type == "1") { mPPropSet.SetProperty("INSTANCE", txtService); mPPropSet.SetProperty("User", txtUserId); mPPropSet.SetProperty("password", txtPassword); mPPropSet.SetProperty("version", "SDE.DEFAULT"); } _dbConnName = txtService; return mPPropSet; } private static string GetSdeConn() { string sdeconn = AppConfig.SdeConnString; if (SdeDbUtil.SaveSdeConnectionFile(sdeconn)) { return sdeconn; } return ""; } //调用执行代码 //如果polyFeatureName的参数为空字符串,则直接进行数据的拷贝工作 //关于SDE要素的连接字符串描述参见:pFieldMappings.AddTable(“C:\\XXX\XXX\\Connection to XXX.sde\\" + pFeatureClass.FeatureDataset.Name + "\\" + pFeatureClass.AliasName) http://blog.sina.com.cn/s/blog_5d25ac4e0100uhob.html //将分析的数据保存到GDB数据库中 string srcFeatureClassPath = ""; string srcOutPath = ""; string resFeatureOutPath; string sdeFile = GetSdeConn(); if (string.IsNullOrEmpty(sdeFile)) { MessageBoxHelper.ShowMessageBox("无法获取成果库的连接!"); return ""; } if (!string.IsNullOrEmpty(pntFeaturnName)) { string srcDbPath = string.Format(@"{0}\{1}", sdeFile, pntFeaturnName); string outName = string.IsNullOrEmpty(outFeatureName) ? pntFeaturnName : outFeatureName; srcOutPath = string.Format(@"{0}\{1}", CurrentWorkGdbPath, AnalysisResHelper.GetAnalysisTempName(outName)); GPSelectFeaturesCore selectFeaturesCorePnt = new GPSelectFeaturesCore(); selectFeaturesCorePnt.InputFeatures = srcDbPath; selectFeaturesCorePnt.OutputFeatureClass = srcOutPath; selectFeaturesCorePnt.WhereClause = pntFilterCondition; selectFeaturesCorePnt.DoAnalysis(); }
以上是关于生成sde的主要内容,如果未能解决你的问题,请参考以下文章