/// <summary> /// Opens a dialog so the user can select an output workspace. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void outputWorkspaceButton_Click(object sender, EventArgs e) { try { IGxObjectFilter geodatabaseFilter = new GxFilterFileGeodatabasesClass(); IGxDialog dlg = new GxDialogClass(); IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg; filters.AddFilter(geodatabaseFilter, false); dlg.Title = "Select the file geodatabase for the output"; dlg.ButtonCaption = "Select"; IEnumGxObject objects = null; if (dlg.DoModalOpen(0, out objects)) { IGxObject obj = objects.Next(); IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass(); IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(obj.FullName, 0); _transform.SetWorkspace(workspace); outputWorkspaceTextBox.Text = obj.Name; EnableSave(); } } catch (Exception ex) { ShowError(ex.Message); } }
/// <summary> /// Opens a dialog so the user can select a dataset containing the new data to be transformed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void inputDatasetButton_Click(object sender, EventArgs e) { try { IGxObjectFilter datasetFilter = new GxFilterFeatureDatasetsClass(); IGxDialog dlg = new GxDialogClass(); IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg; filters.AddFilter(datasetFilter, true); dlg.Title = "Select the feature dataset containing the data to be transformed"; dlg.ButtonCaption = "Select"; IEnumGxObject objects = null; if (dlg.DoModalOpen(0, out objects)) { IGxObject obj = objects.Next(); _inputDatasetName = (IFeatureDatasetName2)obj.InternalObjectName; inputDatasetTextBox.Text = obj.Parent.Name + "/" + obj.Name; List <IDatasetName> fcNames = EsriUtilities.GetFeatureClassNames(esriGeometryType.esriGeometryPoint, _inputDatasetName); fcNames.Sort(_nameComparer); controlPointsComboBox.DataSource = fcNames; controlPointsComboBox.DisplayMember = "Name"; EnableSave(); } } catch (Exception ex) { ShowError(ex.Message); } }
private void button4_Click(object sender, EventArgs e) { IGxDialog gxd = new GxDialog(); gxd.AllowMultiSelect = false; gxd.ButtonCaption = "Add"; gxd.Title = "Add a shapefile"; gxd.RememberLocation = true; IGxObjectFilter filter1 = new GxFilterFileGeodatabases(); IGxObjectFilter filter2 = new GxFilterTables(); IGxObjectFilterCollection filters = gxd as IGxObjectFilterCollection; filters.AddFilter(filter1, true); filters.AddFilter(filter2, false); IEnumGxObject enumObj; if (gxd.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false) // show dialog { return; // return if clicking on cancel } IGxObject gxObj = enumObj.Next(); int len1 = gxObj.FullName.Length; int len2 = gxObj.Name.Length; string shpPath = gxObj.FullName.Substring(0, len1 - len2); string shpPath2 = gxObj.FullName.Substring(0); IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument; textBox4.Text = shpPath2; population = shpPath2; }
private IGxObject AddExistingFilters() { IEnumGxObject enumGxObject = null; IGxObjectFilter gxObjectFilter_Fabrics = new GxFilterCadastralFabricsClass(); IGxDialog gxDialog = new GxDialogClass(); IGxObjectFilterCollection gxObjectFilterCollection = (IGxObjectFilterCollection)gxDialog; gxObjectFilterCollection.AddFilter(gxObjectFilter_Fabrics, true); gxDialog.Title = "Browse Fabrics"; gxDialog.DoModalOpen(0, out enumGxObject); return(enumGxObject.Next()); }
/// <summary> /// Opens a dialog so the user can select a workspace. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonOutWS_Click(object sender, EventArgs e) { try { IGxObjectFilter wsFilter = new GxFilterWorkspacesClass(); IGxDialog dlg = new GxDialogClass(); IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg; filters.AddFilter(wsFilter, false); dlg.Title = "Select File Geodatabase or Shapefile Folder"; dlg.ButtonCaption = "Select"; IEnumGxObject objects = null; if (dlg.DoModalOpen(0, out objects)) { IGxObject obj = objects.Next(); IWorkspaceFactory2 workspaceFactory; if (obj.Category == "File Geodatabase") { workspaceFactory = new FileGDBWorkspaceFactoryClass(); } else if (obj.Category == "Folder") { workspaceFactory = new ShapefileWorkspaceFactoryClass(); } else { ShowError("Not a file geodatabase or shapefile folder."); return; } IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(obj.FullName, 0); _transform.SetWorkspace(workspace); textBoxOutWS.Text = obj.BaseName; _workspaceOK = true; List <IDatasetName> allNames = _transform.GetFeatureClassNames(); listViewData.Items.Clear(); for (int i = 0; i < allNames.Count; i++) { AddItemToListViewData(allNames[i]); } FillControlComboBox(); SelectComboBoxItem(comboBoxControlPts, _transform.GetWorkspacePath(), "Control_Points_Unprojected"); } EnableSelectInputs(); } catch (Exception ex) { ShowError(ex.Message); } }
private void Browse(object o) { //' allows the user to specify the output shapefile path and name. IGxDialog pGxDialog = new GxDialog(); object obj = o; IGxObjectFilterCollection FilterCol = (IGxObjectFilterCollection)pGxDialog; FilterCol.AddFilter(new GxFilterShapefiles(), true); FilterCol.AddFilter(new GxFilterRasterDatasets(), false); switch (o.ToString()) { case "OutputBrws": if (ShowSaveFileDialog(pGxDialog, out m_Path, out m_Name, out m_GenericName, out m_DatasetType)) { OutputFilePath = m_Path; OutputFileName = m_Name; OutPutFeatureClass = OutputFilePath + "\\" + OutputFileName; OutputFileNameGeneric = m_GenericName; OutputDatasetType = m_DatasetType; } break; case "SHPBrws": // If Not ShowOpenFileDialog() if (ShowOpenFileDialog(pGxDialog, out m_Path, out m_Name, out m_GenericName, out m_DatasetType)) { IFeatureClass FeatClass; IGeoDataset GeoDataset; ShapeFilePath = m_Path; ShapeFileName = m_Name; ShpPath = ShapeFilePath + "/" + ShapeFileName; ShapeFileNameGeneric = m_GenericName; FeatClass = OpenShapefile(ShapeFilePath, ShapeFileNameGeneric, windowHandle.ToInt32()); GeoDataset = (IGeoDataset)FeatClass; ExtentDataLeft = GeoDataset.Extent.XMin; ExtentDataRight = GeoDataset.Extent.XMax; ExtentDataBottom = GeoDataset.Extent.YMin; ExtentDataTop = GeoDataset.Extent.YMax; GeoDataset = null; FeatClass = null; } break; } }
private void button2_Click(object sender, EventArgs e) { IGxDialog gxd = new GxDialog(); gxd.AllowMultiSelect = false; gxd.ButtonCaption = "Add"; gxd.Title = "Add a shapefile"; gxd.RememberLocation = true; IGxObjectFilter filter1 = new GxFilterFileGeodatabases(); IGxObjectFilter filter2 = new GxFilterShapefiles(); IGxObjectFilterCollection filters = gxd as IGxObjectFilterCollection; filters.AddFilter(filter1, true); filters.AddFilter(filter2, false); IEnumGxObject enumObj; if (gxd.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false) // show dialog { return; // return if clicking on cancel } IGxObject gxObj = enumObj.Next(); int len1 = gxObj.FullName.Length; int len2 = gxObj.Name.Length; string shpPath = gxObj.FullName.Substring(0, len1 - len2); string shpPath2 = gxObj.FullName.Substring(0); IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument; IWorkspaceFactory wsf = new ShapefileWorkspaceFactory(); IWorkspace ws = wsf.OpenFromFile(shpPath, 0); IFeatureWorkspace fws = ws as IFeatureWorkspace; IFeatureClass featureClass = fws.OpenFeatureClass(gxObj.BaseName); IFeatureLayer featureLayer = new FeatureLayer(); featureLayer.FeatureClass = featureClass; ILayer layer = (ILayer)featureLayer; layer.Name = gxObj.BaseName; mxdoc.AddLayer(layer); mxdoc.ActiveView.Refresh(); mxdoc.UpdateContents(); textBox2.Text = shpPath2; tracts = shpPath2; }
public static GCDConsoleLib.Vector BrowseOpenVector(string formTitle, System.IO.DirectoryInfo diWorkspace, string sFCName, BrowseGISTypes eType, IntPtr hParentWindowHandle) { IGxDialog pGxDialog = new GxDialogClass(); IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog; switch (eType) { case BrowseGISTypes.Point: pFilterCol.AddFilter(new GxFilterPointFeatureClasses(), true); break; case BrowseGISTypes.Line: pFilterCol.AddFilter(new GxFilterPolylineFeatureClasses(), true); break; case BrowseGISTypes.Polygon: pFilterCol.AddFilter(new GxFilterPolygonFeatureClasses(), true); break; default: pFilterCol.AddFilter(new GxFilterFeatureClasses(), true); break; } IEnumGxObject pEnumGx = null; IGxObject pGxObject = null; pGxDialog.RememberLocation = true; pGxDialog.AllowMultiSelect = false; pGxDialog.Title = formTitle; pGxDialog.ButtonCaption = "Select"; if (diWorkspace != null && diWorkspace.Exists) { object existingDirectory = diWorkspace.FullName; pGxDialog.set_StartingLocation(ref existingDirectory); } pGxDialog.Name = sFCName; GCDConsoleLib.Vector gResult = null; try { if (pGxDialog.DoModalOpen(hParentWindowHandle.ToInt32(), out pEnumGx)) { pGxObject = pEnumGx.Next(); sFCName = pGxObject.BaseName; gResult = new GCDConsoleLib.Vector(new System.IO.FileInfo(pGxObject.FullName)); } } catch (Exception ex) { throw new Exception("Error attempting to browse for vector GIS data source", ex); } return(gResult); }
public static string BrowseSaveRaster(string formTitle, IntPtr hParentWindowHandle, string sWorkspace = null, string sName = null) { IGxDialog pGxDialog = new GxDialog(); IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog; pFilterCol.AddFilter(new GxFilterRasterDatasets(), true); pGxDialog.RememberLocation = true; pGxDialog.AllowMultiSelect = false; pGxDialog.Title = formTitle; if (!string.IsNullOrEmpty(sWorkspace)) { pGxDialog.set_StartingLocation(sWorkspace); } if (sWorkspace is string) { sWorkspace = string.Empty; } if (sName is string) { sName = string.Empty; } string sResult = string.Empty; try { if (pGxDialog.DoModalSave(hParentWindowHandle.ToInt32())) { sWorkspace = pGxDialog.FinalLocation.FullName; sName = pGxDialog.Name; sResult = System.IO.Path.Combine(sWorkspace, sName); } } catch (Exception ex) { ex.Data["Title"] = formTitle; ex.Data["Folder"] = sWorkspace; ex.Data["Name"] = sName; throw; } return(sResult); }
/// <summary> /// Initialize the OpenRasterFileDialog. /// </summary> /// <param name="type">Type of the file dialog.</param> public RasterFileDialog(FileDialogType type) { dialog = new GxDialogClass(); IGxObjectFilterCollection filterCollection = (IGxObjectFilterCollection)dialog; IGxObjectFilter objectFilter = new RasterFormatTifFilter(); filterCollection.AddFilter(objectFilter, true); objectFilter = new RasterFormatBMPFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatENVIFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatBILFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatBIPFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatBSQFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatGIFFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatGridFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatImgFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatJP2Filter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatJPGFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatPNGFilter(); filterCollection.AddFilter(objectFilter, false); this.type = type; switch (type) { case FileDialogType.Save: this.Title = "Save Raster Layer as"; break; case FileDialogType.Open: this.Title = "Open Raster Layer"; break; } }
private void ConvertToGxObjectFilterCollection(IGxDialog gxDialog, string filter) { IGxObjectFilterCollection filterCollection = gxDialog as IGxObjectFilterCollection; if (filterCollection == null) { return; } if (filter.ToUpper().Contains(".MDB")) { IGxObjectFilter objectFilter = new GxFilterPersonalGeodatabasesClass(); filterCollection.AddFilter(objectFilter, true); } if (filter.ToUpper().Contains(".GDB")) { IGxObjectFilter objectFilter = new GxFilterFileGeodatabasesClass(); filterCollection.AddFilter(objectFilter, true); } }
public static GCDConsoleLib.Raster BrowseOpenRaster(string sFormTitle, System.IO.DirectoryInfo diWorkspace, string sName, IntPtr hParentWindowHandle) { IGxDialog pGxDialog = new GxDialogClass(); IGxObjectFilter pRasterFilter = new GxFilterRasterDatasets(); IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog; pFilterCol.AddFilter(pRasterFilter, true); pGxDialog.RememberLocation = true; pGxDialog.AllowMultiSelect = false; pGxDialog.Title = sFormTitle; IEnumGxObject pEnumGx = null; IGxObject pGxObject = null; if (diWorkspace is System.IO.DirectoryInfo && diWorkspace.Exists) { pGxDialog.set_StartingLocation(diWorkspace.FullName); } GCDConsoleLib.Raster rResult = null; try { if (pGxDialog.DoModalOpen(hParentWindowHandle.ToInt32(), out pEnumGx)) { pGxObject = pEnumGx.Next(); System.IO.FileInfo sFile = new System.IO.FileInfo(pGxObject.FullName); sName = pGxObject.Name; diWorkspace = sFile.Directory; rResult = new GCDConsoleLib.Raster(new System.IO.FileInfo(pGxObject.FullName)); } } catch (Exception ex) { ex.Data["Title"] = sFormTitle; ex.Data["Name"] = sName; throw; } return(rResult); }
public static IFeatureClass SelectFeatureClassDialog(List <IGxObjectFilter> gxFilters) { IGxDialog pGxDialog = new GxDialogClass(); IGxObjectFilterCollection pFilterCol = pGxDialog as IGxObjectFilterCollection; foreach (IGxObjectFilter gxObjectFilter in gxFilters) { pFilterCol.AddFilter(gxObjectFilter, true); } pGxDialog.AllowMultiSelect = false; pGxDialog.RememberLocation = true; IEnumGxObject pEnumGxObject; if (pGxDialog.DoModalOpen(0, out pEnumGxObject)) { IGxObject pSelectGxObject = pEnumGxObject.Next(); IGxDataset pGxDataset = (IGxDataset)pSelectGxObject; return(pGxDataset.Dataset as IFeatureClass); } return(null); }
public static IGxObject SelectWorkspaceAndDatasetDialog() { IGxDialog pGxDialog = new GxDialogClass(); IGxObjectFilterCollection pCollection = pGxDialog as IGxObjectFilterCollection; pCollection.AddFilter(new GxFilterWorkspacesClass(), true); pCollection.AddFilter(new GxFilterDatasetsClass(), false); IEnumGxObject pEnumGxObject; pGxDialog.Title = "选择数据"; pGxDialog.AllowMultiSelect = false; if (pGxDialog.DoModalOpen(0, out pEnumGxObject)) { IGxObject pGxObject = pEnumGxObject.Next(); if (pGxDialog != null) { return(pGxObject); } } return(null); }
/// <summary> /// Opens a dialog so the user can select an existing shapefile or file geodatabase /// feature class. /// </summary> /// <param name="title">title for dialog</param> /// <returns>dataset name object for the selected feature class or null </returns> private IDatasetName SelectFeatureClass(string title, esriGeometryType geom) { try { IGxObjectFilter shpFilter = new GxFilterShapefilesClass(); IGxObjectFilter gdbFilter = new GxFilterFGDBFeatureClassesClass(); IGxDialog dlg = new GxDialogClass(); IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg; filters.AddFilter(shpFilter, false); filters.AddFilter(gdbFilter, true); dlg.Title = title; IDatasetName dsName = null; IEnumGxObject objects = null; if (dlg.DoModalOpen(0, out objects)) { IGPUtilities2 util = new GPUtilitiesClass(); string name = objects.Next().FullName; dsName = (IDatasetName)util.CreateFeatureClassName(name); IFeatureWorkspace ws = (IFeatureWorkspace)((IName)dsName.WorkspaceName).Open(); IFeatureClass fc = ws.OpenFeatureClass(System.IO.Path.GetFileName(name)); esriGeometryType shp = fc.ShapeType; if (!(geom == esriGeometryType.esriGeometryAny && (shp == esriGeometryType.esriGeometryPoint || shp == esriGeometryType.esriGeometryPolyline || shp == esriGeometryType.esriGeometryPolygon)) && shp != geom) { ShowError("Wrong geometry type."); dsName = null; } dsName = (IDatasetName)((IDataset)fc).FullName; } return(dsName); } catch (Exception ex) { ShowError(ex.Message); return(null); } }
private void button6_Click(object sender, EventArgs e) { IGxDialog dlg = new GxDialogClass(); IGxObjectFilter filter1 = new GxFilterFeatureClassesClass(); IGxObjectFilter filter2 = new GxFilterAnnotationFeatureClassesClass(); IGxObjectFilterCollection filters = dlg as IGxObjectFilterCollection; filters.AddFilter(filter1, true); filters.AddFilter(filter2, false); IEnumGxObject selection; if (dlg.DoModalOpen(this.Handle.ToInt32(), out selection)) { IGxObject gobj = selection.Next(); if (gobj != null) { this.tbxDataSource.Text = gobj.FullName; m_fcName = gobj.InternalObjectName; this.tbxCacheName.Text = gobj.BaseName; } } }
/// <summary> /// Opens a dialog so the user can select a table containing transformation information /// from a previous time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void transformButton_Click(object sender, EventArgs e) { try { IGxObjectFilter tableFilter = new GxFilterTablesClass(); IGxDialog dlg = new GxDialogClass(); IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg; filters.AddFilter(tableFilter, true); dlg.Title = "Select the table containing previous transform information"; dlg.ButtonCaption = "Select"; IEnumGxObject objects = null; if (dlg.DoModalOpen(0, out objects)) { IGxObject obj = objects.Next(); _transformTableName = obj.InternalObjectName; transformTextBox.Text = obj.Name; EnableSave(); } } catch (Exception ex) { ShowError(ex.Message); } }
/// <summary> /// Opens a dialog so the user can select a feature class containing previously transformed /// benchmarks. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void benchmarkButton_Click(object sender, EventArgs e) { try { IGxObjectFilter featureClassFilter = new GxFilterFeatureClassesClass(); IGxDialog dlg = new GxDialogClass(); IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg; filters.AddFilter(featureClassFilter, true); dlg.Title = "Select the feature class containing previously transformed benchmarks"; dlg.ButtonCaption = "Select"; IEnumGxObject objects = null; if (dlg.DoModalOpen(0, out objects)) { IGxObject obj = objects.Next(); _benchmarkName = obj.InternalObjectName; benchmarkTextBox.Text = obj.Name; EnableSave(); } } catch (Exception ex) { ShowError(ex.Message); } }
public static List <IGxObject> SelectGxObject() { List <IGxObject> list = new List <IGxObject>(); IGxDialog gxDialog = new GxDialogClass(); IGxObjectFilterCollection gxObjectFilterCollection = gxDialog as IGxObjectFilterCollection; gxObjectFilterCollection.AddFilter(new GxFilterWorkspacesClass(), true); gxObjectFilterCollection.AddFilter(new GxFilterShapefilesClass(), false); gxDialog.AllowMultiSelect = true; gxDialog.ButtonCaption = "添加"; gxDialog.RememberLocation = true; IEnumGxObject enumGxObject = null; if (gxDialog.DoModalOpen(0, out enumGxObject)) { enumGxObject.Reset(); IGxObject gxObject; while ((gxObject = enumGxObject.Next()) != null) { list.Add(gxObject); } } return(list); }
private void btnOpen_Click(object sender, EventArgs e) { switch (ExportType) { case EnumExportType.FeatureClass: { IGxDialog dialog = new GxDialogClass(); IGxObjectFilterCollection filterCollection = dialog as IGxObjectFilterCollection; filterCollection.AddFilter(new GxFilterWorkspacesClass(), true); filterCollection.AddFilter(new GxFilterDatasetsClass(), false); dialog.AllowMultiSelect = false; dialog.ButtonCaption = "选择"; dialog.RememberLocation = true; dialog.Title = "选择输出位置"; IEnumGxObject selection = null; if (dialog.DoModalOpen(0, out selection)) { if (selection == null) { return; } IGxObject gxObject = selection.Next(); if (gxObject is IGxDatabase) { IGxDatabase gxDatabase = gxObject as IGxDatabase; _dataset = null; _workspace = gxDatabase.Workspace; _saveType = EnumSaveType.Workspace; } else if (gxObject is IGxDataset) { IGxDataset gxDataset = gxObject as IGxDataset; _dataset = gxDataset.Dataset; _workspace = _dataset.Workspace; _saveType = EnumSaveType.Dataset; } txtPath.Text = gxObject.FullName; } } break; case EnumExportType.Shapefile: { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() == DialogResult.OK) { this.txtPath.Text = dialog.SelectedPath; Type factoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory"); IWorkspaceFactory shapefileWorkspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory; if (shapefileWorkspaceFactory == null) { return; } _dataset = null; _workspace = shapefileWorkspaceFactory.OpenFromFile(dialog.SelectedPath, 0); _saveType = EnumSaveType.Workspace; } } break; } }
//工程设置添加文件 private void addFile11(TextBox tx, string tablename) { IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); string GdbPath = Application.StartupPath + "\\GISData.gdb"; string MdbPath = Application.StartupPath + "\\GISData.mdb"; IWorkspaceFactory pWks = new AccessWorkspaceFactoryClass(); IWorkspace pFwk = pWks.OpenFromFile(MdbPath, 0) as IWorkspace; IGxDialog dlg = new GxDialog(); IGxObjectFilterCollection filterCollection = dlg as IGxObjectFilterCollection; filterCollection.AddFilter(new GxFilterFeatureClasses(), true); IEnumGxObject enumObj; dlg.AllowMultiSelect = true; dlg.Title = "添加数据"; dlg.DoModalOpen(0, out enumObj); if (enumObj != null) { enumObj.Reset(); int a = 0; IGxObject gxObj = enumObj.Next(); while (gxObj != null) { Console.WriteLine(a++); if (gxObj is IGxDataset) { IGxDataset gxDataset = gxObj as IGxDataset; IDataset pDataset = gxDataset.Dataset; switch (pDataset.Type) { case esriDatasetType.esriDTFeatureClass: IFeatureClass pFc = pDataset as IFeatureClass; ISpatialReference pSpatialReference = (pFc as IGeoDataset).SpatialReference; //空间参考 CommonClass common = new CommonClass(); if (pSpatialReference.Name != common.GetConfigValue("SpatialReferenceName")) { MessageBox.Show("空间参考错误"); break; } else { tx.Text = pDataset.BrowseName; tx.Name = pDataset.BrowseName; } break; case esriDatasetType.esriDTFeatureDataset: IFeatureDataset pFeatureDs = pDataset as IFeatureDataset; //do anyting you like break; case esriDatasetType.esriDTRasterDataset: IRasterDataset rasterDs = pDataset as IRasterDataset; //do anyting you like break; case esriDatasetType.esriDTTable: ITable pTable = pDataset as ITable; //do anyting you like break; case esriDatasetType.esriDTTin: ITin pTin = pDataset as ITin; //do anyting you like break; case esriDatasetType.esriDTRasterCatalog: IRasterCatalog pCatalog = pDataset as IRasterCatalog; //do anyting you like break; default: break; } } else if (gxObj is IGxLayer) { IGxLayer gxLayer = gxObj as IGxLayer; ILayer pLayer = gxLayer.Layer; break; //do anything you like } gxObj = enumObj.Next(); } } }
//工程设置添加文件 private void addFile(TextBox tx, string tablename) { try { IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass(); IGxDialog dlg = new GxDialog(); IGxObjectFilterCollection filterCollection = dlg as IGxObjectFilterCollection; filterCollection.AddFilter(new GxFilterFeatureClasses(), true); IEnumGxObject enumObj; dlg.AllowMultiSelect = true; dlg.Title = "添加数据"; dlg.DoModalOpen(0, out enumObj); if (enumObj != null) { enumObj.Reset(); int a = 0; IGxObject gxObj = enumObj.Next(); while (gxObj != null) { Console.WriteLine(a++); if (gxObj is IGxDataset) { IGxDataset gxDataset = gxObj as IGxDataset; IDataset pDataset = gxDataset.Dataset; switch (pDataset.Type) { case esriDatasetType.esriDTFeatureClass: IFeatureClass pFc = pDataset as IFeatureClass; ISpatialReference pSpatialReference = (pFc as IGeoDataset).SpatialReference; //空间参考 CommonClass common = new CommonClass(); if (pSpatialReference.Name != common.GetConfigValue("SpatialReferenceName")) { MessageBox.Show("空间参考错误"); break; } else { string layerType = ""; if (pDataset.Category.Contains("个人地理数据库") || pDataset.Category.Contains("Personal")) { layerType = "Access数据库"; } else if (pDataset.Category.Contains("文件地理数据库") || pDataset.Category.Contains("File")) { layerType = "文件夹数据库"; } IFields fields = pFc.Fields; Dictionary <string, List <string> > dicCustom = new Dictionary <string, List <string> >(); Dictionary <string, List <string> > dicSys = new Dictionary <string, List <string> >(); ConnectDB db = new ConnectDB(); DataTable dt = db.GetDataBySql("select FIELD_NAME,DATA_TYPE,MAXLEN from GISDATA_MATEDATA where REG_NAME = '" + tablename + "'"); DataRow[] dr = dt.Select(null); string errorString = ""; for (int i = 0; i < dr.Length; i++) { string FIELD_NAME = dr[i]["FIELD_NAME"].ToString(); string DATA_TYPE = dr[i]["DATA_TYPE"].ToString(); string MAXLEN = dr[i]["MAXLEN"].ToString(); List <string> list1 = new List <string>(); list1.Add(DATA_TYPE); list1.Add(MAXLEN); dicSys.Add(FIELD_NAME, list1); } for (int i = 0; i < fields.FieldCount; i++) { IField field = fields.get_Field(i); if (field.Name != pFc.ShapeFieldName && field.Name != pFc.OIDFieldName) { List <string> list1 = new List <string>(); list1.Add(field.Type.ToString()); list1.Add(field.Length.ToString()); dicCustom.Add(field.Name.ToString(), list1); if (dicSys.ContainsKey(field.Name)) { if (dicSys[field.Name][0] != field.Type.ToString()) { errorString += "字段类型错误:" + field.Name + "(" + dicSys[field.Name][0] + ");\r\n"; } else if (dicSys[field.Name][1] != field.Length.ToString()) { errorString += "字段长度错误:" + field.Name + "(" + dicSys[field.Name][0] + ");\r\n"; } } else { errorString += "多余字段:" + field.Name + ";\r\n"; } } } foreach (KeyValuePair <string, List <string> > itemList in dicSys) { if (!dicCustom.ContainsKey(itemList.Key)) { errorString += "缺少字段:" + itemList.Key + ";\r\n"; } } if (errorString != "") { FormMessage message = new FormMessage("提示", errorString); message.ShowDialog(); //MessageBox.Show(errorString); } else { string path = pDataset.Workspace.PathName.Replace(@"\", @"\\"); Console.WriteLine(path); Boolean result = db.Update("update GISDATA_REGINFO set PATH= '" + path + "',DBTYPE = '" + layerType + "',TABLENAME = '" + pDataset.Name + "' where REG_NAME = '" + tablename + "'"); common.updateXmlNode(tablename, path, layerType, pDataset.Name); tx.Text = pDataset.BrowseName; tx.Name = pDataset.BrowseName; } } break; default: break; } } else if (gxObj is IGxLayer) { IGxLayer gxLayer = gxObj as IGxLayer; ILayer pLayer = gxLayer.Layer; break; //do anything you like } gxObj = enumObj.Next(); } } } catch (Exception e) { LogHelper.WriteLog(typeof(FormMain), e); } }
/// <summary> /// Prompts the user to save features /// /// Use "this.Handle.ToInt32()" as the parentWindow id /// </summary> /// <param name="iParentWindow">The window handle of the parent window</param> /// <returns>The path to selected output (fgdb/shapefile)</returns> public string PromptUserWithGxDialog(int iParentWindow) { //Prep the dialog if (m_ipSaveAsGxDialog == null) { m_ipSaveAsGxDialog = new GxDialog(); IGxObjectFilterCollection ipGxObjFilterCol = (IGxObjectFilterCollection)m_ipSaveAsGxDialog; ipGxObjFilterCol.RemoveAllFilters(); // Add the filters ipGxObjFilterCol.AddFilter(new GxFilterFGDBFeatureClasses(), false); ipGxObjFilterCol.AddFilter(new GxFilterShapefilesClass(), false); m_ipSaveAsGxDialog.AllowMultiSelect = false; m_ipSaveAsGxDialog.Title = "Select output"; m_ipSaveAsGxDialog.ButtonCaption = "OK"; m_ipSaveAsGxDialog.RememberLocation = true; } else { m_ipSaveAsGxDialog.Name = ""; m_ipSaveAsGxDialog.FinalLocation.Refresh(); } //Show the dialog and get the response if (m_ipSaveAsGxDialog.DoModalSave(iParentWindow) == false) { return(null); } else { IGxObject ipGxObject = m_ipSaveAsGxDialog.FinalLocation; string nameString = m_ipSaveAsGxDialog.Name; bool replacingObject = m_ipSaveAsGxDialog.ReplacingObject; string path = m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name; IGxObject ipSelectedObject = m_ipSaveAsGxDialog.InternalCatalog.SelectedObject; // user selected an existing featureclass if (ipSelectedObject != null && ipSelectedObject is IGxDataset) { IGxDataset ipGxDataset = (IGxDataset)ipSelectedObject; IDataset ipDataset = ipGxDataset.Dataset; // User will be prompted if they select an existing shapefile if (ipDataset.Category.Equals("Shapefile Feature Class")) { return(path); } while (DoesFeatureClassExist(ipDataset.Workspace.PathName, m_ipSaveAsGxDialog.Name)) { if (System.Windows.Forms.MessageBox.Show("You've selected a feature class that already exists. Do you wish to replace it?", "Overwrite Feature Class", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { return(m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name); } if (m_ipSaveAsGxDialog.DoModalSave(iParentWindow) == false) { return(null); } if (ipSelectedObject != null && ipSelectedObject is IGxDataset) { ipGxDataset = (IGxDataset)ipSelectedObject; ipDataset = ipGxDataset.Dataset; } } return(m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name); } else { return(path); } } }