Exemplo n.º 1
0
 /// <summary>
 /// 加载Access文件
 /// </summary>
 /// <param name="axMapControl">地图控件引用</param>
 /// <param name="strFilePath">文件路径</param>
 /// <returns>正常:“”,异常:异常字符;</returns>
 private SystemErrorType LoadAccessFile(ref AxMapControl axMapControl, string strFilePath)
 {
     if (strFilePath == "")
     {
         return(SystemErrorType.enumFilePathIsNull);
     }
     try
     {
         //声明区域,创建工作空间并遍历数据集
         IWorkspaceFactory pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
         IFeatureWorkspace pFeatureWorkspace       = null;
         IWorkspace        pWorkspace   = pAccessWorkspaceFactory.OpenFromFile(strFilePath, 0);
         IEnumDataset      pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTAny);
         pEnumDataset.Reset();
         IDataset pDataset = pEnumDataset.Next();
         //如果数据集是IFeatureDataset则遍历它下面的子集
         if (pDataset is IFeatureDataset)
         {
             pFeatureWorkspace = pAccessWorkspaceFactory.OpenFromFile(strFilePath, 0) as IFeatureWorkspace;
             IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
             IEnumDataset    pEnumDataset1   = pFeatureDataset.Subsets;
             pEnumDataset1.Reset();
             IDataset pDataset1 = pEnumDataset1.Next();
             //如果子类是FeatureClass,则添加到地图控件中
             if (pDataset1 is IFeatureClass)
             {
                 IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
                 pFeatureLayer.Name         = pFeatureLayer.FeatureClass.AliasName;
                 axMapControl.ClearLayers();
                 axMapControl.Map.AddLayer(pFeatureLayer);
                 axMapControl.ActiveView.Refresh();
             }
             else
             {
                 return(SystemErrorType.enumDataIsIllegal);
             }
         }
         else
         {
             return(SystemErrorType.enumDataIsIllegal);
         }
     }
     catch (Exception)
     {
         return(SystemErrorType.enumArcObjectHandleError);
     }
     return(SystemErrorType.enumOK);
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            string PDBPath = mdbPath();

            if (PDBPath != "")
            {
                IWorkspaceFactory pWSFactory = new AccessWorkspaceFactoryClass();

                IWorkspace pWS = pWSFactory.OpenFromFile(PDBPath, 0);

                IEnumDataset pEDataset = pWS.get_Datasets(esriDatasetType.esriDTAny);

                IDataset pDataset = pEDataset.Next();
                comboBox1.Items.Clear();

                while (pDataset != null)
                {
                    if (pDataset.Type == esriDatasetType.esriDTFeatureClass)
                    {
                        comboBox1.Items.Add(pDataset.Name);
                    }
                    pDataset = pEDataset.Next();
                }
                comboBox1.Text = comboBox1.Items[0].ToString();
            }
        }
Exemplo n.º 4
0
        private void Add_Tables()
        {
            IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IWorkspace        pWorkspace        = (IWorkspace)pWorkspaceFactory.OpenFromFile(@"C:\Users\mgh\Desktop\Data\GDB_DneshgaheAzad.mdb", 0);
            IEnumDataset      pEnumDataset      = pWorkspace.get_Datasets(esriDatasetType.esriDTTable);
            IDataset          pDataset          = pEnumDataset.Next();

            m_ArrayTables = new ArrayList();

            while (pDataset != null)
            {
                if (pDataset is ITable)
                {
                    cboLayerAttributeTable.Items.Add(pDataset.Name);
                    cboLayerGraph.Items.Add(pDataset.Name);
                    m_ArrayTables.Add(pDataset);
                }
                pDataset = pEnumDataset.Next();
            }
            if (cboLayerAttributeTable.Items.Count > 0)
            {
                cboLayerAttributeTable.SelectedIndex = 0;
            }
            if (cboLayerGraph.Items.Count > 0)
            {
                cboLayerGraph.SelectedIndex = 0;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 添加个人地理数据库
        /// </summary>
        public void addDataSet()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Title       = "请选择地理数据文件";
            openFileDialog1.Filter      = "个人数据库(*.mdb)|*.mdb";//设置过滤属性
            openFileDialog1.Multiselect = false;
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;                                             //未选择文件return
            }
            string            fileName  = openFileDialog1.FileName; //获取到文件路径
            string            pFolder   = System.IO.Path.GetDirectoryName(fileName);
            string            pFileName = System.IO.Path.GetFileName(fileName);
            IWorkspaceFactory wsf       = new AccessWorkspaceFactoryClass();//打开数据库
            IWorkspace        ws        = wsf.OpenFromFile(fileName, 0);

            if (ws != null)
            {
                MessageBox.Show("个人数据库" + pFileName + "打开成功!");
                addDataSetMap(ws);
            }
            else
            {
                MessageBox.Show("个人数据库" + pFileName + "打开失败!");
            }
        }
Exemplo n.º 6
0
 public bool CompactPersonalGeodatabase(string sPGDBFile)
 {
     try
     {
         if (string.IsNullOrEmpty(sPGDBFile) | !File.Exists(sPGDBFile))
         {
             MessageBox.Show("数据文件 " + sPGDBFile + " 丢失。", "压缩数据错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         bool flag = false;
         IWorkspaceFactory factory = null;
         factory = new AccessWorkspaceFactoryClass();
         IWorkspace workspace = null;
         workspace = factory.OpenFromFile(sPGDBFile, 0);
         if ((workspace != null) && (workspace is IDatabaseCompact))
         {
             IDatabaseCompact compact = null;
             compact = workspace as IDatabaseCompact;
             if (compact.CanCompact())
             {
                 compact.Compact();
                 flag = true;
             }
         }
         workspace = null;
         factory   = null;
         return(flag);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.WorkspaceFun", "CompactPersonalGeodatabase", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 打开mdb
        /// </summary>
        /// <param name="pGDBName"></param>
        /// <returns></returns>
        public static ESRI.ArcGIS.Geodatabase.IWorkspace GetMDBWorkspace(String _pGDBName)
        {
            IWorkspaceFactory pWsFac = new AccessWorkspaceFactoryClass();
            IWorkspace        pWs    = pWsFac.OpenFromFile(_pGDBName, 0);

            return(pWs);
        }
Exemplo n.º 8
0
        public void LoadDB()
        {
            try
            {
                openFileDialog1            = new OpenFileDialog();
                openFileDialog1.Title      = "Browse mdb Files";
                openFileDialog1.DefaultExt = "mdb";
                openFileDialog1.Filter     = "mdb Diles (*.mdb)|*.mdb";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    DBPath = openFileDialog1.FileName;;
                }

                IWorkspaceFactory AccessWorkSpace = new AccessWorkspaceFactoryClass();
                IWorkspace        MyWorkSpace     = AccessWorkSpace.OpenFromFile(DBPath, 0);
                IFeatureWorkspace featWorkspace   = MyWorkSpace as IFeatureWorkspace;

                IEnumDataset AllLayerFromDB = MyWorkSpace.get_Datasets(esriDatasetType.esriDTFeatureClass);
                IDataset     SingleLayer    = AllLayerFromDB.Next();
                while (SingleLayer != null)
                {
                    string LayerText = SingleLayer.Name;
                    comboBox12.Items.Add(LayerText);
                    SingleLayer = AllLayerFromDB.Next();
                }
                comboBox12.Text = comboBox12.Items[0].ToString();
            }
            catch
            {
            }
        }
Exemplo n.º 9
0
        private void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //打开目标数据库
            IWorkspaceFactory pAccessWorkspaceFactory;

            pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IWorkspace        fWorkspace    = pAccessWorkspaceFactory.OpenFromFile("E://2018年工作//数据验收平台测试//test.gdb", 0);
            IFeatureWorkspace fW            = fWorkspace as IFeatureWorkspace;
            IEnumDataset      penumDatasets = fWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);

            penumDatasets.Reset();
            IDataset pesriDataset = penumDatasets.Next();

            while (pesriDataset == null)
            {
                IFeatureClass pFeatureClass = fW.OpenFeatureClass("Ⅰ级保护林地范围");
            }
            //启动编辑
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)fWorkspace;

            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
            //调用创建拓朴的方法
            ITopology topology = Create_Topology(fW, "datset", "Ⅰ级保护林地范围", "Polygon_Topo");

            //停止编辑
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            if (topology != null)
            {
                MessageBox.Show("创建拓朴成功!");
            }
        }
