public void ClearSelectedMapFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer) //dhncho 01.10 { if (activeView == null || featureLayer == null) { return; } ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection; // Dynamic Cast // Invalidate only the selection cache. Flag the original selection activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null); // Clear the selection featureSelection.Clear(); // Flag the new selection activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null); }
// Öppnar shapefil. public void AddShapefileUsingOpenFileDialog(ESRI.ArcGIS.Carto.IActiveView activeView) { //parameter check if (activeView == null) { return; } // Use the OpenFileDialog Class to choose which shapefile to load. System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.InitialDirectory = @"H:\VT2019\GIS_App\Projekt\Program\Data\InData\Vektor"; openFileDialog.Filter = "Shapefiles (*.shp)|*.shp"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // The user chose a particular shapefile. // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp" string shapefileLocation = openFileDialog.FileName; if (shapefileLocation != "") { // Ensure the user chooses a shapefile // Create a new ShapefileWorkspaceFactory CoClass to create a new workspace ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass(); // System.IO.Path.GetDirectoryName(shapefileLocation) returns the directory part of the string. Example: "C:\test\" ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(shapefileLocation), 0); // Explicit Cast // System.IO.Path.GetFileNameWithoutExtension(shapefileLocation) returns the base filename (without extension). Example: "cities" ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation)); ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = new ESRI.ArcGIS.Carto.FeatureLayerClass(); featureLayer.FeatureClass = featureClass; featureLayer.Name = featureClass.AliasName; featureLayer.Visible = true; activeView.FocusMap.AddLayer(featureLayer); // Zoom the display to the full extent of all layers in the map activeView.Extent = activeView.FullExtent; activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null); } else { } } else { } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { ILayer layer = m_engineEditor.TargetLayer; if (layer == null) { return; } m_activeView = m_hookHelper.ActiveView; m_map = m_hookHelper.FocusMap; IEnumFeature selectedFeatures = GetSelectedFeatures(); if (selectedFeatures == null) { return; } UnionFeatures(selectedFeatures); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent); // TODO: Add UnionFeaturesCmd.OnClick implementation }
//#### ArcGIS Snippets #### #region "Add Shapefile Using OpenFileDialog" ///<summary>Add a shapefile to the ActiveView using the Windows.Forms.OpenFileDialog control.</summary> /// ///<param name="activeView">An IActiveView interface</param> /// ///<remarks></remarks> public void AddShapefileUsingOpenFileDialog(ESRI.ArcGIS.Carto.IActiveView activeView) { //parameter check if (activeView == null) { return; } // Use the OpenFileDialog Class to choose which shapefile to load. System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "Shapefiles (*.shp)|*.shp"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // The user chose a particular shapefile. // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp" string shapefileLocation = openFileDialog.FileName; if (shapefileLocation != "") { // Ensure the user chooses a shapefile // Create a new ShapefileWorkspaceFactory CoClass to create a new workspace ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory(); // System.IO.Path.GetDirectoryName(shapefileLocation) returns the directory part of the string. Example: "C:\test\" ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(shapefileLocation), 0); // Explicit Cast // System.IO.Path.GetFileNameWithoutExtension(shapefileLocation) returns the base filename (without extension). Example: "cities" ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation)); ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = new ESRI.ArcGIS.Carto.FeatureLayer(); featureLayer.FeatureClass = featureClass; featureLayer.Name = featureClass.AliasName; featureLayer.Visible = true; activeView.FocusMap.AddLayer(featureLayer); // Zoom the display to the full extent of all layers in the map activeView.Extent = activeView.FullExtent; activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null); } else { // The user did not choose a shapefile. // Do whatever remedial actions as necessary // System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #1", // System.Windows.Forms.MessageBoxButtons.OK, // System.Windows.Forms.MessageBoxIcon.Exclamation); } } else { // The user did not choose a shapefile. They clicked Cancel or closed the dialog by the "X" button. // Do whatever remedial actions as necessary. // System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #2", // System.Windows.Forms.MessageBoxButtons.OK, // System.Windows.Forms.MessageBoxIcon.Exclamation); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { //if (!this.m_blCanEdit) return; int nPointCount; nPointCount = this.m_pDrawLineTrack.GetPointCount(); int nRing; nRing = this.m_pDrawLineTrack.GetPartCount(); if (Button == 2) { int nMenuType; if (nPointCount >= 3) { nMenuType = 1; //可封闭 } else if (nPointCount <= 0 && nRing <= 0) { nMenuType = 2; //不可 } else { nMenuType = 3; //可回退 } Dictionary <string, bool> ToolRightMenu = new Dictionary <string, bool>(); if (nMenuType == 1) { ToolRightMenu.Add("封闭", true); } else { ToolRightMenu.Add("封闭", false); } if (nMenuType == 2) { ToolRightMenu.Add("放弃", false); ToolRightMenu.Add("回退", false); } else { ToolRightMenu.Add("放弃", true); ToolRightMenu.Add("回退", true); } ToolRightMenu.Add("平移", true); ToolRightMenu.Add("放大", true); ToolRightMenu.Add("缩小", true); this.m_blCanMove = false; this.m_pDrawLineTrack.MouseMove(X, Y); //ModPublic.PublicClass.OnPopupMenuEventArgs(ToolRightMenu); m_clsEditorMain.MethodInfo_PopupMenuEventArgs.Invoke(m_clsEditorMain.frmMain, new object[] { ToolRightMenu }); return; } if (Button == 1) { object obj = Type.Missing; try { ESRI.ArcGIS.Geometry.IPoint pPoint = this.m_pDrawLineTrack.AddPoint(X, Y, false); nPointCount = m_pDrawLineTrack.GetPointCount(); nRing = m_pDrawLineTrack.GetPartCount(); string sXY; sXY = m_pDrawLineTrack.GetLastPointXYStr(); //ModPublic.PublicClass.OnGetCommandTipEventArgs(OperationParam.CheckUpOut, sXY, ""); m_clsEditorMain.MethodInfo_GetCommandTipEventArgs.Invoke(m_clsEditorMain.frmMain, new object[] { OperationParam.CheckUpOut, sXY, "" }); if (nPointCount <= 2) { if (nPointCount == 0) { if (nRing <= 0) { SetNextStep("0"); } else { SetNextStep("4"); } } else if (nPointCount == 1) { SetNextStep("1"); } else { SetNextStep("2"); } } else { SetNextStep("3"); } } catch (Exception ee) { m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null); } } }