public override void OnClick() { IGxObject firstObject = ((IGxSelection)_context.GxSelection).FirstObject; if (firstObject is IGxFile) { string path = (firstObject as IGxFile).Path; path = (path[path.Length - 1] != '\\' ? string.Concat(path, "\\新建个人数据库") : string.Concat(path, "新建个人数据库")); string str = string.Concat(path, ".mdb"); int num = 1; while (File.Exists(str)) { num++; str = string.Concat(path, " (", num.ToString(), ").mdb"); } IWorkspaceFactory accessWorkspaceFactoryClass = new AccessWorkspaceFactory(); try { IWorkspaceName workspaceName = accessWorkspaceFactoryClass.Create(Path.GetDirectoryName(str), Path.GetFileNameWithoutExtension(str), null, 0); IGxObject gxDatabase = new GxDatabase(); (gxDatabase as IGxDatabase).WorkspaceName = workspaceName; IGxCatalog catalog = GxCatalogCommon.GetCatalog(firstObject); gxDatabase.Attach(firstObject, catalog); catalog.ObjectAdded(gxDatabase); } catch (Exception exception) { MessageBox.Show(exception.Message); } } }
public static IWorkspace CreatePersonGDB(string string_0) { IWorkspace workspace = null; IWorkspaceFactory accessWorkspaceFactoryClass = new AccessWorkspaceFactory(); try { IWorkspaceName workspaceName = accessWorkspaceFactoryClass.Create(System.IO.Path.GetDirectoryName(string_0), System.IO.Path.GetFileNameWithoutExtension(string_0), null, 0); workspace = (workspaceName as IName).Open() as IWorkspace; } catch (COMException cOMException1) { COMException cOMException = cOMException1; int errorCode = cOMException.ErrorCode; MessageBox.Show(string.Concat("错误代码:", errorCode.ToString(), "\r\n", cOMException.Message)); } catch (Exception exception) { } ComReleaser.ReleaseCOMObject(accessWorkspaceFactoryClass); accessWorkspaceFactoryClass = null; return(workspace); }
/// <summary> /// 创建数据库 /// </summary> /// <param name="mdbFolder"></param> /// <param name="mdbName"></param> /// <returns></returns> public IWorkspace CreateMdb(string mdbFolder, string mdbName) { IWorkspaceFactory pFtWsFct = new AccessWorkspaceFactory(); IWorkspaceName workspaceName = pFtWsFct.Create(mdbFolder, mdbName, null, 0); IFeatureWorkspace pFeatureWorkSpace = (workspaceName as IName).Open() as IFeatureWorkspace; IWorkspace pWorkspace = (workspaceName as IName).Open() as IWorkspace; return(pWorkspace); }
public void CreateTempDB() { string str = string.Concat(this.string_0, "\\tempAccess"); this.string_1 = PahtAssistant.GetFinalFileName(str, ".mdb"); IWorkspaceFactory accessWorkspaceFactoryClass = new AccessWorkspaceFactory(); string directoryName = Path.GetDirectoryName(this.string_1); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(this.string_1); this.iworkspaceName_0 = accessWorkspaceFactoryClass.Create(directoryName, fileNameWithoutExtension, null, 0); }
public void CreateTempDB() { string text = this.tmpPath + "\\tempAccess"; this.string_1 = PahtAssistant.GetFinalFileName(text, ".mdb"); IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory(); string directoryName = System.IO.Path.GetDirectoryName(this.string_1); string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(this.string_1); this.iworkspaceName_0 = workspaceFactory.Create(directoryName, fileNameWithoutExtension, null, 0); }
public bool Do() { string path = this.txtOutGDB.Text.Trim(); if (path.Length == 0) { MessageBox.Show("请选择导出位置!"); return(false); } if (!(Path.GetExtension(path).ToLower() == ".mdb")) { MessageBox.Show("请选择正确的导出位置!"); return(false); } if (!File.Exists(path)) { IWorkspaceFactory factory = new AccessWorkspaceFactory(); try { IWorkspaceName name = factory.Create(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path), null, 0); this.txtOutGDB.Tag = name; goto Label_00EC; } catch (Exception exception) { MessageBox.Show(exception.ToString()); return(false); } } IWorkspaceName name2 = new WorkspaceNameClass { WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory", PathName = path }; IWorkspace workspace = (name2 as IName).Open() as IWorkspace; if (!this.method_2(workspace, ExtractionDataHelper.m_pHelper.EnumName)) { return(false); } this.txtOutGDB.Tag = name2; Label_00EC: ExtractionDataHelper.m_pHelper.ReuseSchema = this.chkResueSchema.Checked; ExtractionDataHelper.m_pHelper.CheckOnlySchema = this.rdoType.SelectedIndex == 1; ExtractionDataHelper.m_pHelper.CheckoutWorkspaceName = this.txtOutGDB.Tag as IWorkspaceName; return(true); }
//导入xml工作空间 private void ImportWS(string dbPath, string pGDB, string XmlFile) { IWorkspaceFactory pWSF = new AccessWorkspaceFactory(); IWorkspaceName pWSN = pWSF.Create(dbPath, pGDB, null, 0); IName pName = (IName)pWSN; IWorkspace pWS = (IWorkspace)pName.Open(); //导入库结构 IGdbXmlImport pImporter = new GdbImporter(); IEnumNameMapping pEnumName = null; pImporter.GenerateNameMapping(XmlFile, pWS, out pEnumName); pImporter.ImportWorkspace(XmlFile, pEnumName, pWS, true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWS); }
Thread TH_TimeSpan; //线程 // List<string> LI_AllShapePath = new List<string>();//要导入MDB的所有Shp文件的地址 /// <summary> /// 构造MDB /// </summary> /// <param name="IN_AllShapePath">所有要导入shape的地址</param> /// <param name="IN_MDBPath">要构建的MDB的地址</param> /// <param name="IN_MDBName">要构建的MDB的名称</param> public bool MDB_Builder(string IN_AllShapePath, string IN_MDBPath, string IN_MDBName, string IN_DatasetName) { // LI_AllShapePath = IN_AllShapePath; S_MDBFile = IN_MDBPath + IN_MDBName + ".mdb"; //MDB路径 S_LDBFile = IN_MDBPath + IN_MDBName + ".ldb"; //LDB路径 IWorkspaceFactory Temp_WorkFactory = new AccessWorkspaceFactory(); /* * if (File.Exists(S_MDBFile))//清理MDB和LDB文件 * { * try * { * File.Delete(S_MDBFile); * } * catch (Exception e) { MessageBox.Show(e.Message.ToString()); } * if (File.Exists(S_LDBFile)) * File.Delete(S_LDBFile); * } * Temp_WorkFactory.Create(IN_MDBPath, IN_MDBName, null, 0);//创建一个MDB */ if (File.Exists(S_LDBFile)) { try { File.Delete(S_LDBFile); } catch { } } // if (!File.Exists(S_MDBFile)) { try { Temp_WorkFactory.Create(IN_MDBPath, IN_MDBName, null, 0);//创建一个MDB } catch { } } PRV_CreatFeatureDataset(IN_DatasetName, IN_AllShapePath);//创建要素数据集,以第一个shp文件为空间参考 bool isExists = PRV_AddFeatureClass(IN_AllShapePath);//将每一个shp文件添加进去 return(isExists); }
public static IWorkspace CreatePersonGDB(string string_0) { IWorkspace workspace = null; IWorkspaceFactory o = new AccessWorkspaceFactory(); try { workspace = (o.Create(System.IO.Path.GetDirectoryName(string_0), System.IO.Path.GetFileNameWithoutExtension(string_0), null, 0) as IName).Open() as IWorkspace; } catch (COMException exception) { MessageBox.Show("错误代码:" + exception.ErrorCode.ToString() + "\r\n" + exception.Message); } catch (Exception) { } ComReleaser.ReleaseCOMObject(o); o = null; return(workspace); }
private void EndSave() { if (this.txtName.Text.Trim().Length > 0) { GISDataComboItem selectedItem = this.gisDataComboBox1.SelectedItem as GISDataComboItem; IGxObject tag = selectedItem.Tag as IGxObject; if ((tag != null) && (this._gxObjectFilter != null)) { bool flag = false; string str = this.txtName.Text.Trim(); if (this._gxObjectFilter.CanSaveObject(tag, str, ref flag)) { this._gxObject = tag; this._array2.RemoveAll(); this._gxObjects.Clear(); if (this._gxObjectFilter.Name == "GxFilterWorkspaces") { IWorkspaceName name = null; IGxObject unk = null; unk = new GxDatabase() as IGxObject; name = new WorkspaceName() as IWorkspaceName; string path = (tag as IGxFile).Path + @"\" + str; string str3 = System.IO.Path.GetExtension(path).ToLower(); if (str3 == ".mdb") { name.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory"; } else if ((str3 == ".sde") && flag) { name.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory"; } else { name.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory"; } if (!flag) { if (str3 == ".mdb") { IWorkspaceFactory factory = new AccessWorkspaceFactory() as IWorkspaceFactory; try { factory.Create(System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileNameWithoutExtension(path), null, 0); } catch (Exception exception) { MessageBox.Show(this, exception.Message); } } else { Directory.CreateDirectory(path); } } name.PathName = path; (unk as IGxDatabase).WorkspaceName = name; this._array2.Add(unk); this._gxObjects.Add(unk); } else { if (((tag is IGxFolder) || (tag is IGxDiskConnection)) || (tag is IGxDatabase)) { this._array2.Add(tag); this._gxObjects.Add(tag); } else { if (!(tag is IGxDataset)) { return; } if ((tag as IGxDataset).Type == esriDatasetType.esriDTFeatureDataset) { this._array2.Add(tag); this._gxObjects.Add(tag); } } this._saveName = this.CheckExtension(str, this._gxObjectFilter); } base.DialogResult = DialogResult.OK; if (selectedItem.Tag != null) { _pStartLocation = (selectedItem.Tag as IGxObject).FullName; } base.Close(); } } } }
public override void OnClick() { try { IGeometry geometry = null; if (this._context.FocusMap.SelectionCount >= 1) { IEnumFeature enumFeature = this._context.FocusMap.FeatureSelection as IEnumFeature; enumFeature.Reset(); IFeature feature = enumFeature.Next(); ITopologicalOperator topologicalOperator = null; while (feature != null) { if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { if (topologicalOperator == null) { topologicalOperator = (feature.ShapeCopy as ITopologicalOperator); } else { topologicalOperator = (topologicalOperator.Union(feature.Shape) as ITopologicalOperator); topologicalOperator.Simplify(); } } feature = enumFeature.Next(); } geometry = (topologicalOperator as IGeometry); } else { ITopologicalOperator topologicalOperator = null; IGraphicsContainer graphicsContainer = this._context.FocusMap as IGraphicsContainer; graphicsContainer.Reset(); IElement element = graphicsContainer.Next(); if (element != null) { if (element is IPolygonElement) { if (topologicalOperator == null) { topologicalOperator = (element.Geometry as ITopologicalOperator); } else { topologicalOperator = (topologicalOperator.Union(element.Geometry) as ITopologicalOperator); topologicalOperator.Simplify(); } } element = graphicsContainer.Next(); } geometry = (topologicalOperator as IGeometry); } if (geometry == null && this._context.Hook is IApplication) { geometry = (this._context.Hook as IApplication).BufferGeometry; } if (geometry != null && !geometry.IsEmpty) { geometry.SpatialReference = this._context.FocusMap.SpatialReference; int num = this._subType; if (num != 0) { string str = System.IO.Path.GetTempPath() + "TempPersonGDB"; int num2 = 1; string path = str + ".mdb"; while (File.Exists(path)) { try { File.Delete(path); break; } catch { } num2++; path = str + " (" + num2.ToString() + ").mdb"; } IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory(); IWorkspaceName iworkspaceName_ = workspaceFactory.Create(System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileNameWithoutExtension(path), null, 0); IMap imap_ = new Map(); Clip.ClipMapByRegion(iworkspaceName_, this._context.FocusMap, geometry, imap_); new FormPrinterSetup(); CMapPrinter cMapPrinter; if (this._context.Hook is IApplication) { cMapPrinter = new CMapPrinter(imap_, ApplicationBase.StyleGallery); } else { cMapPrinter = new CMapPrinter(imap_); } cMapPrinter.showPrintUI("打印地图"); } else { new frmDir { FocusMap = this._context.FocusMap, ClipGeometry = geometry }.ShowDialog(); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
public override void OnDblClick() { if (!this.bool_0) { this.idisplayFeedback_0 = null; } else { IGeometry geometry = (this.idisplayFeedback_0 as INewPolygonFeedback).Stop(); this.bool_0 = false; this.idisplayFeedback_0 = null; if (!geometry.IsEmpty) { (geometry as IPolygon).SimplifyPreserveFromTo(); System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; try { geometry.SpatialReference = this._context.FocusMap.SpatialReference; int num = this._subType; if (num != 0) { string str = System.IO.Path.GetTempPath() + "TempPersonGDB"; int num2 = 1; string path = str + ".mdb"; while (File.Exists(path)) { try { File.Delete(path); break; } catch { } num2++; path = str + " (" + num2.ToString() + ").mdb"; } IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory(); IWorkspaceName workspaceName = workspaceFactory.Create( System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileNameWithoutExtension(path), null, 0); IMap imap_ = new Map(); Clip.ExtractSpecifyHRegFeatures(workspaceName, this._context.FocusMap, geometry, imap_); new FormPrinterSetup(); CMapPrinter cMapPrinter; cMapPrinter = new CMapPrinter(imap_); cMapPrinter.showPrintUI("打印地图"); } else { frmOpenFile frmOpenFile = new frmOpenFile(); frmOpenFile.Text = "保存位置"; frmOpenFile.RemoveAllFilters(); frmOpenFile.AddFilter(new MyGxFilterWorkspaces(), true); if (frmOpenFile.DoModalSave() == System.Windows.Forms.DialogResult.OK) { IArray items = frmOpenFile.Items; if (items.Count == 0) { return; } System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; try { IWorkspaceName workspaceName = null; IGxObject gxObject = items.get_Element(0) as IGxObject; if (gxObject is IGxDatabase) { workspaceName = (gxObject.InternalObjectName as IWorkspaceName); } else if (gxObject is IGxFolder) { workspaceName = new WorkspaceName() as IWorkspaceName; workspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory"; workspaceName.PathName = (gxObject.InternalObjectName as IFileName).Path; } if (workspaceName != null) { Clip.ExtractSpecifyHRegFeatures(workspaceName, this._context.FocusMap, geometry); } } catch { } System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } if (this._context.Hook is IApplication) { (this._context.Hook as IApplication).CurrentTool = null; } System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; } } }
public bool Do() { string str = this.txtCheckOutName.Text.Trim(); if (str.Length == 0) { MessageBox.Show("请输入检出名称!"); return(false); } IVersionedWorkspace workspace = (CheckOutHelper.m_pHelper.MasterWorkspaceName as IName).Open() as IVersionedWorkspace; try { if (workspace.FindVersion(str) != null) { MessageBox.Show("主数据库中已存在版本: " + str); return(false); } } catch { } string path = this.txtOutGDB.Text.Trim(); if (path.Length == 0) { MessageBox.Show("请选择检出位置!"); return(false); } if (!(Path.GetExtension(path).ToLower() == ".mdb")) { MessageBox.Show("请选择正确的检出位置!"); return(false); } if (!File.Exists(path)) { IWorkspaceFactory factory = new AccessWorkspaceFactory(); try { IWorkspaceName name = factory.Create(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path), null, 0); this.txtOutGDB.Tag = name; goto Label_016D; } catch (Exception exception) { MessageBox.Show(exception.ToString()); return(false); } } IWorkspaceName name2 = new WorkspaceNameClass { WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory", PathName = path }; IWorkspace workspace2 = (name2 as IName).Open() as IWorkspace; if (!this.method_2(workspace2, CheckOutHelper.m_pHelper.EnumName)) { return(false); } this.txtOutGDB.Tag = name2; Label_016D: CheckOutHelper.m_pHelper.ReuseSchema = this.chkResueSchema.Checked; CheckOutHelper.m_pHelper.CheckOutName = str; CheckOutHelper.m_pHelper.CheckOnlySchema = this.rdoType.SelectedIndex == 1; CheckOutHelper.m_pHelper.CheckoutWorkspaceName = this.txtOutGDB.Tag as IWorkspaceName; return(true); }