zoukankan      html  css  js  c++  java
  • 生成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:\XXXXXX\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();
                }
                
                
                
                
                
                
                
                
                
                
  • 相关阅读:
    图的建立的两种方法(领接矩阵,领接表)
    蛇形填数
    谁买单,猴子选大王等类似题目不同解法!!!
    根据前序中序写后序(正确写法)
    月份牌
    子网掩码
    android 之 surfaceView和普通View的重绘使用
    android 之 Toast通知的使用
    viewSub惰性装载器
    对文件进行加密
  • 原文地址:https://www.cnblogs.com/liuyongpingblog/p/9082411.html
Copyright © 2011-2022 走看看