public void AddPolygonByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y) { ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType; if (featype == esriGeometryType.esriGeometryPolygon)//判断层是否为线层 { //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer; IFeatureClass fc = l.FeatureClass; IFeatureClassWrite fr = fc as IFeatureClassWrite; IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; IFeature f; //可选参数的设置 object Missing = Type.Missing; IPoint p = new PointClass(); w.StartEditing(true); w.StartEditOperation(); f = fc.CreateFeature(); //定义一个多义线对象 IRgbColor color = new RgbColor(); // 设置颜色属性 color.Red = 255; color.Transparency = 255; IGeometry iGeom = axMapControl1.TrackPolygon(); AddRegion(axMapControl1, iGeom); f.Shape = iGeom; fr.WriteFeature(f); w.StopEditOperation(); w.StopEditing(true); } }
public void PolygonSelect(AxMapControl mapControl) { this.init(); IGeometry pGeometryP; pGeometryP = mapControl.TrackPolygon(); //新建选择集对象 ISelectionEnvironment pSelectionEnvP; pSelectionEnvP = new SelectionEnvironmentClass(); //改变选择集的默认颜色 pSelectionEnvP.DefaultColor = pColor; //选择要素,并将其放入选择集 mapControl.Map.SelectByShape(pGeometryP, pSelectionEnvP, false); mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
//查询 public static void QueryByBuffer(AxMapControl axMapControl) { // IDataset data = null; ILayer layer = axMapControl.get_Layer(0); IFeatureLayer featureLayer = layer as IFeatureLayer; //获取featurelayer的featureClass IFeatureClass featureClass = featureLayer.FeatureClass; IFeature feature = null; IQueryFilter queryFilter = new QueryFilterClass(); IFeatureCursor featureCursor; queryFilter.WhereClause = "NAME"; featureCursor = featureClass.Search(queryFilter, true); feature = featureCursor.NextFeature(); if (feature != null) { axMapControl.Map.SelectFeature(axMapControl.get_Layer(axMapControl.Map.LayerCount), feature); axMapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } axMapControl.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair; IGeometry geometry = null; geometry = axMapControl.TrackPolygon(); //geometry = axMapControl.get_Layer(axMapControl.Map.LayerCount - 1) as IGeometry; axMapControl.Map.SelectByShape(geometry, null, false); axMapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
/// <summary> /// 面积测量 /// </summary> /// <param name="axMapControl"></param> public static void MeasureArea(AxMapControl axMapControl) { IActiveView pActiveView = axMapControl.ActiveView; IScreenDisplay screenDisplay = pActiveView.ScreenDisplay; ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); IRgbColor rgbClolor = new RgbColorClass(); lineSymbol.Width = 2; rgbClolor.Red = 255; lineSymbol.Color = rgbClolor; axMapControl.Map.MapUnits = esriUnits.esriKilometers; IPolygon pGon = axMapControl.TrackPolygon() as IPolygon; screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol((ISymbol)lineSymbol); screenDisplay.DrawPolyline(pGon); screenDisplay.FinishDrawing(); try { IArea pArea = pGon as IArea; double s = Math.Abs(pArea.Area*10000);// MessageBox.Show("测量面积为:" + Convert.ToDouble(s).ToString("0.000") + "平方公里(km2)", "面积测量结果"); IGraphicsContainer pDeletElement = axMapControl.ActiveView.FocusMap as IGraphicsContainer; pDeletElement.DeleteAllElements(); axMapControl.ActiveView.Refresh(); } catch(Exception ex) { MessageBox.Show(ex.Message); } }
//自由画面统计 public static void FreePolygonSt(AxMapControl axMapControl,string Path) { try { IActiveView pActiveView = axMapControl.ActiveView; IScreenDisplay screenDisplay = pActiveView.ScreenDisplay; ISimpleFillSymbol sfs = new SimpleFillSymbolClass(); IRgbColor rgbClolor = new RgbColorClass(); sfs.Color = GetRgbColor(23, 255, 55); IPolygon pGon = axMapControl.TrackPolygon() as IPolygon; screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol((ISymbol)sfs); screenDisplay.DrawPolygon((IGeometry)pGon); screenDisplay.FinishDrawing(); if (MessageBox.Show("是否进行统计?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { CreatePolygonFeature(pGon, Path, "统计"); //axMapControl.AddShapeFile(@"G:\数据库\图层数据", "统计"); } } catch(Exception ex) { MessageBox.Show(ex.Message); } }
public void AddPolygonByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y) { ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType; if (featype == esriGeometryType.esriGeometryPolygon)//�жϲ��Ƿ�Ϊ�߲� { //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer; IFeatureClass fc = l.FeatureClass; IFeatureClassWrite fr = fc as IFeatureClassWrite; IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; IFeature f; //��ѡ���������� object Missing = Type.Missing; IPoint p = new PointClass(); w.StartEditing(true); w.StartEditOperation(); f = fc.CreateFeature(); //����һ�������߶��� IRgbColor color = new RgbColor(); // ������ɫ���� color.Red = 255; color.Transparency = 255; IGeometry iGeom = axMapControl1.TrackPolygon(); AddRegion(axMapControl1, iGeom); f.Shape = iGeom; fr.WriteFeature(f); w.StopEditOperation(); w.StopEditing(true); } }
private void axMapControlMainMap_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { int statusFlag = CommonLib.MapMouseFlag; if (statusFlag <= 1) { return; } AxMapControlMainMap.MousePointer = esriControlsMousePointer.esriPointerCrosshair;//鼠标指针:十字状 IPoint pPoint = AxMapControlMainMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); #region 11-19:空间查询(画点、线、面) if (statusFlag >= 11 && statusFlag <= 19) { object symbol = null; switch (statusFlag) { case 11: IPoint point = new ESRI.ArcGIS.Geometry.Point(); point.X = e.mapX; point.Y = e.mapY; CommonLib.MapGeometry = point; symbol = RenderOpt.GetSimpleMarkerSymbol("ff0000"); break; case 12: CommonLib.MapGeometry = AxMapControlMainMap.TrackLine(); symbol = RenderOpt.GetSimpleLineSymbol("ff0000"); break; case 13: CommonLib.MapGeometry = AxMapControlMainMap.TrackPolygon(); symbol = RenderOpt.GetSimpleFillSymbol("99ccff", "ff0000"); break; case 14: CommonLib.MapGeometry = AxMapControlMainMap.TrackRectangle(); symbol = RenderOpt.GetSimpleFillSymbol("99ccff", "ff0000"); break; default: CommonLib.MapGeometry = null; break; } if (CommonLib.MapGeometry != null) { //axMapControlMainMap.Map.SelectByShape(CommonLib.MapGeometry, null, false); //axMapControlMainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); AxMapControlMainMap.DrawShape(CommonLib.MapGeometry, ref symbol); } } #endregion #region //#region 绘制图形 //if (CommonLib.MapMouseFlag >= 1 && CommonLib.MapMouseFlag <= 4) //{ // //初始化Color // IRgbColor rgbColor1 = new RgbColor(); // rgbColor1.Red = 255; // rgbColor1.Green = 255; // rgbColor1.Blue = 0; // //初始化Symbol // object symbol = null; // if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline) //线 // { // ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(); // simpleLineSymbol.Color = rgbColor1; // simpleLineSymbol.Width = 5; // symbol = simpleLineSymbol; // } // else // { // ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(); // simpleFillSymbol.Color = rgbColor1; // symbol = simpleFillSymbol; // } // axMapControlMainMap.DrawShape(geometry, ref symbol); //} //else if (CommonLib.MapMouseFlag == 5) //{ // //初始化Color // IRgbColor rgbColor2 = new RgbColor(); // rgbColor2.Red = 255; // rgbColor2.Green = 0; // rgbColor2.Blue = 0; // //初始化Symbol // object symbol = null; // ITextSymbol textSymbol = new TextSymbol(); // textSymbol.Color = rgbColor2; // symbol = textSymbol; // axMapControlMainMap.DrawText(geometry, "顶你个肺", ref symbol); //} //#endregion //#region 空间选择 //if (CommonLib.MapMouseFlag >= 11 && CommonLib.MapMouseFlag <= 15) //{ // axMapControlMainMap.Map.SelectByShape(geometry, null, false); //} //axMapControlMainMap.Refresh(); //#endregion #endregion }