/// <summary> /// 如果是文件库则需要创建辅助库体的pdb /// 重载构造函数 /// </summary> /// <param name="MTpath">本地辅助库存放路径</param> public GOFuzingTables(string MTpath) { //创建PDB工作空间 IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass(); FileInfo finfo = new FileInfo(MTpath); string outputDBPath = finfo.DirectoryName; string outputDBName = finfo.Name; if (finfo.Exists) { SysCommon.Error.frmInformation frmInfo = new SysCommon.Error.frmInformation("是", "否", "存在同名的辅助库,是否进行替代?"); if (frmInfo.ShowDialog() == DialogResult.OK) { finfo.Delete(); } else { return; } } //outputDBName = outputDBName.Substring(0, outputDBName.Length - 4); IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create(outputDBPath, outputDBName, null, 0); ESRI.ArcGIS.esriSystem.IName pName = (ESRI.ArcGIS.esriSystem.IName)pWorkspaceName; this._Workspace = (IWorkspace)pName.Open(); this._TempleteWorkspace = OpenTempleteWorkSpace(); }
public bool createMDBFile(string mdbfolderpath, string filename) { // IWorkspace workspace = null; IWorkspaceName workspaceName = null; // IName name = null; try { IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass(); workspaceName = wsf.Create(mdbfolderpath, filename, null, 0); // name = workspaceName as IName; if (workspaceName != null) { return(true); } else { return(false); } } catch (Exception eg) { return(false); } }
public static void CreatePersonalGeodatabase(string destinationPGDBFile) { string pgdbFileName; string pgdbParentDirectory; string pgdbFile; destinationPGDBFile = System.IO.Path.GetFullPath(destinationPGDBFile); pgdbFileName = System.IO.Path.GetFileName(destinationPGDBFile); pgdbParentDirectory = System.IO.Path.GetDirectoryName(destinationPGDBFile); pgdbFile = System.IO.Path.Combine(pgdbParentDirectory, pgdbFileName); IWorkspaceFactory pgdbWSFactory = new AccessWorkspaceFactoryClass(); IWorkspaceName pgdbWorkspaceName; //Create the Access database file if it does not already exist if (!System.IO.File.Exists(pgdbFile)) { try { pgdbWorkspaceName = pgdbWSFactory.Create(pgdbParentDirectory, pgdbFileName, null, 0); } catch (System.Runtime.InteropServices.COMException e) { throw new System.Runtime.InteropServices.COMException("An unexpected error occurred while trying to create a personal geodatabase.", e); } } else { throw new System.IO.IOException("A file with the same name already exists. Unable to create personal geodatabase."); } }
/// <summary> /// 新建工作空间 /// </summary> /// <param name="Location">路径名</param> /// <param name="Name">文件名</param> public bool CreateWorkspace(string Location, string Name) { string strSrcdb = Application.StartupPath + @"\..\Template\DataConvertTemplate.mdb"; //string strCopyPath = Location + @"\" + Name; string strCopyPath = Location + Name; System.IO.FileInfo fSrcFile = new System.IO.FileInfo(strSrcdb); System.IO.FileInfo fileCopy = new System.IO.FileInfo(strCopyPath); if (fSrcFile.Exists) { if (!fileCopy.Exists) { fSrcFile.CopyTo(strCopyPath); } else { MessageBox.Show("数据库重名!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } else { IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass(); pWorkspaceFactory.Create(Location, Name, null, 0); } return(true); }
// // CONSTRUCTOR // public PersonalGeodatabaseValidator() : base() { string tempPath = Path.GetTempPath(); string name = Guid.NewGuid().ToString("N").ToUpper(); IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspaceName workspaceName = workspaceFactory.Create(tempPath, name, null, 0); IWorkspace workspace = (IWorkspace)((IName)workspaceName).Open(); this.SetWorkspace(workspace); }
// // CONSTRUCTOR // public PersonalGeodatabaseValidator() : base() { string tempPath = Path.GetTempPath(); string name = Guid.NewGuid().ToString("N").ToUpper(); IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspaceName workspaceName = workspaceFactory.Create(tempPath, name, null, 0); IWorkspace workspace = (IWorkspace)((IName)workspaceName).Open(); this.SetWorkspace(workspace); }
private void button2_Click(object sender, EventArgs e) { string shpName = Application.StartupPath + "\\Project_Data\\" + comboBox1.SelectedItem.ToString() + ".shp"; string mdbName = textBox1.Text; string FileFullPath = shpName; string pFolder = System.IO.Path.GetDirectoryName(FileFullPath); //可以从文件名里面获取路径 string pFileName = System.IO.Path.GetFileName(FileFullPath); //获取文件名 string mdbFileName = textBox1.Text; string dir = System.IO.Path.GetDirectoryName(mdbFileName); mdbFileName = System.IO.Path.GetFileName(mdbFileName); string Getname = System.IO.Path.GetFileNameWithoutExtension(pFileName); IWorkspaceFactory shpWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IWorkspace workspace = shpWorkspaceFactory.OpenFromFile(pFolder, 0); IFeatureWorkspace featureworkSpace = workspace as IFeatureWorkspace; IFeatureClass shpFeatureClass = featureworkSpace.OpenFeatureClass(Getname); IWorkspaceFactory mdbWorkspaceFactory = new AccessWorkspaceFactoryClass(); if (System.IO.File.Exists(textBox1.Text)) { System.IO.File.Delete(dir + mdbFileName); } IWorkspaceName workspaceName = mdbWorkspaceFactory.Create(dir, mdbFileName, null, 0); IName name = (IName)workspaceName; IWorkspace mdbWorkspace = (IWorkspace)name.Open(); IFeatureWorkspace mdbFeatureWorkspace = mdbWorkspace as IFeatureWorkspace; IFeatureClass newFeatureClass = mdbFeatureWorkspace.CreateFeatureClass(shpFeatureClass.AliasName, shpFeatureClass.Fields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); IFeatureCursor featureCursor = shpFeatureClass.Search(null, true); IFeature feature = featureCursor.NextFeature(); while (feature != null) { IFeature newfeature = newFeatureClass.CreateFeature(); for (int i = 0; i < feature.Fields.FieldCount; i++) { if (feature.Fields.get_Field(i).Editable) { newfeature.set_Value(i, feature.get_Value(i)); } } newfeature.Store(); feature = featureCursor.NextFeature(); } }
/// <summary> /// 创建PGDB数据源 /// </summary> private IWorkspace CreateWorkspace() { IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); int nIndex = m_strFilePathName.LastIndexOf("\\"); string sPath = m_strFilePathName.Remove(nIndex); string sName = m_strFilePathName.Substring(nIndex + 1) ; IWorkspaceName workspaceName = workspaceFactory.Create(sPath, sName, null, 0); // Cast the workspace name object to the IName interface and open the workspace. IName name = (IName)workspaceName; IWorkspace workspace = (IWorkspace)name.Open(); return workspace; }
private void CreateTemporaryGeodatabase() { try { //byte[] bytePath = System.Text.Encoding.Unicode.GetBytes(this.DatabasePath); byte[] bytePath = System.Guid.NewGuid().ToByteArray(); string base64Databasepath = Convert.ToBase64String(bytePath); // System.IO.Path.GetFileNameWithoutExtension(this.DatabasePath) IWorkspaceFactory factory = new AccessWorkspaceFactoryClass(); IWorkspaceName workspaceName = factory.Create(System.IO.Path.GetTempPath(), base64Databasepath, null, 0); this.PGDBPath = System.IO.Path.GetTempPath() + "\\" + base64Databasepath + ".mdb"; } catch { } }
private void Sde2Mdb(IWorkspace pMasterWorkspace, string[] featureClassName, string[] featureDatasetName, string outName, string fileName) { if (File.Exists(fileName)) { File.Delete(fileName); } IPropertySet pCheckOutPropSet = new PropertySetClass(); pCheckOutPropSet.SetProperty("Database", fileName); IWorkspaceFactory pCheckOutWorkFact = new AccessWorkspaceFactoryClass(); string path = System.IO.Path.GetDirectoryName(fileName); IWorkspaceName pCheckOutWorkspaceName = pCheckOutWorkFact.Create(path, outName, pCheckOutPropSet, 0); IName pName = pCheckOutWorkspaceName as IName; IWorkspace pCheckOutWorkspace = pName.Open() as IWorkspace; if (pCheckOutWorkspace != null) { IFeatureWorkspace pMasterFeaWorkspace = pMasterWorkspace as IFeatureWorkspace; IFeatureDataset pFeatureDataset; for (int i = 0; i < featureClassName.Length; i++) { //this.pgbExportstat.PerformStep(); ConvertFeatureClass(pMasterWorkspace, pCheckOutWorkspace, featureClassName[i], featureClassName[i]); } for (int i = 0; i < featureDatasetName.Length; i++) { //this.pgbExportstat.PerformStep(); pFeatureDataset = pMasterFeaWorkspace.OpenFeatureDataset(featureDatasetName[i]); //在本地创建同名要素数据集 IFeatureDataset Temp_LocalDataset = (pCheckOutWorkspace as IFeatureWorkspace).CreateFeatureDataset(featureDatasetName[i], (pFeatureDataset as IGeoDataset).SpatialReference); //批量导入要素类 for (int j = 0; j < (pFeatureDataset as IFeatureClassContainer).ClassCount; j++) { string fcName = ((pFeatureDataset as IFeatureClassContainer).get_Class(j) as IDataset).Name; ConvertFeatureClass(pMasterWorkspace, Temp_LocalDataset, fcName, fcName); } } GC.Collect(); } }
// /// <summary> /// 创建一个新的Geodatabase文件,支持mdb和gdb /// </summary> /// <param name="geodatabasePath"></param> public static void CreateGeodatabase(string geodatabasePath) { IWorkspaceFactory wf = null; switch (System.IO.Path.GetExtension(geodatabasePath).ToUpper()) { case ".GDB": if (Directory.Exists(geodatabasePath)) { throw new Exception("路径" + geodatabasePath + "已经存在,不能创建geodatabase。"); } wf = new FileGDBWorkspaceFactoryClass(); break; case ".MDB": if (File.Exists(geodatabasePath)) { throw new Exception("文件" + geodatabasePath + "已经存在,不能创建geodatabase。"); } wf = new AccessWorkspaceFactoryClass(); break; default: break; } if (wf != null) { string text2 = geodatabasePath.Substring(0, geodatabasePath.LastIndexOf(@"\")); string text1 = geodatabasePath.Substring(geodatabasePath.LastIndexOf(@"\") + 1); text1 = text1.Substring(0, text1.LastIndexOf(".")); IPropertySet set1 = new PropertySetClass(); set1.SetProperty("Database", text2); IWorkspaceName wn = wf.Create(text2, text1, set1, 0); } else { throw new NotSupportedException("不支持传入的文件名。"); } }
/// <summary> /// 创建mdb文件 /// </summary> /// <param name="strMdbFileName">mdb文件绝对</param> public IFeatureWorkspace CreateMdbfile(string strMdbFileName) { //文件不存在 if (!File.Exists(strMdbFileName)) { //test string mdbfileName = Path.GetFileNameWithoutExtension(strMdbFileName); //返回文件名 test.mdb string fileName = Path.GetFileName(strMdbFileName); //返回文件目录 f://temp string fileDirectory = Path.GetDirectoryName(strMdbFileName); if (mdbfileName == "") { return(null); } IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspaceName workspaceName = workspaceFactory.Create(fileDirectory, mdbfileName, null, 0); IName name = workspaceName as IName; IWorkspace iWorkspace = (IWorkspace)name.Open(); // return iWorkspace; IFeatureWorkspace pFeWs = iWorkspace as IFeatureWorkspace; return(pFeWs); this.Close(); this.Dispose(); } else { //文件存在,则打开mdb IWorkspaceFactory pFactory = new AccessWorkspaceFactoryClass(); IWorkspace pWorkspace = pFactory.OpenFromFile(strMdbFileName, 0); IFeatureWorkspace pFeatWorkspace = pWorkspace as IFeatureWorkspace; // IFeatureClass pFeatureClass = pFeatWorkspace.OpenFeatureClass("Water") return(pFeatWorkspace); } }
public static IWorkspace VerificarGDBTemporal(string sRuta) { string sFile = "t_" + DateTime.Now.ToString("yyyyMMdd"); if (System.IO.File.Exists(sRuta + @"\" + sFile + ".mdb")) { try { System.IO.File.Delete(sRuta + @"\" + sFile + ".mdb"); } catch (Exception) { sFile += "_2.mdb"; } } IWorkspaceFactory pFW = new AccessWorkspaceFactoryClass(); IWorkspaceName pWName = pFW.Create(sRuta, sFile, null, 0); IName pName = (IName)pWName; IWorkspace pWorkspace = (IWorkspace)pName.Open(); return(pWorkspace); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { SaveFileDialog dbfiledlg = new SaveFileDialog(); dbfiledlg.Filter = "空间数据库文件(*.mdb)|*.mdb"; dbfiledlg.RestoreDirectory = true; if (dbfiledlg.ShowDialog() == DialogResult.OK) { string localFilePath = dbfiledlg.FileName.ToString(); if (System.IO.File.Exists(localFilePath)) { System.IO.File.Delete(localFilePath); } //获得不带文件名的文件路径 string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\")); //获取文件名,不带路径 string fileNameExt = localFilePath.Substring( localFilePath.LastIndexOf("\\") + 1); string fileName = fileNameExt.Substring(0, fileNameExt.LastIndexOf(".")); IWorkspaceFactory ipWSFactory = new AccessWorkspaceFactoryClass(); if (!File.Exists(localFilePath)) { IWorkspaceName ipWsName = ipWSFactory.Create(FilePath, fileName, null, 0); } IWorkspace ipWorkspace = ipWSFactory.OpenFromFile( localFilePath, 0); //添加函数CreateFeatureClass ISpatialReference ipSr = m_hookHelper.FocusMap.SpatialReference; IFeatureClass ipFeatCls = CreateFeatureClass( ipWorkspace as IFeatureWorkspace, ipSr); IFeatureLayer ipFeatLyr = new FeatureLayerClass(); ipFeatLyr.Name = "polygon"; ipFeatLyr.FeatureClass = ipFeatCls; m_hookHelper.FocusMap.AddLayer(ipFeatLyr); } //IWorkspaceFactory wsFactory = new SdeWorkspaceFactoryClass(); //IPropertySet ps = new PropertySetClass(); //ps.SetProperty("SERVER", "DESKTOP-E7NJ8FE\\SQLEXPRESS"); //ps.SetProperty("INSTANCE", ""); //ps.SetProperty("DATABASE", "SDE"); //ps.SetProperty("USER", "SDE"); //ps.SetProperty("PASSWORD", "123"); ////PublicWorkspace.ipWorkspace = wsFactory.Open(ps, 0); ////IEnumDataset eds = PublicWorkspace.ipWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass); //IWorkspace ipWorkspace = wsFactory.Open(ps, 0); ////IEnumDataset eds = ipWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass); //////if (ps.GetProperty("INSTANCE") != "") //////{ //// IFeatureClass fc = eds.Next() as IFeatureClass; //// IFeatureLayer layer = new FeatureLayerClass(); //// layer.Name ="polygon"; //// layer.FeatureClass = fc; //// m_hookHelper.FocusMap.AddLayer(layer as ILayer); //////} //ISpatialReference ipSr = // m_hookHelper.FocusMap.SpatialReference; //IFeatureClass ipFeatCls = CreateFeatureClass( // ipWorkspace as IFeatureWorkspace, ipSr); //IFeatureLayer ipFeatLyr = new FeatureLayerClass(); //ipFeatLyr.Name = "polygon"; //ipFeatLyr.FeatureClass = ipFeatCls; //m_hookHelper.FocusMap.AddLayer(ipFeatLyr); }
/// <summary> /// ����PGDB����Դ /// </summary> private IWorkspace CreateWorkspace() { IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); int nIndex = m_strFilePathName.LastIndexOf("\\"); string sPath = m_strFilePathName.Remove(nIndex); string sName = m_strFilePathName.Substring(nIndex + 1) ; IWorkspaceName workspaceName = workspaceFactory.Create(sPath, sName, null, 0); // Cast the workspace name object to the IName interface and open the workspace. IName name = (IName)workspaceName; IWorkspace workspace = (IWorkspace)name.Open(); return workspace; }
/// <summary> /// 签出数据 /// </summary> /// <param name="pMasterWorkspace">源工作空间</param> /// <param name="featureClassName">要素类的名字</param> /// <param name="featureDatasetName">数据集的名字</param> /// <param name="checkoutName">版本名称</param> /// <param name="onlySchema">是否只签出结构</param> /// <param name="reuseSchema">是否重用已有的结构</param> /// <param name="fileName">文件名</param> /// <param name="dataExtractionType">数据提取的类型(checkout或只导出数据)</param> /// <param name="replicaModelType">简单图层或与源工作空间结构相同</param> public void CheckOut(IWorkspace pMasterWorkspace, string[] featureClassName, //要素类类的名字 string[] featureDatasetName, //数据集的名字 string checkoutName, bool onlySchema, bool reuseSchema, string fileName, esriDataExtractionType dataExtractionType, esriReplicaModelType replicaModelType) { if (File.Exists(fileName)) { File.Delete(fileName); } bool hasVersion = false; string versionName = System.IO.Path.GetFileNameWithoutExtension(fileName); IEnumVersionInfo pEnumVersionInfo = (pMasterWorkspace as IVersionedWorkspace).Versions; if (pEnumVersionInfo != null) { pEnumVersionInfo.Reset(); IVersionInfo pVersionInfo = pEnumVersionInfo.Next(); while (pVersionInfo != null) { if (pVersionInfo.VersionName == "SDE." + checkoutName) { hasVersion = true; break; } pVersionInfo = pEnumVersionInfo.Next(); } } if (hasVersion) { IVersion pVersion = (pMasterWorkspace as IVersionedWorkspace).FindVersion(versionName); if (pVersion != null) { pVersion.Delete(); } } IPropertySet pCheckOutPropSet = new PropertySetClass(); pCheckOutPropSet.SetProperty("Database", fileName); IWorkspaceFactory pCheckOutWorkFact = new AccessWorkspaceFactoryClass(); string path = System.IO.Path.GetDirectoryName(fileName); IWorkspaceName pCheckOutWorkspaceName = pCheckOutWorkFact.Create(path, checkoutName, pCheckOutPropSet, 0); IName pName = pCheckOutWorkspaceName as IName; IWorkspace pCheckOutWorkspace = pName.Open() as IWorkspace; if (pCheckOutWorkspace != null) { IFeatureWorkspace pMasterFeaWorkspace = pMasterWorkspace as IFeatureWorkspace; IFeatureClass pFeaClass; IFeatureDataset pFeatureDataset; IDataset pDS; IEnumNameEdit pEnumNameEdit = new NamesEnumeratorClass(); IEnumName pEnumName; IReplicaDescription pRepDescription = new ReplicaDescriptionClass(); for (int i = 0; i < featureClassName.Length; i++) { pFeaClass = pMasterFeaWorkspace.OpenFeatureClass(featureClassName[i]); pDS = pFeaClass as IDataset; pEnumNameEdit.Add(pDS.FullName as IName); } for (int i = 0; i < featureDatasetName.Length; i++) { pFeatureDataset = pMasterFeaWorkspace.OpenFeatureDataset(featureDatasetName[i]); pDS = pFeatureDataset as IDataset; pEnumNameEdit.Add(pDS.FullName as IName); } pEnumName = pEnumNameEdit as IEnumName; pRepDescription.Init(pEnumName, pCheckOutWorkspaceName, false, dataExtractionType); pRepDescription.ReplicaModelType = replicaModelType;//简单图层类型或与SDE数据库一样 ICheckOut pCheckOut = new CheckOutClass(); try { pCheckOut.CheckOutData(pRepDescription, true, checkoutName); } catch (Exception ex) { MessageBox.Show("可能是备份的SDE数据没有注册为版本,或者是由于该文件名上次已经作为一个版本号存在数据库中。" + ex.ToString()); } pCheckOutWorkspace = null; GC.Collect(); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add createMDB.OnClick implementation //设定相应格式 SaveFileDialog dbfiledlg = new SaveFileDialog(); dbfiledlg.Filter = "空间数据库文件(*.mdb)|*.mdb"; dbfiledlg.RestoreDirectory = true; //设置格式 if (dbfiledlg.ShowDialog() == DialogResult.OK) { string localFilePath = dbfiledlg.FileName.ToString(); string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\")); //获得不带文件名的文件路径 string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径 //实例化一个数据库 IWorkspaceFactory ipWSFactory = new AccessWorkspaceFactoryClass(); IWorkspaceName ipWsName = ipWSFactory.Create(FilePath, fileNameExt, null, 0); //以name对象方式打开 IName name = (IName)ipWsName; IWorkspace ipWorkspace = (IWorkspace)name.Open(); //创建空间参考和要素集 ISpatialReference ipSr = m_hookHelper.FocusMap.SpatialReference; IFeatureDataset ipFeatDs = ((IFeatureWorkspace)ipWorkspace).CreateFeatureDataset("dataset", ipSr); //设置相应字段和属性 IFields ipFields = new FieldsClass(); ((IFieldsEdit)ipFields).FieldCount_2 = 3; IFieldEdit ipField = new FieldClass(); ((IFieldEdit)ipField).Name_2 = "ObjectID"; ((IFieldEdit)ipField).AliasName_2 = "FID"; ((IFieldEdit)ipField).Type_2 = esriFieldType.esriFieldTypeOID; ((IFieldsEdit)ipFields).set_Field(0, ipField); //Add others miscellaneous text field IFieldEdit ipField2 = new FieldClass(); ((IFieldEdit)ipField2).Name_2 = "SmallInteger"; ((IFieldEdit)ipField2).AliasName_2 = "short"; ((IFieldEdit)ipField2).Type_2 = esriFieldType.esriFieldTypeSmallInteger; ((IFieldsEdit)ipFields).set_Field(1, ipField2); //Make the shape field //it will need a geometry definition, with a spatial reference IGeometryDefEdit ipGeoDef = new GeometryDefClass(); ipGeoDef.SpatialReference_2 = ipSr; ipGeoDef.GeometryType_2 = esriGeometryType.esriGeometryPoint; IFieldEdit ipField3 = new FieldClass(); ((IFieldEdit)ipField3).Name_2 = "Point"; ((IFieldEdit)ipField3).AliasName_2 = "point"; ((IFieldEdit)ipField3).Type_2 = esriFieldType.esriFieldTypeGeometry; ((IFieldEdit)ipField3).GeometryDef_2 = ipGeoDef; ((IFieldsEdit)ipFields).set_Field(2, ipField3); IFeatureClass ipFeatCls = ipFeatDs.CreateFeatureClass("point", ipFields, null, null, esriFeatureType.esriFTSimple, "point", ""); IFeatureLayer ipFeatLyr = new FeatureLayerClass(); ipFeatLyr.Name = "New Point FeatureCls"; ipFeatLyr.FeatureClass = ipFeatCls; m_hookHelper.FocusMap.AddLayer(ipFeatLyr); IGeometryDefEdit ipGeoDef1 = new GeometryDefClass(); ipGeoDef1.SpatialReference_2 = ipSr; ipGeoDef1.GeometryType_2 = esriGeometryType.esriGeometryPolygon; IFieldEdit ipField4 = new FieldClass(); ((IFieldEdit)ipField4).Name_2 = "Polygon"; ((IFieldEdit)ipField4).AliasName_2 = "polygon"; ((IFieldEdit)ipField4).Type_2 = esriFieldType.esriFieldTypeGeometry; ((IFieldEdit)ipField4).GeometryDef_2 = ipGeoDef1; ((IFieldsEdit)ipFields).set_Field(2, ipField4); IFeatureClass ipFeatCls1 = ipFeatDs.CreateFeatureClass("polygon", ipFields, null, null, esriFeatureType.esriFTSimple, "Polygon", ""); IFeatureLayer ipFeatLyr1 = new FeatureLayerClass(); ipFeatLyr1.Name = "New Polygon FeatureCls"; ipFeatLyr1.FeatureClass = ipFeatCls1; m_hookHelper.FocusMap.AddLayer(ipFeatLyr1); //Make the polygon field IGeometryDefEdit ipGeoDef2 = new GeometryDefClass(); ipGeoDef2.SpatialReference_2 = ipSr; ipGeoDef2.GeometryType_2 = esriGeometryType.esriGeometryPolyline; IFieldEdit ipField5 = new FieldClass(); ((IFieldEdit)ipField5).Name_2 = "Line"; ((IFieldEdit)ipField5).AliasName_2 = "line"; ((IFieldEdit)ipField5).Type_2 = esriFieldType.esriFieldTypeGeometry; ((IFieldEdit)ipField5).GeometryDef_2 = ipGeoDef2; ((IFieldsEdit)ipFields).set_Field(2, ipField5); IFeatureClass ipFeatCls2 = ipFeatDs.CreateFeatureClass("line", ipFields, null, null, esriFeatureType.esriFTSimple, "Line", ""); IFeatureLayer ipFeatLyr2 = new FeatureLayerClass(); ipFeatLyr2.Name = "New Line FeatureCls"; ipFeatLyr2.FeatureClass = ipFeatCls2; m_hookHelper.FocusMap.AddLayer(ipFeatLyr2); } }
private IWorkspace GetWksBySetting() { if (this.cboDataType.Tag == null) { return(null); } string strType = this.cboDataType.Tag.ToString(); IWorkspace pTempWks = null; Exception err = null; errorServer.Clear(); errorService.Clear(); errorUser.Clear(); errorPassWord.Clear(); errorVersion.Clear(); errorDataBase.Clear(); try { if (strType == "ARCSDE") { if (txtServer.Text == "") { errorServer.SetError(btnNew, "必填!"); } if (txtService.Text == "") { errorService.SetError(txtService, "必填!"); } if (txtUser.Text == "") { errorUser.SetError(txtUser, "必填!"); } if (txtPassWord.Text == "") { errorPassWord.SetError(txtPassWord, "必填!"); } if (cboVersion.Text == "") { errorVersion.SetError(cboVersion, "必填!"); } if (txtDataBase.Text == "") { errorDataBase.SetError(txtDataBase, "必填!"); return(pTempWks); } pTempWks = SetWorkspace(this.txtServer.Text, this.txtService.Text, this.txtDataBase.Text, this.txtUser.Text, this.txtPassWord.Text, this.cboVersion.Text, out err); } else if (strType == "FGDB") { if (txtServer.Text == "") { errorServer.SetError(btnNew, "必填!"); return(pTempWks); } if (Directory.Exists(this.txtServer.Text)) { pTempWks = SetWorkspace(this.txtServer.Text, WksType.FGDB, out err); } else { if (_Addtag == "New") { string path = txtServer.Text.Substring(0, txtServer.Text.LastIndexOf("\\") + 1); string name = txtServer.Text.Substring(txtServer.Text.LastIndexOf("\\") + 1); IWorkspaceFactory pworkspacefactory = new FileGDBWorkspaceFactoryClass(); IWorkspaceName workspaceName = pworkspacefactory.Create(path, name, null, 0); ESRI.ArcGIS.esriSystem.IName pname = (ESRI.ArcGIS.esriSystem.IName)workspaceName; pTempWks = SetWorkspace(this.txtServer.Text, WksType.FGDB, out err); } } } else if (strType == "PGDB") { if (txtServer.Text == "") { errorServer.SetError(btnNew, "必填!"); return(pTempWks); } if (File.Exists(this.txtServer.Text)) { pTempWks = SetWorkspace(this.txtServer.Text, WksType.PGDB, out err); } else { if (_Addtag == "New") { string path = txtServer.Text.Substring(0, txtServer.Text.LastIndexOf("\\") + 1); string name = txtServer.Text.Substring(txtServer.Text.LastIndexOf("\\") + 1); if (!Directory.Exists(path)) { return(null); } IWorkspaceFactory pworkspacefactory = new AccessWorkspaceFactoryClass(); IWorkspaceName workspaceName = pworkspacefactory.Create(path, name, null, 0); ESRI.ArcGIS.esriSystem.IName pname = (ESRI.ArcGIS.esriSystem.IName)workspaceName; pTempWks = SetWorkspace(this.txtServer.Text, WksType.PGDB, out err); } } } if (pTempWks == null && err != null) { Fan.Common.Error.ErrorHandle.ShowFrmErrorHandle("提示", "无法连接数据库:" + this.txtServer.Text + err.Message); return(null); } } catch (Exception ex) { Fan.Common.Error.ErrorHandle.ShowFrmErrorHandle("提示", "无法连接数据库:" + this.txtServer.Text + " " + ex.Message); } return(pTempWks); }
//根据XML节点获取连接信息 public static object GetDBInfoByXMLNode(XmlElement dbElement, string strPath) { try { string strType = dbElement.GetAttribute("类型"); string strServer = dbElement.GetAttribute("服务器"); string strInstance = dbElement.GetAttribute("服务名"); string strDB = dbElement.GetAttribute("数据库"); if (strPath != "") { strDB = strPath + strDB; } string strUser = dbElement.GetAttribute("用户"); string strPassword = dbElement.GetAttribute("密码"); string strVersion = dbElement.GetAttribute("版本"); IPropertySet pPropSet = null; switch (strType.Trim().ToLower()) { case "pdb": pPropSet = new PropertySetClass(); AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass(); if (!File.Exists(strDB)) { FileInfo filePDB = new FileInfo(strDB); pAccessFact.Create(filePDB.DirectoryName, filePDB.Name, null, 0); } pPropSet.SetProperty("DATABASE", strDB); IWorkspace pdbWorkspace = pAccessFact.Open(pPropSet, 0); pAccessFact = null; return(pdbWorkspace); case "gdb": pPropSet = new PropertySetClass(); FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass(); if (!Directory.Exists(strDB)) { DirectoryInfo dirGDB = new DirectoryInfo(strDB); pFileGDBFact.Create(dirGDB.Parent.FullName, dirGDB.Name, null, 0); } pPropSet.SetProperty("DATABASE", strDB); IWorkspace gdbWorkspace = pFileGDBFact.Open(pPropSet, 0); pFileGDBFact = null; return(gdbWorkspace); case "sde": pPropSet = new PropertySetClass(); IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", strServer); pPropSet.SetProperty("INSTANCE", strInstance); pPropSet.SetProperty("DATABASE", strDB); pPropSet.SetProperty("USER", strUser); pPropSet.SetProperty("PASSWORD", strPassword); pPropSet.SetProperty("VERSION", strVersion); IWorkspace sdeWorkspace = pSdeFact.Open(pPropSet, 0); pSdeFact = null; return(sdeWorkspace); case "access": System.Data.Common.DbConnection dbCon = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDB); dbCon.Open(); return(dbCon); case "oracle": string strOracle = "Data Source=" + strDB + ";Persist Security Info=True;User ID=" + strUser + ";Password="******";Unicode=True"; System.Data.Common.DbConnection dbConoracle = new OracleConnection(strOracle); dbConoracle.Open(); return(dbConoracle); case "sql": string strSql = "Data Source=" + strDB + ";Initial Catalog=" + strInstance + ";User ID=" + strUser + ";Password=" + strPassword; System.Data.Common.DbConnection dbConsql = new SqlConnection(strSql); dbConsql.Open(); return(dbConsql); default: break; } return(null); } catch (Exception e) { //******************************************************************* //guozheng added if (ModuleData.v_SysLog != null) { ModuleData.v_SysLog.Write(e, null, DateTime.Now); } else { ModuleData.v_SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModuleData.v_SysLog.Write(e, null, DateTime.Now); } //******************************************************************** return(null); } }
private void btnOk_Click(object sender, EventArgs e) { if (listViewEx.CheckedItems.Count == 0) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未选择对象,无法生成历史!"); return; } Exception err = null; //获取现势库连接信息 SysCommon.Gis.SysGisDataSet sourceSysGisDataSet = new SysCommon.Gis.SysGisDataSet(); switch (comBoxType.Text) { case "SDE": sourceSysGisDataSet.SetWorkspace(txtServer.Text, txtInstance.Text, txtDB.Text, txtUser.Text, txtPassword.Text, txtVersion.Text, out err); break; case "GDB": sourceSysGisDataSet.SetWorkspace(txtDB.Text, SysCommon.enumWSType.GDB, out err); break; case "PDB": sourceSysGisDataSet.SetWorkspace(txtDB.Text, SysCommon.enumWSType.PDB, out err); break; default: break; } if (err != null || sourceSysGisDataSet.WorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未设置用户数据库连接或连接失败,请检查!"); return; } //获取历史库连接信息 IPropertySet pPropSet = new PropertySetClass(); IWorkspace pTagetWorkspace = null; try { switch (comboBoxTypeHistory.Text) { case "PDB": AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass(); if (!File.Exists(txtDBHistory.Text)) { FileInfo filePDB = new FileInfo(txtDBHistory.Text); pAccessFact.Create(filePDB.DirectoryName, filePDB.Name, null, 0); } pPropSet.SetProperty("DATABASE", txtDBHistory.Text); pTagetWorkspace = pAccessFact.Open(pPropSet, 0); break; case "GDB": FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass(); DirectoryInfo dirGDB = new DirectoryInfo(txtDBHistory.Text); pFileGDBFact.Create(dirGDB.Parent.FullName, dirGDB.Name.Substring(0, dirGDB.Name.Length - 4), null, 0); pPropSet.SetProperty("DATABASE", txtDBHistory.Text); pTagetWorkspace = pFileGDBFact.Open(pPropSet, 0); break; case "SDE": IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass(); pPropSet.SetProperty("SERVER", txtServerHistory.Text); pPropSet.SetProperty("INSTANCE", txtInstanceHistory.Text); pPropSet.SetProperty("DATABASE", txtDBHistory.Text); pPropSet.SetProperty("USER", txtUserHistory.Text); pPropSet.SetProperty("PASSWORD", txtPasswordHistory.Text); pPropSet.SetProperty("VERSION", txtVersionHistory.Text); pTagetWorkspace = pSdeFact.Open(pPropSet, 0); break; default: break; } } catch (Exception er) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(er, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(er, null, DateTime.Now); } //******************************************************************** } if (pTagetWorkspace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未设置历史库连接或连接失败,请检查!"); return; } this.Cursor = System.Windows.Forms.Cursors.AppStarting; List <string> lstData = new List <string>(); try { //根据用户数据库结构创建历史库 foreach (ListViewItem aItem in listViewEx.CheckedItems) { if (aItem.Tag.ToString() == "FD") { IFeatureDataset tagetFeatureDataset = null; IFeatureDataset pFeatureDataset = sourceSysGisDataSet.GetFeatureDataset(aItem.Text, out err); if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureDataset, aItem.Text + "_GOH")) { tagetFeatureDataset = (pTagetWorkspace as IFeatureWorkspace).CreateFeatureDataset(aItem.Text + "_GOH", (pFeatureDataset as IGeoDataset).SpatialReference); } else { tagetFeatureDataset = (pTagetWorkspace as IFeatureWorkspace).OpenFeatureDataset(aItem.Text + "_GOH"); } IEnumDataset pEnumDs = pFeatureDataset.Subsets; pEnumDs.Reset(); IDataset pDs = pEnumDs.Next(); while (pDs != null) { IFeatureClass pFeatureClass = pDs as IFeatureClass; if (pFeatureClass != null) { if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, pDs.Name + "_GOH")) { CreateFeatCls(tagetFeatureDataset, pFeatureClass, pDs.Name + "_GOH", out err); } lstData.Add(pDs.Name); } pDs = pEnumDs.Next(); } } else if (aItem.Tag.ToString() == "FC") { IFeatureClass pFeatureClass = sourceSysGisDataSet.GetFeatureClass(aItem.Text, out err); if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, aItem.Text + "_GOH")) { CreateFeatCls(pTagetWorkspace as IFeatureWorkspace, pFeatureClass, aItem.Text + "_GOH", out err); } lstData.Add(aItem.Text); } } } catch (Exception er) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(er, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(er, null, DateTime.Now); } //******************************************************************** this.Cursor = System.Windows.Forms.Cursors.Default; SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建历史库结构失败!"); return; } //遍历现势库数据FC进行数据移植 Dictionary <string, string> dicFieldsPair = new Dictionary <string, string>(); dicFieldsPair.Add("OBJECTID", "SourceOID"); Dictionary <string, object> dicValue = new Dictionary <string, object>(); dicValue.Add("FromDate", DateTime.Now.ToString("u")); dicValue.Add("ToDate", DateTime.MaxValue.ToString("u"));//.ToString("YYYY-MM-DD HH:MI:SS")); dicValue.Add("State", 0); (pTagetWorkspace as IWorkspaceEdit).StartEditing(false); bool res = true; progressBarXLay.Maximum = lstData.Count; progressBarXLay.Minimum = 0; progressBarXLay.Value = 0; foreach (string aFeatClsName in lstData) { labelXMemo.Text = "正在进行图层" + aFeatClsName + "..."; Application.DoEvents(); int cnt = 0; int allcnt = 0; IFeatureCursor featureCursor = null; IFeatureClass tagetFeatCls = null; try { featureCursor = sourceSysGisDataSet.GetFeatureCursor(aFeatClsName, "", null, "", out err, out cnt, out allcnt); tagetFeatCls = (pTagetWorkspace as IFeatureWorkspace).OpenFeatureClass(aFeatClsName + "_GOH"); } catch (Exception ex) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(ex, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(ex, null, DateTime.Now); } //******************************************************************** SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message); return; } progressBarXFeat.Maximum = cnt; progressBarXFeat.Minimum = 0; progressBarXFeat.Value = 0; ModDBOperator.NewFeatures(tagetFeatCls, featureCursor, dicFieldsPair, dicValue, true, false, progressBarXFeat, out err); Marshal.ReleaseComObject(featureCursor); progressBarXLay.Value++; labelXMemo.Text = ""; Application.DoEvents(); if (err != null) { res = false; break; } } (pTagetWorkspace as IWorkspaceEdit).StopEditing(res); this.Cursor = System.Windows.Forms.Cursors.Default; if (res) { if (m_DbProjectElement != null) { try { XmlElement aElement = m_DbProjectElement.SelectSingleNode(".//内容//历史库//连接信息") as XmlElement; SaveObjDB(aElement, listViewEx.Items[0].Text + "_GOH"); } catch (Exception er) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(er, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(er, null, DateTime.Now); } //******************************************************************** return; } } SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "生成历史库成功!"); this.Close(); } else { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "生成历史库失败!"); } }
private void btnOk_Click(object sender, EventArgs e) { if (txtProjectName.Text == "") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请填写输出文件名称 !"); return; } if (!Directory.Exists(txtSavePath.Text.Trim())) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请选择保存路径 !"); return; } if (listViewEx.CheckedItems.Count == 0) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请选择数据版本信息 !"); return; } string WorkSpacePath = txtSavePath.Text.Trim() + "\\" + txtProjectName.Text.Trim(); IPropertySet pPropSet = new PropertySetClass(); IWorkspace pTagetWorkspace = null; try { switch (comBoxType.Tag.ToString().Trim()) { case "PDB": AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass(); if (!File.Exists(WorkSpacePath + ".mdb")) { pAccessFact.Create(txtSavePath.Text, txtProjectName.Text, null, 0); } pPropSet.SetProperty("DATABASE", WorkSpacePath + ".mdb"); pTagetWorkspace = pAccessFact.Open(pPropSet, 0); pAccessFact = null; pPropSet = null; break; case "GDB": FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass(); if (!Directory.Exists(WorkSpacePath + ".gdb")) { pFileGDBFact.Create(txtSavePath.Text, txtProjectName.Text, null, 0); } pPropSet.SetProperty("DATABASE", WorkSpacePath + ".gdb"); pTagetWorkspace = pFileGDBFact.Open(pPropSet, 0); pFileGDBFact = null; pPropSet = null; break; default: break; } } catch (Exception er) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(er, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(er, null, DateTime.Now); } //******************************************************************** } if (pTagetWorkspace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未设置输出库连接或连接失败,请检查!"); return; } this.Cursor = System.Windows.Forms.Cursors.AppStarting; Exception err = null; bool res = true; List <IFeatureLayer> lstFeatLay = new List <IFeatureLayer>(); //根据历史图层创建输出数据图层结构 for (int i = 0; i < Map.LayerCount; i++) { //cyf 20110706 add ILayer mLayer = Map.get_Layer(i); if (mLayer is IGroupLayer) { ICompositeLayer pComLayer = mLayer as ICompositeLayer; for (int j = 0; j < pComLayer.Count; j++) { IFeatureLayer featLay = pComLayer.get_Layer(j) as IFeatureLayer; if (featLay == null) { continue; } if (!(featLay.FeatureClass as IDataset).Name.EndsWith("_GOH")) { continue; } lstFeatLay.Add(featLay); if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, featLay.Name))//(featLay.FeatureClass as IDataset).Name { if (!CreateFeatCls(pTagetWorkspace as IFeatureWorkspace, featLay.FeatureClass, featLay.Name, out err)) { res = false; featLay = null; pComLayer = null; mLayer = null; break; } } } }//end else { IFeatureLayer featLay = Map.get_Layer(i) as IFeatureLayer; if (featLay == null) { continue; } if (!(featLay.FeatureClass as IDataset).Name.EndsWith("_GOH")) { continue; } lstFeatLay.Add(featLay); if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, featLay.Name))//(featLay.FeatureClass as IDataset).Name { if (!CreateFeatCls(pTagetWorkspace as IFeatureWorkspace, featLay.FeatureClass, featLay.Name, out err)) { res = false; featLay = null; mLayer = null; break; } } } } if (res == false) { this.Cursor = System.Windows.Forms.Cursors.Default; SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建输出库结构失败!"); System.Runtime.InteropServices.Marshal.ReleaseComObject(pTagetWorkspace); pTagetWorkspace = null; lstFeatLay.Clear(); lstFeatLay = null; try { Directory.Delete(txtSavePath.Text + "\\" + txtProjectName.Text + ".gdb", true); } catch (Exception err2) { } return; } StringBuilder sb = new StringBuilder(); foreach (ListViewItem aItem in listViewEx.CheckedItems) { if (sb.Length != 0) { sb.Append("or"); } else { sb.Append("("); } sb.Append("(FromDate<='" + aItem.Text + "' and ToDate>'" + aItem.Text + "')"); } sb.Append(")"); //遍历数据FC进行数据移植 (pTagetWorkspace as IWorkspaceEdit).StartEditing(false); progressBarXLay.Maximum = lstFeatLay.Count; progressBarXLay.Minimum = 0; progressBarXLay.Value = 0; foreach (IFeatureLayer aFeatLay in lstFeatLay) { labelXMemo.Text = aFeatLay.FeatureClass.AliasName + "..."; Application.DoEvents(); StringBuilder newSB = new StringBuilder(); newSB.Append(sb.ToString()); if (m_Sel) { int fdIndex = aFeatLay.FeatureClass.Fields.FindField("SourceOID"); if (fdIndex == -1) { continue; } IFeatureLayerDefinition featLayDefTemp = aFeatLay as IFeatureLayerDefinition; IEnumIDs pEnumIDs = featLayDefTemp.DefinitionSelectionSet.IDs; int ID = pEnumIDs.Next(); StringBuilder sbTemp = new StringBuilder(); while (ID != -1) { IFeature pFeat = aFeatLay.FeatureClass.GetFeature(ID); if (sbTemp.Length != 0) { sbTemp.Append(","); } sbTemp.Append(pFeat.get_Value(fdIndex).ToString()); ID = pEnumIDs.Next(); } newSB.Append(" and SourceOID in (" + sbTemp.ToString() + ")"); } IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = newSB.ToString(); IFeatureCursor featureCursor = aFeatLay.FeatureClass.Search(queryFilter, false); progressBarXFeat.Maximum = aFeatLay.FeatureClass.FeatureCount(queryFilter); progressBarXFeat.Minimum = 0; progressBarXFeat.Value = 0; try { //cyf 20110706 modify:去掉用户名 string pFeaLayerName = aFeatLay.Name.Trim(); if (pFeaLayerName.Contains(".")) { pFeaLayerName = pFeaLayerName.Substring(pFeaLayerName.IndexOf('.') + 1); } //end IFeatureClass tagetFeatCls = (pTagetWorkspace as IFeatureWorkspace).OpenFeatureClass(pFeaLayerName);//(aFeatLay.FeatureClass as IDataset).Name ModDBOperator.NewFeatures(tagetFeatCls, featureCursor, null, null, true, false, progressBarXFeat, out err); } catch (Exception ex) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(ex, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(ex, null, DateTime.Now); } //******************************************************************** SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "入库失败!"); return; } Marshal.ReleaseComObject(featureCursor); progressBarXLay.Value++; labelXMemo.Text = ""; Application.DoEvents(); if (err != null) { res = false; break; } } (pTagetWorkspace as IWorkspaceEdit).StopEditing(res); this.Cursor = System.Windows.Forms.Cursors.Default; if (res) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "提取成功!"); this.Close(); } else { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "提取失败!"); } }
private void sure_Click(object sender, EventArgs e) { double rad = Convert.ToDouble(radius.Text); string temp_path = FilePath; string layer_name = layers.Text; ILayer choose = null; IFeatureLayer lidan = null; ILayer temp_lay; for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) { temp_lay = (IFeatureLayer)m_hookHelper.FocusMap.get_Layer(i); if (temp_lay.Name == layer_name) { choose = temp_lay; } } IWorkspaceFactory ipWSFactory = new AccessWorkspaceFactoryClass(); IWorkspaceName ipWsName = ipWSFactory.Create(FilePath, name, null, 0); IWorkspace ipWorkspace = ipWSFactory.OpenFromFile( need + name + ".mdb", 0); ISpatialReference ipSr = m_hookHelper.FocusMap.SpatialReference; IFeatureClass temp = CreateFeatureClass(ipWorkspace as IFeatureWorkspace, ipSr); lidan = choose as IFeatureLayer; IFeatureClass lidan1 = lidan.FeatureClass; IQueryFilter queryFilterlast = new QueryFilterClass(); IFeatureCursor pFCursor; IFeature feature; queryFilterlast.WhereClause = null; pFCursor = lidan1.Search(queryFilterlast, false); feature = pFCursor.NextFeature(); while (feature != null) { ITopologicalOperator to = feature.Shape as ITopologicalOperator; IPolygon poly = to.Buffer(rad) as IPolygon; IFeature polyFeature = temp.CreateFeature(); polyFeature.Shape = poly; feature = pFCursor.NextFeature() as IFeature; polyFeature.Store(); } change(temp, temp_path); }