Exemplo n.º 1
0
        public IWorkspace CreateOrOpenLoaclGeoDataBase(string path, EnumLoaclGeoDatabaseType type)
        {
            try
            {
                IWorkspaceFactory pTargetWsf = null;
                switch (type)
                {
                case EnumLoaclGeoDatabaseType.MDB:
                    pTargetWsf = new AccessWorkspaceFactory();
                    break;

                case EnumLoaclGeoDatabaseType.GDB:
                    pTargetWsf = new FileGDBWorkspaceFactory();
                    break;

                case EnumLoaclGeoDatabaseType.SHP:
                    pTargetWsf = new ShapefileWorkspaceFactory();
                    break;
                }
                if (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))
                {
                    if (pTargetWsf.IsWorkspace(path))
                    {
                        return(pTargetWsf.OpenFromFile(path, 0));
                    }
                    else
                    {
                        ErrorMessage = "当前工作空间已经损坏";
                        return(null);
                    }
                }
                else
                {
                    string         sPath          = System.IO.Path.GetDirectoryName(path);
                    string         sName          = System.IO.Path.GetFileNameWithoutExtension(path);
                    IWorkspaceName pWorkspaceName = pTargetWsf.Create(sPath, sName, null, 0);
                    return(pTargetWsf.Open(pWorkspaceName.ConnectionProperties, 0));
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置PDB、GDB、SHP工作区
        /// </summary>
        /// <param name="sFilePath">文件路径</param>
        /// <param name="wstype">工作区类型</param>
        /// <returns>输出错误Exception</returns>
        private IWorkspace SetWorkspace(string sFilePath, string dbType, out Exception eError)
        {
            eError = null;
            IWorkspace   pWS      = null;
            IPropertySet pPropSet = new PropertySetClass();

            try
            {
                switch (dbType)
                {
                case "PDB":
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWS         = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    break;

                case "GDB":
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWS          = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact = null;
                    break;

                case "SHP":
                    ShapefileWorkspaceFactory pFileSHPFact = new ShapefileWorkspaceFactory();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWS          = pFileSHPFact.Open(pPropSet, 0);
                    pFileSHPFact = null;
                    break;
                }
                pPropSet = null;
                return(pWS);
            }
            catch (Exception eX)
            {
                eError = eX;
                return(null);
            }
        }
Exemplo n.º 3
0
        private void tbnAddData_Click(object sender, EventArgs e)
        {   //添加数据
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.DefaultExt = "shp";
            openFileDialog.Filter     = "shp 文件|*.shp";

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

            // 得到Shapefile文件所在的目录.
            string strDir = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
            // 得到Shapefile文件的名字,.shp后缀.
            string strShpFile = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName);

            IWorkspaceFactory pWSF         = new ShapefileWorkspaceFactory();
            IPropertySet      pPropertySet = new PropertySetClass();

            pPropertySet.SetProperty("DATABASE", strDir);

            try
            {
                IWorkspace        pWorkspace        = pWSF.Open(pPropertySet, 0);
                IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
                IFeatureClass     pFeatureClass     = pFeatureWorkspace.OpenFeatureClass(strShpFile);
                IFeatureLayer     pFeatureLayer     = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                pFeatureLayer.Name         = pFeatureClass.AliasName;
                MainMap.AddLayer(pFeatureLayer as ILayer);
                MapViewer.AddLayer(pFeatureLayer as ILayer);
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Exemplo n.º 4
0
        public static IFeatureWorkspace GetFeatureWoskspacePasta(string pasta)
        {
            IFeatureWorkspace pFeatureWorkspace;

            IPropertySet pPropset = new PropertySetClass();
            IWorkspace pWorkspace = null;

            pPropset.SetProperty("DATABASE", pasta);

            IWorkspaceFactory pFact = new ShapefileWorkspaceFactory();
            pWorkspace = pFact.Open(pPropset, 0);

            pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

            return pFeatureWorkspace;
        }
Exemplo n.º 5
0
 public void Convert()
 {
     if (this.list_0.Count != 0)
     {
         IWorkspaceFactory shapefileWorkspaceFactoryClass = new ShapefileWorkspaceFactory();
         IPropertySet      propertySetClass = new PropertySet();
         propertySetClass.SetProperty("DATABASE", this.string_0);
         IWorkspace         workspace           = shapefileWorkspaceFactoryClass.Open(propertySetClass, 0);
         frmExportProcessEx _frmExportProcessEx = new frmExportProcessEx()
         {
             ConvertEvent = this
         };
         _frmExportProcessEx.Show();
         if (this.setMinValueHandler_0 != null)
         {
             this.setMinValueHandler_0(0);
         }
         if (this.setMaxValueHandler_0 != null)
         {
             this.setMaxValueHandler_0(this.list_0.Count);
         }
         for (int i = 0; i < this.list_0.Count; i++)
         {
             IFeatureClass item = this.list_0[i];
             if (this.setPositionHandler_0 != null)
             {
                 this.setPositionHandler_0(i);
             }
             if (item != null)
             {
                 ISpatialFilter spatialFilterClass = null;
                 if (this.igeometry_0 != null)
                 {
                     spatialFilterClass = new SpatialFilter()
                     {
                         GeometryField = item.ShapeFieldName,
                         Geometry      = this.igeometry_0
                     };
                     if (item.ShapeType != esriGeometryType.esriGeometryPoint)
                     {
                         spatialFilterClass.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                     }
                     else
                     {
                         spatialFilterClass.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                     }
                 }
                 int num = item.FeatureCount(spatialFilterClass);
                 if (num != 0)
                 {
                     if (this.setHandleFeatureInfoHandler_0 != null)
                     {
                         this.setHandleFeatureInfoHandler_0(item.AliasName);
                     }
                     string str = string.Format("  正在处理要素类{0}", item.AliasName);
                     if (this.setMessageHandler_0 != null)
                     {
                         this.setMessageHandler_0(str);
                     }
                     if (this.setFeatureClassMinValueHandler_0 != null)
                     {
                         this.setFeatureClassMinValueHandler_0(0);
                     }
                     if (this.setFeatureClassMaxValueHandler_0 != null)
                     {
                         this.setFeatureClassMaxValueHandler_0(num);
                     }
                     this.method_1(item, workspace);
                 }
                 else if (this.setMessageHandler_0 != null)
                 {
                     this.setMessageHandler_0(string.Format("{0}无选中要素,将不导出!", item.AliasName));
                 }
             }
         }
         if (this.finishHander_0 != null)
         {
             this.finishHander_0();
         }
         if (_frmExportProcessEx.IsAutoClose)
         {
             _frmExportProcessEx.Close();
         }
     }
 }