Пример #1
0
        private void MainWnd_Load(object sender, EventArgs e)
        {
            // Get workspace and open mdb file
            IWorkspaceFactory2 wkspcFactory = (IWorkspaceFactory2) new FileGDBWorkspaceFactoryClass();
            string             filePath     = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            filePath = System.IO.Path.Combine(filePath, @"ArcGIS\data\SanFrancisco\SanFrancisco.gdb");
            IFeatureWorkspace wkspc = wkspcFactory.OpenFromFile(filePath, Handle.ToInt32()) as IFeatureWorkspace;

            //open the Geodatabase table
            ITable foundITable = wkspc.OpenFeatureClass("Parks") as ITable;

            if (null != foundITable)
            {
                // Bind dataset to the binding source
                tableWrapper = new ArcDataBinding.TableWrapper(foundITable);
                bindingSource1.DataSource = tableWrapper;

                // Bind binding source to grid. Alternatively it is possible to bind TableWrapper
                // directly to the grid to this offers less flexibility
                dataGridView1.DataSource = bindingSource1;

                // Bind binding source to text box, we are binding the NAME
                // field.
                txtBoxBinding = new Binding("Text", bindingSource1, "NAME");
                textBox1.DataBindings.Add(txtBoxBinding);
            }
        }
Пример #2
0
        public static IRaster AbrirRasterDesdeGDB(string sDir, string sNombre)
        {
            try
            {
                IWorkspaceFactory2 pWorkspaceFactory2 = (IWorkspaceFactory2) new AccessWorkspaceFactoryClass();
                IRasterWorkspaceEx pRasterWorkspaceEx = (IRasterWorkspaceEx)pWorkspaceFactory2.OpenFromFile(sDir, 0);
                //IWorkspace pWorkspace = (IWorkspace)pRasterWorkspaceEx;
                //IEnumDataset pEnumDS = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset);
                //IDataset pDS = pEnumDS.Next();
                //while (pDS != null)
                //{
                //  if (pDS.Name.ToUpper().Equals(sNombre.ToUpper()))
                //  {
                //    IRasterDataset pRDS = (IRasterDataset)pDS;

                //  }
                //  pDS = pEnumDS.Next();
                //}
                IRasterDataset pRDS2 = pRasterWorkspaceEx.OpenRasterDataset(sNombre);
                return(pRDS2.CreateDefaultRaster());
                //IWorkspaceFactory wsFactory = new RasterWorkspaceFactoryClass();
                //IRasterWorkspace ws = (IRasterWorkspace)wsFactory.OpenFromFile(sDir, 0);
                //IRasterDataset rasterDataset = ws.OpenRasterDataset(sNombre);
                //return rasterDataset.CreateDefaultRaster();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// open geodatabase from path filename
        /// </summary>
        /// <param name="path">path file name of file geodatabase</param>
        /// <returns>object Workspace</returns>
        public static IWorkspace OpenFGDB(string path)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)Activator.CreateInstance(factoryType);

            return(workspaceFactory.OpenFromFile(path, 0));
        }
Пример #4
0
        /// <summary>
        /// 打开个人数据库工作空间
        /// </summary>
        /// <param name="ppOutWS">打开的工作空间</param>
        /// <param name="strFullPath">mdb全路径</param>
        /// <returns>打开成功与否</returns>
        public static bool OpenPGDBEx(ref IWorkspace ppOutWS, string strFullPath)
        {
            try
            {
                if (!System.IO.File.Exists(strFullPath))
                {
                    return(false);
                }

                IWorkspaceFactory2 pFactory = GetWorkspaceFactory(enumDataType.PGDB);
                ppOutWS = pFactory.OpenFromFile(strFullPath, 0);
                if (pFactory != null)
                {
                    Marshal.ReleaseComObject(pFactory);
                    pFactory = null;
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
            return(true);
        }
Пример #5
0
        static IWorkspace OpenRasterPGDBWorkspace(string connStr)
        {
            Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");

            System.Object      obj = Activator.CreateInstance(t);
            IWorkspaceFactory2 workspaceFactory = obj as IWorkspaceFactory2;

            return(workspaceFactory.OpenFromFile(connStr, 0));
        }
        public static ILocatorWorkspace GetFileGDBLocatorWorkspace(string path)
        {
            // Open a workspace from a file geodatabase
            System.Object      obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"));
            IWorkspaceFactory2 workspaceFactory = obj as IWorkspaceFactory2;
            IWorkspace         workspace        = workspaceFactory.OpenFromFile(path, 0); // example of path string is... @"C:\UnitedStates.gdb"

            // Get a locator from the locator Workspace
            obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"));
            ILocatorManager2  locatorManager   = obj as ILocatorManager2;
            ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspace(workspace);

            return(locatorWorkspace);
        }
Пример #7
0
        public static ITable AbrirTablaDesdeGDB(string sDir, string sNombre)
        {
            try
            {
                IWorkspaceFactory2 pWorkspaceFactory2 = (IWorkspaceFactory2) new AccessWorkspaceFactoryClass();
                IFeatureWorkspace  pFWorkspace        = (IFeatureWorkspace)pWorkspaceFactory2.OpenFromFile(sDir, 0);

                return(pFWorkspace.OpenTable(sNombre));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #8
0
        public static IWorkspace OpenWorkspace(enumDataType wsType, string strPath)
        {
            IWorkspaceFactory2 wsFactory = GetWorkspaceFactory(wsType);

            if (wsFactory == null)
            {
                throw new Exception("调用错误:打开Workspace时传入了未被支持的数据类型");
            }

            try
            {
                return(wsFactory.OpenFromFile(strPath, 0));
            }
            catch (Exception exp)
            {
                throw new Exception("打开Workspace时发生错误,可能的原因是数据路径与数据类型不一致,信息:" + exp.ToString());
            }
        }