// //获取地图状态信息 // private void GetStatusXY(double mapX, double mapY) { try { if (this._barItemXY != null) { ISpatialReference spatialReference = this._mapControl.SpatialReference; if (spatialReference != null) { if (spatialReference is IProjectedCoordinateSystem) { IProjectedCoordinateSystem projectedCoordinateSystem = spatialReference as IProjectedCoordinateSystem; IPoint point = new PointClass(); point.SpatialReference = spatialReference; point.X = mapX; point.Y = mapY; point.Project(projectedCoordinateSystem.GeographicCoordinateSystem); double lon = point.X; double lat = point.Y; int lon_degree = (int)Math.Floor(Convert.ToDecimal(lon)); int lat_degree = (int)Math.Floor(Convert.ToDecimal(lat)); lon = (lon - lon_degree) * 60; lat = (lat - lat_degree) * 60; int lon_m = (int)Math.Floor(Convert.ToDecimal(lon)); int lat_m = (int)Math.Floor(Convert.ToDecimal(lat)); lon = (lon - lon_m) * 60; lat = (lat - lat_m) * 60; int lon_s = (int)Math.Floor(Convert.ToDecimal(lon)); int lat_s = (int)Math.Floor(Convert.ToDecimal(lat)); string strLon = ""; string strLat = ""; if (lon_degree > 0) { strLon = lon_degree + "° " + lon_m + "′ " + lon_s + "″ E"; } else { strLon = lon_degree + "° " + lon_m + "′ " + lon_s + "″ E"; } if (lat_degree > 0) { strLat = lat_degree + "° " + lat_m + "′ " + lat_s + "″ N"; } else { strLat = lat_degree + "° " + lat_m + "′ " + lat_s + "″ N"; } this._barItemXY.Caption = string.Format("坐标:{0},{1}", strLon, strLat); } } else { this._barItemXY.Caption = string.Format("坐标:{0},{1}", mapX, mapY); } } if (this._barItemRaster != null) { this._barItemRaster.Visibility = BarItemVisibility.Never; if (this._rasterLayer != null) { IRaster2 raster = this._rasterLayer.Raster as IRaster2; IPoint point = new PointClass(); point.X = mapX; point.Y = mapY; point.SpatialReference = this._spatialReference; ISpatialReference spatialReference = (raster as IGeoDataset).SpatialReference; if (!EngineAPI.IsEqualSpatialReference(this._spatialReference, spatialReference)) { point.Project(spatialReference); } int colum; int row; raster.MapToPixel(point.X, point.Y, out colum, out row); if (colum >= 0 && colum <= this._rasterLayer.ColumnCount && row >= 0 && row <= this._rasterLayer.RowCount) { this._barItemRaster.Visibility = BarItemVisibility.Always; double value = CommonAPI.ConvertToDouble(raster.GetPixelValue(0, colum, row)); this._barItemRaster.Caption = string.Format("行:{0}, 列:{1}, 像素值:{2}", row, colum, value); } } } } catch (Exception ex) { Log.WriteLog(typeof(GFSApplication), ex); } }
private bool LoadROI(string inSample, out string msg) { try { msg = ""; if (roiLayerDic.Count > 0) { roiLayerDic.Clear(); } if (!string.IsNullOrEmpty(inSample) && File.Exists(inSample)) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(inSample); XmlNode xmlNode = xmlDocument.SelectSingleNode("RegionsOfInterest"); if (xmlNode == null) { msg = "ROI内容为空!"; return(false); } for (int i = 0; i < xmlNode.ChildNodes.Count; i++) { XmlNode xmlNode2 = xmlNode.ChildNodes[i]; string value = xmlNode2.Attributes[0].Value; string value2 = xmlNode2.Attributes[1].Value; string[] array = value2.Split(new char[] { ',' }); int red = CommonAPI.ConvertToInt(array[0]); int green = CommonAPI.ConvertToInt(array[1]); int blue = CommonAPI.ConvertToInt(array[2]); IRgbColor color = new RgbColorClass { Red = red, Green = green, Blue = blue }; ROILayerClass rOILayerClass = new ROILayerClass(); rOILayerClass.ID = ((roiLayerDic.Keys.Count == 0) ? 1 : (roiLayerDic.Keys.Max() + 1)); rOILayerClass.Name = value; rOILayerClass.Color = color; rOILayerClass.ElementList = new List <ROIElementClass>(); roiLayerDic.Add(rOILayerClass.ID, rOILayerClass); string innerText = xmlNode2.SelectSingleNode("GeometryDef/CoordSysStr").InnerText; spatialReference = EngineAPI.GetSpatialRefFromPrjStr(innerText); XmlNodeList xmlNodeList = xmlNode2.SelectNodes("GeometryDef/Polygon/Exterior/LinearRing/Coordinates"); for (int j = 0; j < xmlNodeList.Count; j++) { IPointCollection pointCollection = new PolygonClass(); string innerText2 = xmlNodeList[j].InnerText; string[] array2 = innerText2.Split(new char[] { ' ' }); int num = array2.Length / 2; for (int k = 0; k < num; k++) { IPoint point = new PointClass(); double x = CommonAPI.ConvertToDouble(array2[2 * k]); double y = CommonAPI.ConvertToDouble(array2[2 * k + 1]); point.PutCoords(x, y); object value3 = Missing.Value; object value4 = Missing.Value; pointCollection.AddPoint(point, ref value3, ref value4); } IPolygon polygon = pointCollection as IPolygon; polygon.FromPoint = pointCollection.get_Point(0); polygon.ToPoint = pointCollection.get_Point(pointCollection.PointCount - 1); if (spatialReference == null) { spatialReference = new UnknownCoordinateSystemClass(); } polygon.SpatialReference = spatialReference; polygon.Close(); IElement element = new PolygonElementClass(); element.Geometry = polygon; ROIElementClass rOIElementClass = new ROIElementClass { Element = element, Checked = true }; rOILayerClass.ElementList.Add(rOIElementClass); } } } return(true); } catch (Exception ex) { msg = ex.Message; return(false); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 1) { List <ILayer> layers = EngineAPI.GetLayers(this.m_hookHelper.FocusMap, "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}", null); if (layers.Count == 0) { IdentifyManager.instance.FrmIdentify.Close(); IdentifyManager.instance.FrmIdentify = null; EnviVars.instance.MapControl.CurrentTool = null; EnviVars.instance.MapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } else { foreach (ILayer current in layers) { IIdentify identify = current as IIdentify; IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IArray array = identify.Identify(point); if (array != null && array.Count != 0) { IdentifyManager.instance.FrmIdentify.treeList1.ClearNodes(); IIdentifyObj identifyObj = array.get_Element(0) as IIdentifyObj; identifyObj.Flash(this.m_hookHelper.ActiveView.ScreenDisplay); TreeListNode treeListNode = IdentifyManager.instance.FrmIdentify.treeList1.AppendNode(new object[] { identifyObj.Layer.Name }, 0, identifyObj); DataColumn column = new DataColumn("字段", typeof(string)); DataColumn column2 = new DataColumn("值", typeof(string)); DataTable dataTable = new DataTable(); dataTable.Columns.Add(column); dataTable.Columns.Add(column2); if (current is IFeatureLayer) { IFeature feature = (identifyObj as IRowIdentifyObject).Row as IFeature; TreeListNode treeListNode2 = IdentifyManager.instance.FrmIdentify.treeList1.AppendNode(new object[] { feature.OID.ToString() }, treeListNode); int num = feature.Fields.FindField((current as IFeatureLayer).FeatureClass.ShapeFieldName); for (int i = 0; i < feature.Fields.FieldCount; i++) { if (num != i) { DataRow dataRow = dataTable.NewRow(); dataRow["字段"] = feature.Fields.get_Field(i).AliasName; dataRow["值"] = feature.get_Value(i).ToString(); dataTable.Rows.Add(dataRow); } } treeListNode2.Tag = dataTable; } else if (current is IRasterLayer) { IRasterLayer rasterLayer = current as IRasterLayer; IRaster2 raster = rasterLayer.Raster as IRaster2; int num2 = raster.ToPixelRow(point.Y); int num3 = raster.ToPixelColumn(point.X); double num4 = CommonAPI.ConvertToDouble(raster.GetPixelValue(0, num3, num2)); this.AddRow(dataTable, "像素值", num4); this.AddRow(dataTable, "行号", num2); this.AddRow(dataTable, "列号", num3); IRasterIdentifyObj rasterIdentifyObj = array.get_Element(0) as IRasterIdentifyObj; if (rasterLayer.BandCount != 1) { Regex regex = new Regex("\\d{2,3}"); MatchCollection matchCollection = regex.Matches(rasterIdentifyObj.MapTip); if (matchCollection.Count == 3) { this.AddRow(dataTable, "R", matchCollection[0].Value); this.AddRow(dataTable, "G", matchCollection[1].Value); this.AddRow(dataTable, "B", matchCollection[2].Value); } } IdentifyManager.instance.FrmIdentify.treeList1.AppendNode(new object[] { rasterIdentifyObj.Name }, treeListNode, dataTable); } IdentifyManager.instance.FrmIdentify.UpdateStatusText(string.Format("X:{0:0.000 },Y:{1:0.000}", point.X, point.Y)); IdentifyManager.instance.FrmIdentify.treeList1.ExpandAll(); if (treeListNode.Nodes.Count > 0) { IdentifyManager.instance.FrmIdentify.treeList1.FocusedNode = treeListNode.Nodes[0]; } IdentifyManager.instance.FrmIdentify.Show(); break; } IdentifyManager.instance.FrmIdentify.Close(); IdentifyManager.instance.FrmIdentify = null; } } } }