Exemplo n.º 10
0
        public void ExportToMDB(string name, string outputPath)
        {
            IWorkspaceFactory wsFct      = new AccessWorkspaceFactoryClass();
            IWorkspace        pWorkspace = (IWorkspace)wsFct.OpenFromFile(outputPath, 0);

            ConvertFeatureClassToGDB(this.m_workSpace, pWorkspace, name, name, null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Converts string to Workspace
        /// </summary>
        /// <param name="s">The connection string  for geodatabase</param>
        /// <returns>geodatabase IWorkspace </returns>
        public static IWorkspace ToWorkspace(this string s)
        {
            IWorkspace workspace = null;

            try
            {
                if (s.EndsWith("sde", StringComparison.CurrentCultureIgnoreCase))
                {
                    IWorkspaceFactory factory = new SdeWorkspaceFactoryClass();
                    workspace = factory.OpenFromFile(s, 0);
                }
                else if (s.EndsWith("gdb", StringComparison.CurrentCultureIgnoreCase))
                {
                    IWorkspaceFactory factory = new FileGDBWorkspaceFactoryClass();
                    workspace = factory.OpenFromFile(s, 0);
                }
                else if (s.EndsWith("mdb", StringComparison.CurrentCultureIgnoreCase))
                {
                    IWorkspaceFactory factory = new AccessWorkspaceFactoryClass();
                    workspace = factory.OpenFromFile(s, 0);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }

            return(workspace);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 获取GDB或MDB工作空间
        /// </summary>
        /// <param name="path">gdb或mdb数据库路径</param>
        /// <returns>gdb或mdb工作空间</returns>
        public static IWorkspace GetWorkspace(String path)
        {
            IWorkspaceFactory workspaceFactory;
            IWorkspace        workspace = null;

            try
            {
                if (path.EndsWith(".gdb"))
                {
                    workspaceFactory = new FileGDBWorkspaceFactoryClass();
                    workspace        = workspaceFactory.OpenFromFile(path, 0);
                }
                else if (path.EndsWith(".mdb"))
                {
                    workspaceFactory = new AccessWorkspaceFactoryClass();
                    workspace        = workspaceFactory.OpenFromFile(path, 0);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接到地理空间数据库失败:\r\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(workspace);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 作用:打开mdb文件并获取workspace
        /// 作者:汪建龙
        /// 编写时间:2017年4月11日15:39:36
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static IWorkspace OpenAccessFileWorkSpace(this string filePath)
        {
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(filePath, 0);

            return(workspace);
        }
Exemplo n.º 14
0
        private void btnSetDataSourcePath_Click(object sender, EventArgs e)
        {
            string sDir = Application.StartupPath;

            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.InitialDirectory = sDir + @"\..\Result\";
            openFileDialog.Filter           = "mdb|*.mdb";
            openFileDialog.Title            = "请选择数据库";

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string strFileName = openFileDialog.FileName;

            IDataLayer   pDataLayer          = (IDataLayer)m_FeaLay;
            IName        pName               = pDataLayer.DataSourceName;
            IDatasetName pDatasetName        = pName as IDatasetName;
            string       strFeatureClassName = pDatasetName.Name;

            IWorkspaceFactory pFact      = new AccessWorkspaceFactoryClass();
            IWorkspace        pWorkspace = pFact.OpenFromFile(strFileName, 0);
            IFeatureWorkspace pFeatws    = pWorkspace as IFeatureWorkspace;
            IFeatureClass     pFeatcls   = pFeatws.OpenFeatureClass(strFeatureClassName);

            m_FeaLay.FeatureClass = pFeatcls;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Converts  the spatialite table to a featureclass in a temporary, scratch workspace.
        /// </summary>
        /// <returns>IFeatureClass copy of the spatialite table</returns>
        public IFeatureClass ConvertToFeatureclass()
        {
            try
            {
                CreateTemporaryGeodatabase();

                IWorkspaceFactory factory   = new AccessWorkspaceFactoryClass();
                IWorkspace        workspace = factory.OpenFromFile(this.PGDBPath, 0);

                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

                IFields fields = CreateFields();

                // Use IFieldChecker to create a validated fields collection.
                IFieldChecker   fieldChecker    = new FieldCheckerClass();
                IEnumFieldError enumFieldError  = null;
                IFields         validatedFields = null;
                fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(this.TableName, validatedFields,
                                                                                 null, null, esriFeatureType.esriFTSimple, "Shape", "");

                LoadFeatureclass(featureClass);

                return(featureClass);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }
Exemplo n.º 16
0
        public void AddLayer(string LayerName)
        {
            IMap FocusedMap = axMapControl1.ActiveView.FocusMap;
            IWorkspaceFactory AccessWorkSpace    = new AccessWorkspaceFactoryClass();
            IWorkspace        MyWorkSpace        = AccessWorkSpace.OpenFromFile(DBPath, 0);
            IFeatureWorkspace FeatureOfWorkSpace = MyWorkSpace as IFeatureWorkspace;
            IFeatureClass     FeatureClassOfLayer;


            try
            {
                FeatureClassOfLayer = FeatureOfWorkSpace.OpenFeatureClass(LayerName);
                IFeatureLayer LayerToBeAdded = new FeatureLayerClass();
                LayerToBeAdded.FeatureClass = FeatureClassOfLayer;
                LayerToBeAdded.Name         = LayerName;
                LayerToBeAdded.ShowTips     = true;
                FocusedMap.AddLayer(LayerToBeAdded);
                FocusedMap.MoveLayer(LayerToBeAdded, 2);



                if (!checkedListBox1.Items.Contains(LayerName))
                {
                    checkedListBox1.Items.Add(LayerName);
                    checkedListBox1.SetItemChecked(checkedListBox1.Items.Count - 1, true);
                    comboBox3.Items.Add(LayerName);
                    comboBox2.Items.Add(LayerName);
                    comboBox8.Items.Add(LayerName);
                }
            }
            catch
            {
            }
        }
Exemplo n.º 17
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                IWorkspaceFactory wfactory  = new AccessWorkspaceFactoryClass();
                IWorkspace        ws        = wfactory.OpenFromFile(textBox3.Text, 0); //makan el database
                IFeatureWorkspace fws       = ws as IFeatureWorkspace;
                IFeatureClass     featclass = fws.OpenFeatureClass(comboBox3.SelectedItem.ToString());
                IFeatureLayer     featLayer = new FeatureLayerClass();
                featLayer.FeatureClass = featclass;
                featLayer.Name         = comboBox3.SelectedItem.ToString();
                mdoc.get_Map(comboBox1.SelectedIndex).AddLayer(featLayer);
                IMap map = mdoc.get_Map(comboBox1.SelectedIndex);
                axMapControl1.Map = map;
                axMapControl1.Refresh();

                checkedListBox1.Items.Clear();
                comboBox2.Items.Clear();
                IEnumLayer allLayers = map.get_Layers();
                ILayer     layer     = allLayers.Next();
                while (layer != null)
                {
                    checkedListBox1.Items.Add(layer.Name);
                    comboBox2.Items.Add(layer.Name);
                    layer = allLayers.Next();
                }
                for (int d = 0; d < checkedListBox1.Items.Count; d++)
                {
                    checkedListBox1.SetItemChecked(d, true);
                }
            }
            catch
            {
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 打开MDB工作空间
 /// </summary>
 /// <param name="strFilePath"></param>
 /// <returns></returns>
 public static IWorkspace OpenMdbWorspace(string strFilePath)
 {
     if (strFilePath == string.Empty)
     {
         LOG.Error("参数strFilePath不能为空");
         throw new Exception("参数strFilePath不能为空");
     }
     try
     {
         IWorkspaceFactory2 pWrksFactory = new AccessWorkspaceFactoryClass();
         //int index = strFilePath.LastIndexOf('\\');
         //string strDic = strFilePath.Substring(0, index);
         //string strName = strFilePath.Substring(index + 1, strFilePath.Length - index - 1);
         //IWorkspaceName pWrkspsName = pWrksFactory.Create(strDic, strName, null, 0);
         //IWorkspace pWrksps = ((IName)pWrkspsName).Open() as IWorkspace;
         return(pWrksFactory.OpenFromFile(strFilePath, 0));
         //return pWrksps;
     }
     catch (Exception ex)
     {
         LOG.Error("mdb工作空间打开失败,详情:" + ex.Message);
         // Console.WriteLine("创建mdb工作空间失败,详情:" + ex.Message);
         return(null);
     }
 }
Exemplo n.º 19
0
        //读取mdb数据
        public List <ILayer> ReadLayerFromAccess(List <string> filePathList)
        {
            List <ILayer> layerList = new List <ILayer>();

            if (filePathList.Count == 0)
            {
                return(null);
            }
            else
            {
                foreach (string path in filePathList)
                {
                    IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
                    IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(path, 0);
                    IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

                    IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset;
                    pEnumDataset.Reset();
                    IDataset pDataset = pEnumDataset.Next();

                    while (pDataset is IFeatureClass)
                    {
                        IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                        pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
                        pFeatureLayer.Name         = pDataset.Name;
                        ILayer pLayer = pFeatureLayer as ILayer;
                        layerList.Add(pFeatureLayer as ILayer);
                        pDataset = pEnumDataset.Next();
                    }
                }
                return(layerList);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 打开本地模板工作空间
        /// </summary>
        /// <returns>返回模板工作空间</returns>
        private IWorkspace OpenTempleteWorkSpace()
        {
            string            PDBPath           = Application.StartupPath + "\\..\\CacheDB\\TempleteDatabase.mdb";
            IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();

            return(pWorkspaceFactory.OpenFromFile(PDBPath, 0));
        }
Exemplo n.º 21
0
        public IWorkspace getMDBWorkspace(string mdbfilepath)
        {
            IWorkspaceFactory pWsFac = new AccessWorkspaceFactoryClass();
            IWorkspace        pWs    = pWsFac.OpenFromFile(mdbfilepath, 0);

            return(pWs);
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 打开工作空间
        /// </summary>
        public IWorkspace OpenWorkspace(string strMDBName)
        {
            IWorkspaceFactory workspaceFactory;

            workspaceFactory = new AccessWorkspaceFactoryClass();
            return(workspaceFactory.OpenFromFile(strMDBName, 0));
        }
Exemplo n.º 24
0
        //测试
        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); }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// ÅжÏÊÇ·ñ´æÔÚ×ÅÏàÓ¦±ÈÀû³ßµÄͼ¸±
        /// </summary>
        /// <param name="MapPath">ͼ¸±Â·¾¶</param>
        /// <param name="StrScale">±ÈÀý³ß</param>
        /// <returns></returns>
        private string GetMapFrameName(string MapPath, string StrScale, out Exception eError)
        {
            eError = null;
            IWorkspaceFactory pWorkSpaceFactory = new AccessWorkspaceFactoryClass();
            IWorkspace        pWorkSpace        = null;
            IEnumDataset      pEnumDataSet      = null;
            IDataset          pDataSet          = null;
            IFeatureDataset   pFeatureDataSet   = null;
            IEnumDataset      pEnumFC           = null;
            IDataset          pFC          = null;
            string            LayerName    = "";
            string            MapFrameName = "";

            if (MapPath != "")
            {
                pWorkSpace   = pWorkSpaceFactory.OpenFromFile(MapPath, 0);
                pEnumDataSet = pWorkSpace.get_Datasets(esriDatasetType.esriDTFeatureClass);
                pEnumDataSet.Reset();
                pDataSet = pEnumDataSet.Next();
                while (pDataSet != null)
                {
                    if (pDataSet is IFeatureClass)
                    {
                        LayerName = pDataSet.Name;
                        if (LayerName.Contains(StrScale))
                        {
                            MapFrameName = LayerName;
                        }
                    }
                    else if (pDataSet is IFeatureDataset)
                    {
                        pFeatureDataSet = pDataSet as IFeatureDataset;
                        pEnumFC         = pFeatureDataSet.Subsets;
                        pEnumFC.Reset();
                        pFC = pEnumFC.Next();
                        while (pFC != null)
                        {
                            LayerName = pFC.Name;
                            if (LayerName.Contains(StrScale))
                            {
                                MapFrameName = LayerName;
                            }
                        }
                    }
                    else
                    {
                        MapFrameName = "";
                    }
                    pDataSet = pEnumDataSet.Next();
                }
                if (MapFrameName == "")
                {
                    eError = new Exception("δÕÒµ½±ÈÀý³ßΪ'" + StrScale + "'µÄ·¶Î§Êý¾Ý£¬Çë¼ì²é£¡");
                    return("");
                }
            }
            return(MapFrameName);
        }
        private void EngineEditingForm_Load(object sender, EventArgs e)
        {
            //Set buddy controls
            axTOCControl1.SetBuddyControl(axMapControl1);
            axEditorToolbar.SetBuddyControl(axMapControl1);
            axToolbarControl1.SetBuddyControl(axMapControl1);

            //Add items to the ToolbarControl
            axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);

            //Add items to the custom editor toolbar
            axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);

            //Create a popup menu
            m_toolbarMenu = new ToolbarMenuClass();
            m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly);

            //share the command pool
            axToolbarControl1.CommandPool = axEditorToolbar.CommandPool;
            m_toolbarMenu.CommandPool     = axEditorToolbar.CommandPool;

            //Create an operation stack for the undo and redo commands to use
            IOperationStack operationStack = new ControlsOperationStackClass();

            axEditorToolbar.OperationStack = operationStack;

            //add some sample line data to the map
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            //relative file path to the sample data from EXE location
            string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            filePath = System.IO.Path.Combine(filePath, @"ArcGIS\data\StreamflowDateTime\Streamflow.mdb");

            IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd);

            //Add a polygon layer
            IFeatureLayer featureLayer1 = new FeatureLayerClass();

            featureLayer1.Name         = "Watershed";
            featureLayer1.Visible      = true;
            featureLayer1.FeatureClass = workspace.OpenFeatureClass("Watershed");
            axMapControl1.Map.AddLayer((ILayer)featureLayer1);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 遍历树节点
        /// </summary>
        private Boolean RecursionNodes(TreeListNodes Nodes)
        {
            ConnectDB cd       = new ConnectDB();
            Boolean   boolFlag = true;

            foreach (TreeListNode node in Nodes)
            {
                //// 如果当前节点下还包括子节点,就调用递归
                if (node.Nodes.Count > 0)
                {
                    RecursionNodes(node.Nodes);
                }
                else
                {
                    if (node.Checked && !node.HasChildren)
                    {
                        DataRowView nodeData = this.treeList1.GetDataRecordByNode(node) as DataRowView;

                        IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
                        IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(nodeData["PATH"].ToString(), 0) as IFeatureWorkspace;
                        //打开数据文件中航路点这个表
                        IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(nodeData["NAME"].ToString());
                        string        FeatureType   = pFeatureClass.ShapeType.ToString();
                        Boolean       result        = cd.Insert("insert into GISDATA_REGINFO (REG_NAME,REG_ALIASNAME,FEATURE_TYPE,PATH,DBTYPE) values ('" + nodeData["NAME"].ToString() + "','" + nodeData["NAME"].ToString() + "','" + FeatureType + "','" + nodeData["PATH"].ToString().Replace(@"\", @"\\") + "','" + nodeData["TYPE"].ToString() + "')");
                        CommonClass   common        = new CommonClass();
                        common.insertXmlNode(nodeData["NAME"].ToString(), nodeData["PATH"].ToString(), nodeData["TYPE"].ToString(), nodeData["NAME"].ToString());
                        if (result)
                        {
                            for (int i = 0; i < pFeatureClass.Fields.FieldCount; i++)
                            {
                                IField field = pFeatureClass.Fields.get_Field(i);
                                if (field.Name != pFeatureClass.ShapeFieldName && field.Name != pFeatureClass.OIDFieldName)
                                {
                                    string  REG_NAME      = nodeData["NAME"].ToString();
                                    string  FIELDID       = i.ToString();
                                    string  FIELD_NAME    = field.Name;
                                    string  FIELD_ALSNAME = field.AliasName;
                                    string  DATA_TYPE     = field.Type.ToString();
                                    string  MAXLEN        = field.Length.ToString();
                                    string  MINLEN        = field.Length.ToString();
                                    string  CODE_PK       = "";
                                    string  CODE_WHERE    = "";
                                    string  IS_NULL       = field.IsNullable.ToString();
                                    string  DEFAULT_VALUE = field.DefaultValue.ToString();
                                    Boolean insertResult  = cd.Insert("insert into GISDATA_MATEDATA (REG_NAME,FIELDID,FIELD_NAME,FIELD_ALSNAME,DATA_TYPE,MAXLEN,MINLEN,CODE_PK,CODE_WHERE,IS_NULL,DEFAULT_VALUE) values ('" + REG_NAME + "','" + FIELDID + "','" + FIELD_NAME + "','" + FIELD_ALSNAME + "','" + DATA_TYPE + "','" + MAXLEN + "','" + MINLEN + "','" + CODE_PK + "','" + CODE_WHERE + "','" + IS_NULL + "','" + DEFAULT_VALUE + "')");
                                    if (!insertResult)
                                    {
                                        boolFlag = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(boolFlag);
        }
Exemplo n.º 28
0
        //函数名:openAccessWorkspace
        //函数功能:打开个人数据库空间
        public IWorkspace openAccessWorkspace(string connString)
        {
            //Open the AccessWorkSpace by the given name which including extention(.mdb)
            IWorkspace        ws  = null;
            IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass();

            ws = wsf.OpenFromFile(connString, 0);
            return(ws);
        }
Exemplo n.º 29
0
        /// <summary>
        /// 获取指定的工作空间(Access类型)
        /// </summary>
        /// <param name="accessFile">Access文件名</param>
        /// <returns></returns>
        public static IWorkspace GetAccessWs(string accessFile)
        {
            IWorkspaceFactory pAccessWorkSpaceFactory;
            IWorkspace        pAccessWorkSpace;

            pAccessWorkSpaceFactory = new AccessWorkspaceFactoryClass();

            pAccessWorkSpace = pAccessWorkSpaceFactory.OpenFromFile(accessFile, 0);

            return(pAccessWorkSpace);
        }
Exemplo n.º 30
0
        /// <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);
        }
Exemplo n.º 31
0
Arquivo: Home.cs Projeto: gistop/aegis
 private void AddMDB()
 {
     string filePath = "C:\\temp\\mdb.mdb";
     AccessWorkspaceFactory fac = new AccessWorkspaceFactoryClass();
     IFeatureWorkspace space = (IFeatureWorkspace)fac.OpenFromFile(filePath, 0);
     IFeatureClass featureclass = space.OpenFeatureClass("layer");
     IFeatureLayer pFLRoads = new FeatureLayer();
     pFLRoads.FeatureClass = featureclass;
     pFLRoads.Name = "点";
     ILayer pLayerRoads = pFLRoads as ILayer;
     Global.mainmap.AddLayer(pLayerRoads);
 }
Exemplo n.º 32
0
 private IWorkspace OpenAccessWorkspace(string fileName)
 {
     try
     {
         IWorkspaceFactory2 wsf = new AccessWorkspaceFactoryClass();
         return(wsf.OpenFromFile(fileName, 0));
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 33
0
        /// <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;
        }
Exemplo n.º 34
0
 public static IWorkspace GetAccessWorkspace(string sFilePath)
 {
     if (!File.Exists(sFilePath))
     {
         return null;
     }
     try
     {
         IWorkspaceFactory factory = new AccessWorkspaceFactoryClass();
         return factory.OpenFromFile(sFilePath, 0);
     }
     catch
     {
         return null;
     }
 }
Exemplo n.º 35
0
 /// <summary>
 /// ����GDB����Դ
 /// </summary>
 public IWorkspace ConnectWorkspace()
 {
     IWorkspaceFactory factory = new AccessWorkspaceFactoryClass();
     try
     {
         return factory.OpenFromFile(m_strFilePathName, 0);
     }
     catch (Exception ex)
     {
         //ProjectData.SetProjectError(exception1);
         Logger.WriteErrorLog(ex);
         //ProjectData.ClearProjectError();
     }
     return null;
 }
Exemplo n.º 36
0
        /// <summary>
        /// 连接MDB的Workspace
        /// </summary>
        /// <param name="Path">MDB路径</param>
        public IWorkspace Workspace_MDB(string Path)
        {
            IWorkspaceFactory MDBWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IWorkspace WS = null;

            try
            {
                WS = MDBWorkspaceFactory.OpenFromFile(Path, 0);
            }
            catch
            {
                MessageBox.Show("请检查MDB路径是否正确");
            }

            return WS;
        }
Exemplo n.º 37
0
 //��������openAccessWorkspace
 //�������ܣ��򿪸������ݿ�ռ�
 public IWorkspace openAccessWorkspace(string connString)
 {
     //Open the AccessWorkSpace by the given name which including extention(.mdb)
     IWorkspace ws = null;
     IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass();
     ws = wsf.OpenFromFile(connString, 0);
     return ws;
 }
Exemplo n.º 38
0
 //++++++++GeoDatabase Part++++++
 public IFeatureClass openFeatureClass(string mdbName, string featName)
 {
     //Open the AccessWorkSpace by the given name which including extention(.mdb)
     IWorkspace ws = null;
     IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass();
     ws = wsf.OpenFromFile(mdbName, 0);
     IFeatureWorkspace pFeatWorkspace = ws as IFeatureWorkspace;
     IFeatureClass pFeatCls = pFeatWorkspace.OpenFeatureClass(featName);
     return pFeatCls;
 }
Exemplo n.º 39
0
        private void mnuSourceD_Click(object sender, EventArgs e)
        {
            int FCount;
            DirectoryInfo[] instDirs;
            IWorkspaceFactory theWSFact;
            IWorkspace theWS;
            IFeatureWorkspace theFWS;
            IFeatureClass theFClass;
            // get the directory that is to be scanned for Shapefiles or Geodatabases

            DialogResult theAns;
            FolderBrowserDialog DirBrowserDlg = new FolderBrowserDialog();
            DirBrowserDlg.RootFolder = Environment.SpecialFolder.MyComputer;

            DirBrowserDlg.Description = "Select the Parent Folder containing Geospatial Items.";

            theAns = DirBrowserDlg.ShowDialog();

            if (theAns == DialogResult.OK)
            {
                DirectoryInfo iDir = new DirectoryInfo(DirBrowserDlg.SelectedPath);

                try
                {
                    instDirs = iDir.GetDirectories();

                    foreach (DirectoryInfo theDir in instDirs)
                    {
                    }

                    foreach (FileInfo theFile in iDir.GetFiles("*.mdb"))
                    {
                        theWSFact = new AccessWorkspaceFactoryClass();

                        theWS = theWSFact.OpenFromFile(theFile.FullName, 0);

                        String[] theSrcNames = GeoDbProcs.GetFeatureClassNames(srcWrkSpc);

                        foreach (String theSrcName in theSrcNames)
                        {
                            theFWS = (IFeatureWorkspace)theWS;
                            theFClass = theFWS.OpenFeatureClass(theSrcName);
                            lbSource.Items.Add(new FeatureData(theSrcName, theFClass));
                            Application.DoEvents();
                        }
                        CheckforGeoSpatialData(iDir.FullName, "ShapeFile", lbSource);
                    }
                }
                catch (Exception ex) { }
            }
        }
Exemplo n.º 40
0
        public IFeatureClass OpenFeatureClassFromFileMdb(string path, string name)
        {
            IWorkspaceFactory2 mdbWspf = new AccessWorkspaceFactoryClass();
            IWorkspace wsp;
            IFeatureWorkspace fwsp;

            wsp = mdbWspf.OpenFromFile(path, 0);
            fwsp = (IFeatureWorkspace)wsp;
            return fwsp.OpenFeatureClass(name);
        }
Exemplo n.º 41
0
        public void CreateRoutesUsing2Fields(string pAccessWS, string sLineFC, string sOutRouteFC, string sWhereClause, string sRouteIDField, string sFromMeasureField, string sToMeasureField)
        {
            try
            {

                IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass();
                IWorkspace ws = wsf.OpenFromFile(pAccessWS, 0);
                IFeatureWorkspace fws = (IFeatureWorkspace)ws;
                IFeatureClass lineFC = fws.OpenFeatureClass(sLineFC);
                // Create an output feature class name object. We'll write to a stand alone feature class in the
                // the same workspace as the inputs
                IDataset ds = (IDataset)ws;
                IWorkspaceName outWSN = (IWorkspaceName)ds.FullName;
                IFeatureClassName outFCN = new FeatureClassNameClass();
                IDatasetName outDSN = (IDatasetName)outFCN;
                outDSN.WorkspaceName = outWSN;
                outDSN.Name = sOutRouteFC;
                //This name should not already exist
                // Create a geometry definition for the new feature class. For the most part, we will copy the geometry
                // definition from the input lines. We'll explicitly set the M Domain, however. You should always set an
                // M Domain that is appropriate to your data. What is below is just a sample.
                IFields flds = lineFC.Fields;
                Int32 i = flds.FindField(lineFC.ShapeFieldName);
                IField fld = flds.get_Field(i);
                IClone GDefclone = (IClone)fld.GeometryDef;
                IGeometryDef gDef = (IGeometryDef)GDefclone.Clone();
                ISpatialReference2 srRef = (ISpatialReference2)gDef.SpatialReference;
                srRef.SetMFalseOriginAndUnits(-1000, 10000);
                // Create a selection set to limit the number of lines that will be used to create routes
                IQueryFilter qFilt = new QueryFilterClass();
                qFilt.WhereClause = sWhereClause;
                ISelectionSet2 selSet = (ISelectionSet2)lineFC.Select(qFilt, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, ws);
                // Create a new RouteMeasureCreator object. Note that below, we use the selection set and not the
                // InputFeatureClass property
                IRouteMeasureCreator routeCreator = new RouteMeasureCreatorClass();
                routeCreator.InputFeatureSelection = selSet;
                routeCreator.InputRouteIDFieldName = sRouteIDField;

                IEnumBSTR errors = routeCreator.CreateUsing2Fields(sFromMeasureField, sToMeasureField, outFCN, gDef, "", null);
                // The results of running CreatingUsing2Fields returns IEnumBSTR, which is a container
                // for a list of error strings indicating why certain lines could not be used to create routes.
                string sError = errors.Next();
                do
                {
                    System.Windows.Forms.MessageBox.Show(sError);
                    sError = errors.Next();
                } while (sError.Length != 0);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }
        private void EngineEditingForm_Load(object sender, EventArgs e)
        {
            m_editor = new EngineEditorClass();
           
            //Set buddy controls
            axTOCControl1.SetBuddyControl(axMapControl1);
            axEditorToolbar.SetBuddyControl(axMapControl1);
            axToolbarControl1.SetBuddyControl(axMapControl1);

            //Add items to the ToolbarControl
            axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);            
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
           
            //Add items to the custom editor toolbar          
            axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
                       
            //Create a popup menu
            m_toolbarMenu = new ToolbarMenuClass();
            m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly);

            //share the command pool          
            axToolbarControl1.CommandPool = axEditorToolbar.CommandPool;
            m_toolbarMenu.CommandPool = axEditorToolbar.CommandPool;

            //Create an operation stack for the undo and redo commands to use
            IOperationStack operationStack = new ControlsOperationStackClass();
            axEditorToolbar.OperationStack = operationStack;

            // Fill the Check List of Events for Selection
            TabControl tabControl = eventTabControl as TabControl;
            System.Collections.IEnumerator enumTabs = tabControl.TabPages.GetEnumerator();
            enumTabs.MoveNext();
            m_listenTab = enumTabs.Current as TabPage;
            enumTabs.MoveNext();
            m_selectTab = enumTabs.Current as TabPage;

            CheckedListBox editEventList = m_selectTab.GetNextControl(m_selectTab, true) as CheckedListBox;
            editEventList.ItemCheck += new ItemCheckEventHandler(editEventList_ItemCheck);

            ListBox listEvent = m_listenTab.GetNextControl(m_listenTab, true) as ListBox;
            listEvent.MouseDown += new MouseEventHandler(listEvent_MouseDown);

            eventListener = new Events.EventListener(m_editor);

            eventListener.Changed += new Events.ChangedEventHandler(eventListener_Changed);

            //populate the editor events            
            editEventList.Items.AddRange(Enum.GetNames(typeof(Events.EventListener.EditorEvent)));

            //add some sample line data to the map
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            //relative file path to the sample data from EXE location
            string filePath = @"..\..\..\data\StreamflowDateTime\Streamflow.mdb";
            
            IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd);

            //Add the various layers
            IFeatureLayer featureLayer1 = new FeatureLayerClass();
            featureLayer1.Name = "Watershed";
            featureLayer1.Visible = true;
            featureLayer1.FeatureClass = workspace.OpenFeatureClass("Watershed");
            axMapControl1.Map.AddLayer((ILayer)featureLayer1);

            IFeatureLayer featureLayer2 = new FeatureLayerClass();
            featureLayer2.Name = "TimSerTool";
            featureLayer2.Visible = true;
            featureLayer2.FeatureClass = workspace.OpenFeatureClass("TimSerTool");
            axMapControl1.Map.AddLayer((ILayer)featureLayer2);

        }
		public static void Main(string[] args)
		{
			#region Licensing
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
			IAoInitialize aoInitialize = new AoInitializeClass();
			esriLicenseStatus licenseStatus = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
			if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
			{
				MessageBox.Show("An Advanced License could not be checked out.");
				return;
			}
			#endregion

			try
			{
				// Open the workspace.
				IWorkspaceFactory workspaceFactory = null;
				switch (geodatabaseType)
				{
					case GeodatabaseType.ArcSDE:
						workspaceFactory = new SdeWorkspaceFactoryClass();
						break;
					case GeodatabaseType.FileGDB:
						workspaceFactory = new FileGDBWorkspaceFactoryClass();
						break;
					case GeodatabaseType.PersonalGDB:
						workspaceFactory = new AccessWorkspaceFactoryClass();
						break;
				}
				IWorkspace workspace = workspaceFactory.OpenFromFile(workspacePath, 0);
				IWorkspaceExtensionManager workspaceExtensionManager = (IWorkspaceExtensionManager)workspace;

				// Create a UID for the workspace extension.
				UID uid = new UIDClass();
				uid.Value = extensionGuid;

                // Determine whether there are any existing geodatabase-register extensions.
				// To disambiguate between GDB-register extensions and component category extensions,
				// check the extension count of a new scratch workspace.
				IScratchWorkspaceFactory scratchWorkspaceFactory = new FileGDBScratchWorkspaceFactoryClass();
				IWorkspace scratchWorkspace = scratchWorkspaceFactory.CreateNewScratchWorkspace();
				IWorkspaceExtensionManager scratchExtensionManager = (IWorkspaceExtensionManager)scratchWorkspace;
				Boolean workspaceExtensionApplied = false;
				UID gdbRegisteredUID = null;
				try
				{
					workspaceExtensionApplied = (workspaceExtensionManager.ExtensionCount > scratchExtensionManager.ExtensionCount);
				}
				catch (COMException comExc)
				{
					// This is necessary in case the existing extension could not be initiated.
					if (comExc.ErrorCode == (int)fdoError.FDO_E_WORKSPACE_EXTENSION_CREATE_FAILED)
					{
						// Parse the error message for the current extension's GUID.
						Regex regex = new Regex("(?<guid>{[^}]+})");
						MatchCollection matchCollection = regex.Matches(comExc.Message);
						if (matchCollection.Count > 0)
						{
							Match match = matchCollection[0];
							gdbRegisteredUID = new UIDClass();
							gdbRegisteredUID.Value = match.Groups["guid"].Value;
							workspaceExtensionApplied = true;
						}
						else
						{
							throw comExc;
						}
					}
					else
					{
						throw comExc;
					}
				}

				if (workspaceExtensionApplied)
				{
					if (gdbRegisteredUID == null)
					{
						// There is GDB-registered extension on the SDE workspace. Find the SDE extension that is not
						// applied to the scratch workspace. 
						for (int i = 0; i < workspaceExtensionManager.ExtensionCount; i++)
						{
							IWorkspaceExtension workspaceExtension = workspaceExtensionManager.get_Extension(i);
							IWorkspaceExtension scratchExtension = scratchExtensionManager.FindExtension(workspaceExtension.GUID);
							if (scratchExtension == null)
							{
								gdbRegisteredUID = workspaceExtension.GUID;
							}
						}
					}
				}

				// If the extension could be located, remove it.
				if (gdbRegisteredUID != null)
				{
					workspaceExtensionManager.UnRegisterExtension(gdbRegisteredUID);
				}

				// Register the extension.
				workspaceExtensionManager.RegisterExtension("RasterSyncExtension.RasterSyncWorkspaceExtension", uid);
			}
			catch (COMException comExc)
			{
				switch (comExc.ErrorCode)
				{
					case (int)fdoError.FDO_E_WORKSPACE_EXTENSION_NO_REG_PRIV:
						MessageBox.Show("The connection file's privileges are insufficient to perform this operation.",
							"Register Workspace Extension", MessageBoxButtons.OK, MessageBoxIcon.Error);
						break;
					case (int)fdoError.FDO_E_WORKSPACE_EXTENSION_CREATE_FAILED:
						String createErrorMessage = String.Concat("The workspace extension could not be created.",
							Environment.NewLine, "Ensure that it has been registered for COM Interop.");
						MessageBox.Show(createErrorMessage, "Register Workspace Extension", MessageBoxButtons.OK, MessageBoxIcon.Error);
						break;
					case (int)fdoError.FDO_E_WORKSPACE_EXTENSION_DUP_GUID:
					case (int)fdoError.FDO_E_WORKSPACE_EXTENSION_DUP_NAME:
						String dupErrorMessage = String.Concat("A duplicate name or GUID was detected. Make sure any existing GDB-registered",
							"workspaces are not component category-registered as well.");
						MessageBox.Show(dupErrorMessage, "Register Workspace Extension", MessageBoxButtons.OK, MessageBoxIcon.Error);
						break;
					default:
						String otherErrorMessage = String.Format("An unexpected error has occurred:{0}{1}{2}", Environment.NewLine, comExc.Message,
							comExc.ErrorCode);
						MessageBox.Show(otherErrorMessage);
						break;
				}
			}
			catch (Exception exc)
			{
				String errorMessage = String.Format("An unexpected error has occurred:{0}{1}", Environment.NewLine, exc.Message);
				MessageBox.Show(errorMessage);
			}

			// Shutdown the AO initializer.
			aoInitialize.Shutdown();
		}
Exemplo n.º 44
0
        //IFeatureClass ITnExToolsDataManager.TnOpenFeatureClassFromFileMdb(string pathNoEnd, string name)
        //{
        //    IWorkspaceFactory2 mdbWspf = new AccessWorkspaceFactoryClass();
        //    IWorkspace wsp;
        //    IFeatureWorkspace fwsp;
        //    wsp = mdbWspf.OpenFromFile(pathNoEnd, 0);
        //    fwsp = (IFeatureWorkspace)wsp;
        //    return fwsp.OpenFeatureClass(name);
        //}
        IFeatureClass IDataManager.TnOpenFeatureClassFromFileMdb(params string[] fullpathOrPathandname)
        {
            IWorkspaceFactory2 mdbWspf = new AccessWorkspaceFactoryClass();
               IWorkspace wsp;
               IFeatureWorkspace fwsp;
               int i = fullpathOrPathandname.Length;
               string pathNoEnd = "";
               string name = "";
               int j = 0;
               if (i == 2)
               {
               pathNoEnd = fullpathOrPathandname[0];
               name = fullpathOrPathandname[1];
               }
               else if(i==1)
               {
               for (j = fullpathOrPathandname[0].Length-1; j > 0; j--)
               {
                   if (fullpathOrPathandname[0][j].CompareTo(System.Char.Parse("/"))==0)
                   {
                       break;
                   }
               }
               pathNoEnd = fullpathOrPathandname[0].Substring(0, j);
               name = fullpathOrPathandname[0].Substring(j + 1, fullpathOrPathandname[0].Length - 1 - j);
               }

               wsp = mdbWspf.OpenFromFile(pathNoEnd, 0);
               fwsp = (IFeatureWorkspace)wsp;
               return fwsp.OpenFeatureClass(name);
        }
        private void EngineEditingForm_Load(object sender, EventArgs e)
        {
           
            //Set buddy controls
            axTOCControl1.SetBuddyControl(axMapControl1);
            axEditorToolbar.SetBuddyControl(axMapControl1);
            axToolbarControl1.SetBuddyControl(axMapControl1);

            //Add items to the ToolbarControl
            axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);            
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
           
            //Add items to the custom editor toolbar          
            axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
           
            //Create a popup menu
            m_toolbarMenu = new ToolbarMenuClass();
            m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly);

            //share the command pool
            axToolbarControl1.CommandPool = axEditorToolbar.CommandPool;
            m_toolbarMenu.CommandPool = axEditorToolbar.CommandPool;

            //Create an operation stack for the undo and redo commands to use
            IOperationStack operationStack = new ControlsOperationStackClass();
            axEditorToolbar.OperationStack = operationStack;

            //add some sample line data to the map
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            //relative file path to the sample data from EXE location            
            string filePath = @"..\..\..\..\data\StreamflowDateTime\Streamflow.mdb";
            
            IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd);

            //Add a polygon layer
            IFeatureLayer featureLayer1 = new FeatureLayerClass();
            featureLayer1.Name = "Watershed";
            featureLayer1.Visible = true;
            featureLayer1.FeatureClass = workspace.OpenFeatureClass("Watershed");
            axMapControl1.Map.AddLayer((ILayer)featureLayer1);
        }
Exemplo n.º 46
0
        private void 删除要素类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string WsName = WsPath();

             if (WsName != "")
             {

                 IWorkspaceFactory pWsFt = new AccessWorkspaceFactoryClass();

                 IWorkspace pWs = pWsFt.OpenFromFile(WsName, 0);

                 IFeatureWorkspace pFWs = pWs as IFeatureWorkspace;

                 IFeatureClass pFClass = pFWs.OpenFeatureClass("PointTest");

                 IDataset pDatset = pFClass as IDataset;

                 pDatset.Delete();

             }
        }
Exemplo n.º 47
0
        private void txtfolder_Click(object sender, EventArgs e)
        {
            bool cancel = true;
            switch (m_DataType)
            {
                case enumDataType.VCT:
                    dlgSourceFile.Filter = "VCT�ļ�|*.VCT";
                    dlgSourceFile.FileName = txtDatasource.Text;
                    if (dlgSourceFile.ShowDialog() == DialogResult.OK)
                    {
                        txtDatasource.Text = dlgSourceFile.FileName;
                        cancel = false;
                    }
                    break;

                case enumDataType.FileGDB:
                case enumDataType.SHP:
                    dlgSourceFolder.SelectedPath = txtDatasource.Text;
                    if (dlgSourceFolder.ShowDialog() == DialogResult.OK)
                    {
                        txtDatasource.Text = dlgSourceFolder.SelectedPath;
                        cancel = false;
                    }
                    break;

                case enumDataType.PGDB:
                    dlgSourceFile.Filter = "PGDB(MDB)�ļ�|*.MDB";
                    dlgSourceFile.FileName = txtDatasource.Text;
                    if (dlgSourceFile.ShowDialog() == DialogResult.OK)
                    {
                        txtDatasource.Text = dlgSourceFile.FileName;
                        cancel = false;
                    }
                    break;

                default:
                    break;
            }
            if (string.IsNullOrEmpty(txtDatasource.Text))
            {
                dxErrorProvider.SetError(txtDatasource, "����Դ·������Ϊ��");
            }
            else
            {
                dxErrorProvider.SetError(txtDatasource, null);
            }

            if (cancel)
                return;

            if (m_DataType != enumDataType.VCT)
            {
                try
                {
                    // �ռ�ο��б�
                    m_DicSpatialReference = new Dictionary<string, ISpatialReference>();
                    cmbSpatialRefLayer.Properties.Items.Clear();
                    IWorkspaceFactory wsFactory = null;
                    switch (m_DataType)
                    {
                        case enumDataType.FileGDB:
                            wsFactory = new FileGDBWorkspaceFactoryClass();
                            break;
                        case enumDataType.SHP:
                            wsFactory = new ShapefileWorkspaceFactoryClass();
                            break;

                        case enumDataType.PGDB:
                            wsFactory = new AccessWorkspaceFactoryClass();
                            break;
                        default:
                            break;
                    }
                    IWorkspace wsSource = wsFactory.OpenFromFile(txtDatasource.Text, 0);
                    IEnumDataset enDataset = wsSource.get_Datasets(esriDatasetType.esriDTAny);
                    IDataset ds = enDataset.Next();

                    while (ds != null)
                    {
                        IGeoDataset geoDs = ds as IGeoDataset;
                        if (geoDs != null)
                        {
                            cmbSpatialRefLayer.Properties.Items.Add(ds.Name);
                            m_DicSpatialReference.Add(ds.Name, geoDs.SpatialReference);
                        }
                        ds = enDataset.Next();
                    }

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wsSource);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wsFactory);
                    wsSource = null;
                    wsFactory = null;
                    GC.Collect();

                }
                catch
                {
                    MessageBoxApi.ShowErrorMessageBox("ѡ�������Դ����ȷ��������Դ��û�пռ����ݣ�");
                    txtDatasource.Text = "";
                }

                if (cmbSpatialRefLayer.Properties.Items.Count == 0)
                {
                    MessageBoxApi.ShowErrorMessageBox("ѡ�������Դ����ȷ��������Դ��û�пռ����ݣ�");
                    //dxErrorProvider.SetError(txtDatasource, "��ǰ����Դ��û�пռ�����", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
                    txtDatasource.Text = "";
                }
                else
                {
                    dxErrorProvider.SetError(txtDatasource, null);
                    cmbSpatialRefLayer.SelectedIndex = 0;
                }
            }
        }
Exemplo n.º 48
0
        /// <summary>
        /// 打开个人数据库
        /// </summary>
        /// <param name="_pGDBName"></param>
        /// <returns></returns>
        public IWorkspace GetMDBWorkspace(String _pGDBName)
        {
            IWorkspaceFactory pWsFac = new AccessWorkspaceFactoryClass();

               IWorkspace pWs = pWsFac.OpenFromFile(_pGDBName,0);

               return pWs;
        }
Exemplo n.º 49
0
 public void ExportToMDB(string name, string outputPath)
 {
     IWorkspaceFactory wsFct = new AccessWorkspaceFactoryClass();
     IWorkspace pWorkspace = (IWorkspace)wsFct.OpenFromFile(outputPath, 0);
     ConvertFeatureClassToGDB(this.m_workSpace, pWorkspace, name, name, null);
 }
Exemplo n.º 50
0
        private void 获取所有要素类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string WsName = WsPath();

             if (WsName != "")
             {

                 IWorkspaceFactory pWsFt = new AccessWorkspaceFactoryClass();

                 IWorkspace pWs = pWsFt.OpenFromFile(WsName, 0);

                 IEnumDataset pEDataset = pWs.get_Datasets(esriDatasetType.esriDTAny);

                 IDataset pDataset = pEDataset.Next();

                 while (pDataset != null)
                 {
                     if (pDataset.Type == esriDatasetType.esriDTFeatureClass)
                     {
                         FeatureClassBox.Items.Add(pDataset.Name);
                     }
                     //如果是数据集
                     else if (pDataset.Type == esriDatasetType.esriDTFeatureDataset)
                     {
                         IEnumDataset pESubDataset = pDataset.Subsets;

                         IDataset pSubDataset = pESubDataset.Next();

                         while (pSubDataset != null)
                         {
                             FeatureClassBox.Items.Add(pSubDataset.Name);

                             pSubDataset = pESubDataset.Next();
                         }
                     }

                     pDataset = pEDataset.Next();
                 }

             }

             FeatureClassBox.Text = FeatureClassBox.Items[0].ToString();
        }
Exemplo n.º 51
0
        //Open Personal Geodatabase RasterCatalog
        //   ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesGDB
        public IRasterCatalog OpenPGDBRasterCatalog(string pathName, string rasterCatalogName)
        {
            // Open personal geodatabase raster catalog with the given name
            // pathName is the PGDB path (location of the personal geodatabase)
            // rasterCatalogName is the name of the raster catalog to be opened

            //Open the Access workspace
            IWorkspaceFactory2 workspaceFactory = new AccessWorkspaceFactoryClass();

            IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspaceEx;

            //Open the PGDB raster Catalog
            IRasterCatalog rasterCatalog = null;
            rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);

            return rasterCatalog;
        }
Exemplo n.º 52
0
        /// <summary>
        ///打开要素类,以下几个函数为公用,暂时放在不放在一个公用类里面
        /// </summary>
        /// <returns></returns>
        /// <summary>
        /// 获取要素类
        /// </summary>
        /// <param name="p_GDBFileName"></param>
        /// <param name="p_FeatureClassName"></param>
        /// <returns></returns>
        private IFeatureClass OpenFeatureClass(string p_GDBFileName, string p_FeatureClassName)
        {
            IWorkspaceFactory li_WorkspaceFactory;

            IWorkspace li_Workspace;

            IFeatureWorkspace li_FeatureWorkspace;

            IFeatureClass li_FeatureClass;

            li_WorkspaceFactory = new AccessWorkspaceFactoryClass();

            li_Workspace = li_WorkspaceFactory.OpenFromFile(p_GDBFileName, 0);

            li_FeatureWorkspace = li_Workspace as IFeatureWorkspace;

            li_FeatureClass = li_FeatureWorkspace.OpenFeatureClass(p_FeatureClassName);

            return li_FeatureClass;
        }
Exemplo n.º 53
0
        private void FillSubDirectory(DirectoryInfo di)
        {
            IWorkspaceFactory theWSFact;
            IWorkspace theWS;
            IFeatureWorkspace theFWS;
            IFeatureClass theFClass;
            int FCount;

            try
            {
                foreach (DirectoryInfo iDir in di.GetDirectories())
                {
                    FillSubDirectory(iDir);
                }

                foreach (FileInfo theFile in di.GetFiles("*.mdb"))
                {
                    theWSFact = new AccessWorkspaceFactoryClass();

                    theWS = theWSFact.OpenFromFile(theFile.FullName, 0);
                    theFWS = (IFeatureWorkspace)theWS;

                    String[] theSrcNames = GeoDbProcs.GetFeatureClassNames(srcWrkSpc);

                    foreach (String theSrcName in theSrcNames)
                    {
                        theFClass = theFWS.OpenFeatureClass(theSrcName);
                        lbSource.Items.Add(new FeatureData(theSrcName, theFClass));
                        Application.DoEvents();
                    }
                }
            }
            catch { }
        }