public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolCreateParallel.OnMouseDown implementation if (Button == 1 && (m_pMapCtl = ClsGlobal.GetMapControl(m_hookHelper)) != null) { IMap pMap = m_pMapCtl.Map; IPoint po = m_pMapCtl.ToMapPoint(X, Y); ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass(); IGeometry geometry = new PolygonClass(); geometry = m_pMapCtl.TrackRectangle(); pMap.SelectByShape(geometry, pSelectionEnv, true); m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); IEnumFeatureSetup pSelectionsetup = pMap.FeatureSelection as IEnumFeatureSetup; pSelectionsetup.AllFields = true;//这里是关键 IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature; IFeature pF = pFeatureCollection.Next(); if (pF != null && pF.Shape is IPolyline) { FrmParallelLineOffset frm = new FrmParallelLineOffset(); if (frm.ShowDialog() == DialogResult.OK) { IPolyline pPolyline = ConstructOffset(pF.Shape as IPolyline, frm.offset); IFeature pFeature = m_FLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPolyline; pFeature.Store(); m_pMapCtl.Refresh(); } } } }
private void btnOK_Click(object sender, EventArgs e) { frmWaitDialog frmWait = new frmWaitDialog("正在汇总...", "提示信息"); try { frmWait.Owner = this; frmWait.TopMost = false; SampleSummary summary = new SampleSummary(_pSampleLayer, _pSurveyLayer, cmbFieldVillage.Text, cmbFieldID.Text, cmbFieldCropType.Text, cmbCropName.Text, cmbFieldArea.Text, txtOut.Text); string msg = ""; if (!summary.Summary(out msg)) { XtraMessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (DialogResult.OK == XtraMessageBox.Show("汇总完成!", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) { //MapAPI.AddShpFileToMap(txtOut.Text); BLL.EnviVars.instance.MapControl.Refresh(); } } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } finally { frmWait.Close(); XtraMessageBox.Show("汇总完成!"); _pMapControl.Refresh(); _pTOCControl.Update(); } }
//添加点图层按钮 private void btAddPoint_Click(object sender, EventArgs e) { OpenFileDialog OpenFile = new OpenFileDialog(); OpenFile.Title = "添加点图层"; OpenFile.Filter = "(*.shp)|*.shp"; if (OpenFile.ShowDialog() == DialogResult.OK) { cboBoxPointLayer.Items.Add(System.IO.Path.GetFileNameWithoutExtension(OpenFile.FileName)); try { //获得文件路径 string filePath = System.IO.Path.GetDirectoryName(OpenFile.FileName); //获得文件名称 string fileNam = System.IO.Path.GetFileName(OpenFile.FileName); //加载shape文件 pMapcontrol.AddShapeFile(filePath, fileNam); pMapcontrol.Refresh(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } cboBoxPointLayer.SelectedIndex = 0; } }
private void AxTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { IBasicMap pMap = null; ILayer pLayer = null; object legendgp = null; object index = null; esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone; axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref legendgp, ref index); //点击测试,点击图例打开符号选择器 if (e.button == 1) { ILegendGroup pLegendGroup = new LegendGroup(); ILegendClass pLegendClass = new LegendClass(); pLegendGroup = (ILegendGroup)legendgp; if (pItem == esriTOCControlItem.esriTOCControlItemLegendClass) { pLegendClass = pLegendGroup.get_Class(Convert.ToInt32(index.ToString())); if (pLegendClass == null) { return; } FormSymbolSelector dlg = new FormSymbolSelector(pLegendClass, pLayer); if (dlg != null) { dlg.ShowDialog(); m_pTocControl.Update(); m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); } } } }
private void StretchRender() { if (comboBoxBand.SelectedItem == null) { MessageBox.Show("波段不能为空!"); return; } IColorRamp pColorRamp = (IColorRamp)EnumStyleItem[comboBoxColor.SelectedIndex]; IRasterLayer pRasterLayr = m_layer as IRasterLayer; IRasterStretchColorRampRenderer pStretchRenderer = new RasterStretchColorRampRendererClass(); IRasterRenderer pRasterRenderer = (IRasterRenderer)pStretchRenderer; IRaster pRaster = pRasterLayr.Raster; pRasterRenderer.Raster = pRaster; pRasterRenderer.Update(); pStretchRenderer.BandIndex = comboBoxBand.SelectedIndex; pStretchRenderer.ColorRamp = pColorRamp; IRasterStretch pStretchType = (IRasterStretch)pRasterRenderer; pStretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations; pStretchType.StandardDeviationsParam = Convert.ToDouble(textBoxStandardValue.Text); pRasterLayr.Renderer = pRasterRenderer; m_mapControl3.Refresh(); }
/// <summary> /// Activate the MapControl and deactivate the PagleLayoutControl /// </summary> /// <param name="syncExtent">true if synchronizing map view extent</param> public void ActivateMap(bool syncExtent = false) { try { if (m_pageLayoutControl == null || m_mapControl == null) { throw new Exception("ControlsSynchronizer::ActivateMap:\r\nEither MapControl or PageLayoutControl are not initialized!"); } //Get IActiveView interface IActiveView activeView = m_pageLayoutControl.ActiveView.FocusMap as IActiveView; IEnvelope extent = activeView.Extent; //deactivate the PagleLayout m_pageLayoutControl.ActiveView.Deactivate(); //activate the MapControl m_mapControl.ActiveView.Activate(m_mapControl.hWnd); if (syncExtent == true) { m_mapControl.Extent = extent; m_mapControl.Refresh(); } m_IsMapCtrlactive = true; //on each of the framework controls, set the Buddy control to the MapControl this.SetBuddies(m_mapControl.Object); } catch (Exception ex) { throw new Exception(string.Format("ControlsSynchronizer::ActivateMap:\r\n{0}", ex.Message)); } }
public override void OnClick() { // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = (INALayer)m_mapControl.CustomProperty; // Set the Active Analysis layer to be the layer right-clicked on m_naEnv.NAWindow.ActiveAnalysis = naLayer; if (!Enabled) { return; } // Show the Property Page form for Network Analyst frmLoadLocations loadLocations = new frmLoadLocations(); if (loadLocations.ShowModal(m_mapControl, m_naEnv)) { // If loaded locations, refresh the NAWindow and the Screen m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); m_naEnv.NAWindow.UpdateContent(m_naEnv.NAWindow.ActiveCategory); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add SelectByShapeTool.OnMouseDown implementation //²úÉúÍÏÒ·¶à±ßÐÎ IGeometry pGeom = m_mapControl.TrackPolygon(); m_mapControl.Map.SelectByShape(pGeom, null, false); m_mapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
private void clearLocationsToolStripMenuItem_Click(object sender, EventArgs e) { IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; IEngineNetworkAnalystHelper naHelper = m_naEnv as IEngineNetworkAnalystHelper; IEngineNAWindow naWindow = m_naWindow; INALayer naLayer = naWindow.ActiveAnalysis; naHelper.DeleteAllNetworkLocations(); mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); }
public override void OnClick() { if (m_mapControl == null) { MessageBox.Show("Error: Map control is null for this command"); return; } // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = m_mapControl.CustomProperty as INALayer; if (naLayer == null) { MessageBox.Show("Error: NALayer was not set as the CustomProperty of the map control"); return; } var naEnv = CommonFunctions.GetTheEngineNetworkAnalystEnvironment(); if (naEnv == null || naEnv.NAWindow == null) { MessageBox.Show("Error: EngineNetworkAnalystEnvironment is not properly configured"); return; } // Set the active Analysis layer IEngineNAWindow naWindow = naEnv.NAWindow; if (naWindow.ActiveAnalysis != naLayer) { naWindow.ActiveAnalysis = naLayer; } // Remember what the current category is IEngineNAWindowCategory originalCategory = naWindow.ActiveCategory; // Loop through deleting all the items from all the categories INamedSet naClasses = naLayer.Context.NAClasses; var naHelper = naEnv as IEngineNetworkAnalystHelper; for (int i = 0; i < naClasses.Count; i++) { IEngineNAWindowCategory category = naWindow.get_CategoryByNAClassName(naClasses.get_Name(i)); naWindow.ActiveCategory = category; naHelper.DeleteAllNetworkLocations(); } //Reset to the original category naWindow.ActiveCategory = originalCategory; // Redraw the map m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add SearchAndZoomIn.OnMouseDown implementation //空间查询 try { MyMapControl.Map.ClearSelection(); MyMapControl.Refresh(); IArray geoArray = new ArrayClass(); if (MyselectedLayer == null) { return; } IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } IEnvelope envelope = MyMapControl.TrackRectangle(); IGeometry geometry = envelope as IGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geometry;//指定几何体 switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; break; } spatialFilter.GeometryField = featureClass.ShapeFieldName; IQueryFilter filter = spatialFilter as IQueryFilter;//筛选器 IFeatureCursor cursor = featureClass.Search(filter, false); // 缩放到选择结果集,并高亮显示 ZoomToSelectedFeature((IFeatureLayer)MyselectedLayer, filter); } catch { } }
private void btnOK_Click(object sender, EventArgs e) { switch (startPosition) { case "startFromMap": pMapControl.SpatialReference = pSpaReference; pMapControl.Refresh(); break; case "startFromLayer": break; } this.Close(); }
private void onSelectedValueChanged(object sender, EventArgs e) { IMap m; Int16 i; for (i = 0; i < m_arrMaps.Count; i++) { m = (IMap)m_arrMaps.Element[i]; if (m.Name == cboFrame.Text) { m_blnExistingMap = true; m_mapControl.Map = (IMap)m_arrMaps.Element[i]; m_mapControl.Refresh(); m_blnExistingMap = false; return; } } }
private void miLoadLocations_Click(object sender, System.EventArgs e) { IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; // 显示网络分析的属性页窗体 frmLoadLocations loadLocations = new frmLoadLocations(); if (loadLocations.ShowModal(mapControl, m_naEnv)) { // 上下文已更改,已将位置添加到其中的一个naclass INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit; contextEdit.ContextChanged(); // 如果加载,刷新NAWindow屏幕 INALayer naLayer = m_naWindow.ActiveAnalysis; mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); m_naWindow.UpdateContent(m_naWindow.ActiveCategory); } }
private void loadLocationsToolStripMenuItem_Click(object sender, EventArgs e) { IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; // Show the Property Page form for Network Analyst frmLoadLocation loadLocations = new frmLoadLocation(); if (loadLocations.ShowModal(mapControl, m_naEnv)) { // notify that the context has changed because we have added locations to a NAClass within it INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit; contextEdit.ContextChanged(); // If loaded locations, refresh the NAWindow and the Screen INALayer naLayer = m_naWindow.ActiveAnalysis; mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); m_naWindow.UpdateContent(m_naWindow.ActiveCategory); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { ILayer layer = ClsGlobal.GetSelectedLayer(m_hookHelper); if (m_subType == 1) { layer.MaximumScale = m_mapControl.MapScale; } if (m_subType == 2) { layer.MinimumScale = m_mapControl.MapScale; } if (m_subType == 3) { layer.MaximumScale = 0; layer.MinimumScale = 0; } m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); }
public override void OnClick() { ILayer layer = (ILayer)m_mapControl.CustomProperty; if (m_subType == 1) { layer.MaximumScale = m_mapControl.MapScale; } if (m_subType == 2) { layer.MinimumScale = m_mapControl.MapScale; } if (m_subType == 3) { layer.MaximumScale = 0; layer.MinimumScale = 0; } m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void SaveChanges(DataTable editedRow) { try { ITable aeTable = _FeatureLayer.FeatureClass as ITable; int fieldCount = aeTable.Fields.FieldCount; int fidIndex = aeTable.FindField("FID"); IRow pRow = null; foreach (DataRow iRow in editedRow.Rows) { ICursor pCursor = aeTable.Update(null, true); while ((pRow = pCursor.NextRow()) != null) { if (pRow.get_Value(fidIndex).ToString() == iRow[fidIndex].ToString()) { for (int i = 2; i < fieldCount; i++) { pRow.set_Value(i, iRow[i]); } pCursor.UpdateRow(pRow); } } if (pCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); } } _CurrentTable.AcceptChanges(); XtraMessageBox.Show("保存成功!"); MapAPI.UniqueValueRender(_FeatureLayer, "分层"); (_pMapControl.Map as IActiveView).Extent = _FeatureLayer.AreaOfInterest; _pMapControl.Refresh(); _pTOCControl.Update(); } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } }
//Periodically update the statistics information private void timerStats_Tick(object sender, EventArgs e) { //Initialize TA if there is hasn't been already and there are Tracking layers in the map if (!m_bTAInitialized && GetAllTrackingLayers() != null) { object oMapControl = m_mapControl; ITrackingEnvironment3 taEnv = setupTrackingEnv(ref oMapControl); //ITrackingEnvironment3 taEnv = setupTrackingEnv(ref oMapControl); if (taEnv != null) { m_bTAInitialized = true; } //Need to refresh the map once to get the tracks moving m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); } RefreshStatistics(); }
public override void OnClick() { IEngineNetworkAnalystEnvironment naEnv = new EngineNetworkAnalystEnvironmentClass(); IEngineNetworkAnalystHelper naHelper = naEnv as IEngineNetworkAnalystHelper; IEngineNAWindow naWindow = naEnv.NAWindow; // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = (INALayer)m_mapControl.CustomProperty; INAContext naContext = naLayer.Context; // Set the active Analysis layer if (naWindow.ActiveAnalysis != naLayer) { naWindow.ActiveAnalysis = naLayer; } // Remember what the current category is IEngineNAWindowCategory currentCategory = naWindow.ActiveCategory; // Loop through deleting all the items from all the categories INamedSet naClasses = naContext.NAClasses; for (int i = 0; i < naClasses.Count; i++) { IEngineNAWindowCategory category = naWindow.get_CategoryByNAClassName(naClasses.get_Name(i)); naWindow.ActiveCategory = category; naHelper.DeleteAllNetworkLocations(); } //Reset to the original category naWindow.ActiveCategory = currentCategory; m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); }
private void miAddItem_Click(object sender, System.EventArgs e) { //可以双击该项来编辑属性 //只为新项填充initDefaultValues方法中的默认值和自动生成的名称值。 IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; IEngineNAWindowCategory2 activeCategory = m_naWindow.ActiveCategory as IEngineNAWindowCategory2; IDataLayer pDataLayer = activeCategory.DataLayer; // 在类中创建一个新行并填充并初始默认值 ITable table = pDataLayer as ITable; IRow row = table.CreateRow(); IRowSubtypes rowSubtypes = row as IRowSubtypes; rowSubtypes.InitDefaultValues(); // 自动生成显示名称 IFeatureLayer ipFeatureLayer = activeCategory.Layer as IFeatureLayer; IStandaloneTable ipStandaloneTable = pDataLayer as IStandaloneTable; string name = ""; if (ipFeatureLayer != null) { name = ipFeatureLayer.DisplayField; } else if (ipStandaloneTable != null) { name = ipStandaloneTable.DisplayField; } //如果显示字段为空字符串或不代表NaClass上的实际字段,则跳过自动生成 string currentName = ""; int fieldIndex = row.Fields.FindField(name); if (fieldIndex >= 0) { currentName = row.get_Value(fieldIndex) as string; if (currentName.Length <= 0) { row.set_Value(fieldIndex, "Item" + ++autogenInt); } } INAClassDefinition naClassDef = activeCategory.NAClass.ClassDefinition; if (naClassDef.Name == "OrderPairs") { fieldIndex = row.Fields.FindField("SecondOrderName"); if (fieldIndex >= 0) { string secondName = row.get_Value(fieldIndex) as string; if (secondName.Length <= 0) { row.set_Value(fieldIndex, "Item" + ++autogenInt); } } } row.Store(); // 向naclass添加项 INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit; contextEdit.ContextChanged(); // 刷新 NAWindow 和屏幕界面 INALayer naLayer = m_naWindow.ActiveAnalysis; mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); m_naWindow.UpdateContent(m_naWindow.ActiveCategory); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolCreateCircle.OnMouseDown implementation if ((m_pMapCtl = ClsGlobal.GetMapControl(m_hookHelper)) == null) { return; } IPoint pPoint = m_pMapCtl.ToMapPoint(X, Y); if (Button == 1) { if (m_NewCircleFeedback == null) { m_NewCircleFeedback = new NewCircleFeedbackClass(); m_NewCircleFeedback.Display = m_pMapCtl.ActiveView.ScreenDisplay; m_NewCircleFeedback.Start(pPoint); m_CenterPoint = pPoint; } else { try { object Miss = Type.Missing; ICircularArc pArc = m_NewCircleFeedback.Stop(); //IGeometry geometry = new PolygonClass(); //geometry = m_pMapCtl.TrackCircle(); IPolygon pPolygon = new PolygonClass(); ISegment pArcC = pArc as ISegment; ISegmentCollection pArcP = pPolygon as ISegmentCollection; pArcP.AddSegment(pArcC, ref Miss, ref Miss); pPolygon.Close(); IFeature pFeature = m_FLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPolygon; pFeature.Store(); m_pMapCtl.Refresh(); m_NewCircleFeedback = null; } catch (System.Exception ex) { } } } if (Button == 2) { double radius = Math.Sqrt((pPoint.X - m_CenterPoint.X) * (pPoint.X - m_CenterPoint.X) + (pPoint.Y - m_CenterPoint.Y) * (pPoint.Y - m_CenterPoint.Y)); FrmDrawCircle frm = new FrmDrawCircle(radius); IConstructCircularArc pArcConstruct = null; if (m_NewCircleFeedback == null) { return; } if (frm.ShowDialog() == DialogResult.OK) { try { pArcConstruct = new CircularArcClass(); pArcConstruct.ConstructCircle(m_CenterPoint, frm.m_radius, false); if (pArcConstruct != null) { IPolygon pPolygon = new PolygonClass(); ISegment pArcC = pArcConstruct as ISegment; ISegmentCollection pArcP = pPolygon as ISegmentCollection; pArcP.AddSegment(pArcC); pPolygon.Close(); IFeature pFeature = m_FLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPolygon; pFeature.Store(); m_pMapCtl.Refresh(); m_NewCircleFeedback.Stop(); m_NewCircleFeedback = null; } } catch (System.Exception ex) { MessageBox.Show(ex.Message); if (m_NewCircleFeedback != null) { m_NewCircleFeedback.Stop(); } m_NewCircleFeedback = null; } } } }
private void btnOK_Click(object sender, EventArgs e) { ITableConversion conver = new TableConversion(); DataTable dt = conver.AETableToDataTable(_pFLayer.FeatureClass); //添加主键以提高处理速度 dt.PrimaryKey = new DataColumn[] { dt.Columns["FID"] }; AutoLayer auto = new AutoLayer(); _pFDt = auto.OptimalStratifying(dt, _lyrField, _lyrNum); ITable pTable = _pFLayer.FeatureClass as ITable; //添加分层字段 string fName = "FCBH"; if (pTable.FindField(fName) < 0) { IField layerField = new FieldClass(); IFieldEdit fieldEdit = layerField as IFieldEdit; fieldEdit.Name_2 = fName; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; pTable.AddField(layerField); } //字段赋值 ICursor pCursor = pTable.Update(null, false); IRow pRow = null; int layerIndex = pTable.FindField(fName); if (layerIndex < 0) { XtraMessageBox.Show("添加分层字段失败!"); return; } while ((pRow = pCursor.NextRow()) != null) { string value = pRow.get_Value(0).ToString(); //改用find接口以二叉树查找,效率提高百倍级别 DataRow test = _pFDt.Rows.Find(value); if (test == null) { continue; } pRow.set_Value(layerIndex, test[fName]); pCursor.UpdateRow(pRow); //原始遍历方法 //foreach(DataRow dRow in _pFDt.Rows) //{ // if (value == dRow["FID"].ToString()) // { // pRow.set_Value(layerIndex, dRow[fName]); // pCursor.UpdateRow(pRow); // } //} } Marshal.ReleaseComObject(pCursor); XtraMessageBox.Show("分层完毕!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); { SampleData.layerField = fName; MapAPI.UniqueValueRender(_pFLayer, fName); (_pMapControl.Map as IActiveView).Extent = _pFLayer.AreaOfInterest; _pMapControl.Refresh(); _pTOCControl.Update(); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add TrackRectangleQuary.OnMouseDown implementation //空间查询 try { MyMapControl.Map.ClearSelection(); MyMapControl.Refresh(); IArray geoArray = new ArrayClass(); if (MyselectedLayer == null) { return; } IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } IEnvelope envelope = MyMapControl.TrackRectangle(); //IGeometry geometry = MyMapControl.TrackCircle(); IGeometry geometry = envelope as IGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geometry;//指定几何体 switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; break; } spatialFilter.GeometryField = featureClass.ShapeFieldName; IQueryFilter filter = spatialFilter as IQueryFilter;//筛选器 IFeatureCursor cursor = featureClass.Search(filter, false); IFeature pfeature = cursor.NextFeature(); MyselectedFeature = new List <IFeature>();//此处**初始化list while (pfeature != null) { //geoArray.Add(pfeature);//直接存入数组geoArray用于闪烁 MyselectedFeature.Add(pfeature); //存入list pfeature = cursor.NextFeature(); //枚举 } //或者将list(MyselectedFeature)转存入数组geoArray用于闪烁 /*for (int i = 0; i < MyselectedFeature.Count; i++) * { * geoArray.Add(MyselectedFeature[i]); * }*/ SelectOnMouseDown(); //高亮 FlashAndIdentify(geoArray); //闪烁 } catch { } }
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { try { esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; //Determine what kind of item is selected m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); if (item == esriTOCControlItem.esriTOCControlItemNone) { return; } // Load TOC context menu if (e.button == 2) { if (item == esriTOCControlItem.esriTOCControlItemMap) { m_tocControl.SelectItem(map, null); } else { m_tocControl.SelectItem(layer, null); } //Set the layer into the CustomProperty (this is used by the custom layer commands) m_mapControl.CustomProperty = layer; //Popup the correct context menu if (item == esriTOCControlItem.esriTOCControlItemMap) { return; } if (item == esriTOCControlItem.esriTOCControlItemLayer) { m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd); } } //Ensure the item gets selected //Load Simple Color pallette 071017 HK if (e.button == 1 && item == esriTOCControlItem.esriTOCControlItemLegendClass) { IFeatureLayer featureLayer = layer as IFeatureLayer; IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; DialogResult DR; if (geoFeatureLayer.Renderer is ISimpleRenderer) // Only apply this function to simple Renderer { DR = cdColor.ShowDialog(); } else { return; } IRgbColor pRGBcolor = new RgbColorClass(); if (DR == DialogResult.OK) { pRGBcolor = m_pSnippet.getRGB(cdColor.Color.R, cdColor.Color.G, cdColor.Color.B); } ISimpleRenderer simpleRenderer = (ISimpleRenderer)geoFeatureLayer.Renderer; ISymbol pSymbol = simpleRenderer.Symbol; //Update only color switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: ISimpleMarkerSymbol pSimpleMarkerSymobl = (ISimpleMarkerSymbol)pSymbol; pSimpleMarkerSymobl.Color = (IColor)pRGBcolor; pSymbol = (ISymbol)pSimpleMarkerSymobl; break; case esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol pSimpleLineSymobl = (ISimpleLineSymbol)pSymbol; pSimpleLineSymobl.Color = (IColor)pRGBcolor; pSymbol = (ISymbol)pSimpleLineSymobl; break; case esriGeometryType.esriGeometryPolygon: ISimpleFillSymbol pSimpleFillSymobl = (ISimpleFillSymbol)pSymbol; pSimpleFillSymobl.Color = (IColor)pRGBcolor; pSymbol = (ISymbol)pSimpleFillSymobl; break; } simpleRenderer.Symbol = pSymbol; geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer; m_tocControl.ActiveView.ContentsChanged(); m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); } } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
private void addItemToolStripMenuItem_Click(object sender, EventArgs e) { IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; IEngineNAWindowCategory2 activeCategory = m_naWindow.ActiveCategory as IEngineNAWindowCategory2; IDataLayer pDataLayer = activeCategory.DataLayer; // In order to add an item, we need to create a new row in the class and populate it // with the initial default values for that class. ITable table = pDataLayer as ITable; IRow row = table.CreateRow(); IRowSubtypes rowSubtypes = row as IRowSubtypes; rowSubtypes.InitDefaultValues(); IFeatureLayer ipFeatureLayer = activeCategory.Layer as IFeatureLayer; IStandaloneTable ipStandaloneTable = pDataLayer as IStandaloneTable; string name = ""; if (ipFeatureLayer != null) { name = ipFeatureLayer.DisplayField; } else if (ipStandaloneTable != null) { name = ipStandaloneTable.DisplayField; } string currentName = ""; int fieldIndex = row.Fields.FindField(name); if (fieldIndex >= 0) { currentName = row.get_Value(fieldIndex) as string; if (currentName.Length <= 0) { row.set_Value(fieldIndex, "Item" + ++autogenInt); } } INAClassDefinition naClassDef = activeCategory.NAClass.ClassDefinition; if (naClassDef.Name == "OrderPairs") { fieldIndex = row.Fields.FindField("SecondOrderName"); if (fieldIndex >= 0) { string secondName = row.get_Value(fieldIndex) as string; if (secondName.Length <= 0) { row.set_Value(fieldIndex, "Item" + ++autogenInt); } } } row.Store(); // notify that the context has changed because we have added an item to a NAClass within it INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit; contextEdit.ContextChanged(); // refresh the NAWindow and the Screen INALayer naLayer = m_naWindow.ActiveAnalysis; mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); m_naWindow.UpdateContent(m_naWindow.ActiveCategory); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add pPointSearch.OnMouseDown implementation try { MyMapControl.Map.ClearSelection(); MyMapControl.Refresh(); IArray geoArray = new ArrayClass(); if (MyselectedLayer == null) { return; } IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } //IEnvelope envelope = MyMapControl.TrackRectangle(); ISpatialFilter spatialFilter = new SpatialFilterClass(); IPoint point = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IGeometry geometry = point as IGeometry; double length = ConvertPixelsToMapUnits(4); ITopologicalOperator pTopo = geometry as ITopologicalOperator; IGeometry buffer = pTopo.Buffer(length);//获取缓冲区 geometry = buffer.Envelope as IGeometry; spatialFilter.Geometry = geometry;//指定几何体 switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; break; } spatialFilter.GeometryField = featureClass.ShapeFieldName; IQueryFilter filter = spatialFilter as IQueryFilter;//筛选器 IFeatureCursor cursor = featureClass.Search(filter, false); IFeature pfeature = cursor.NextFeature(); MyselectedFeature = new List <IFeature>();//此处**初始化list while (pfeature != null) { geoArray.Add(pfeature); //直接存入数组geoArray用于闪烁 MyselectedFeature.Add(pfeature); //存入list pfeature = cursor.NextFeature(); //枚举 } //或者将list(MyselectedFeature)转存入数组geoArray用于闪烁 /*for (int i = 0; i < MyselectedFeature.Count; i++) * { * geoArray.Add(MyselectedFeature[i]); * }*/ SelectOnMouseDown(); //高亮 FlashAndIdentify(geoArray); //闪烁 } catch { } }
private DataTable OpenVec(Dictionary <string, DataType> Dic) { IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); IWorkspace pVecWorkspace = pWorkspaceFactory.OpenFromFile(m_VecPath, 0); IFeatureWorkspace pFeatureWorkspace = pVecWorkspace as IFeatureWorkspace; IEnumDataset pEnumDataset = pVecWorkspace.get_Datasets(esriDatasetType.esriDTAny) as IEnumDataset; pEnumDataset.Reset(); IDataset pDataset = pEnumDataset.Next(); while (null != pDataset) { if (pDataset is IFeatureClass)//SHP文件 { if (pDataset.Name.ToUpper().Equals("PROVINCE")) { IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name); if (null == pFeatureClass) { return(null); } //加载图层 IFeatureLayer pFeaLayer = new FeatureLayerClass(); pFeaLayer.Name = pDataset.Name; pFeaLayer.FeatureClass = pFeatureClass; m_MapControl.AddLayer(pFeaLayer as ILayer, 0); m_MapControl.Refresh(); //读取字段 DataTable mDtResult = new DataTable(); mDtResult.Columns.Add("字段名", typeof(System.String)); mDtResult.Columns.Add("类型", typeof(System.String)); mDtResult.Columns.Add("长度", typeof(System.String)); mDtResult.Columns.Add("最大值", typeof(System.String)); mDtResult.Columns.Add("最小值", typeof(System.String)); foreach (var value in Dic) { DataRow DtRow = mDtResult.NewRow(); DtRow[0] = value.Key; for (int i = 0; i < pFeatureClass.Fields.FieldCount; i++) { if (pFeatureClass.Fields.Field[i].Name == value.Key) { if (pFeatureClass.Fields.Field[i].Type == value.Value.Texttype) { DtRow[1] = "类型为" + pFeatureClass.Fields.Field[i].Type.ToString() + ",正确"; } else { DtRow[1] = "类型为" + pFeatureClass.Fields.Field[i].Type.ToString() + ",错误,实际应为" + value.Value.Texttype; } if (pFeatureClass.Fields.Field[i].Length <= value.Value.Length) { DtRow[2] = "最大长度为" + pFeatureClass.Fields.Field[i].Length.ToString() + ",正确"; } else { DtRow[2] = "最大长度超过" + value.Value.Length.ToString(); } if (value.Value.Max > 999999) { DtRow[3] = "最大值无限制"; } else { DtRow[3] = QueryMax(pFeatureClass, value.Value.Max, value.Key); } if (value.Value.Min < -999999) { DtRow[4] = "最小值无限制"; } else { DtRow[4] = QueryMin(pFeatureClass, value.Value.Min, value.Key); } break; } } mDtResult.Rows.Add(DtRow); } return(mDtResult); } } pDataset = pEnumDataset.Next(); } return(null); }