示例#1
0
        public Identify(ILayer layer, IPoint position, IRow row, IRasterIdentifyObj pixel, Language lang)
        {
            InitializeComponent();
            if (lang == Language.English)
            {
                this.Text   = "Identify";
                label2.Text = "Layer";
                label1.Text = "Position";
            }
            rtbAttribute.ReadOnly = true;
            txtLayer.ReadOnly     = true;
            txtPosition.ReadOnly  = true;
            txtPosition.Text      = position.X + "," + position.Y;
            if (layer is IFeatureLayer)
            {
                if (lang == Language.Chinese)
                {
                    txtLayer.Text = layer.Name + "(矢量图层)";
                }
                else if (lang == Language.English)
                {
                    txtLayer.Text = layer.Name + "(Feature Layer)";
                }
                IFeatureLayer featureLayer = layer as IFeatureLayer;
                IFeatureClass feature      = featureLayer.FeatureClass;
                int           shpIndex     = feature.FindField(feature.ShapeFieldName);
                string        shpType      = feature.ShapeType.ToString().Substring(12);
                if (lang == Language.Chinese)
                {
                    switch (shpType)
                    {
                    case "Point":
                        shpType = "点";
                        break;

                    case "Polyline":
                        shpType = "线";
                        break;

                    case "Polygon":
                        shpType = "面";
                        break;
                    }
                }

                for (int i = 0; i < row.Fields.FieldCount; i++)
                {
                    if (i == shpIndex)
                    {
                        rtbAttribute.AppendText(feature.Fields.get_Field(i).Name + "*:" + shpType + "\n");
                    }
                    else
                    {
                        rtbAttribute.AppendText(row.Fields.get_Field(i).Name + ":" + row.get_Value(i).ToString() + "\n");
                    }
                }
            }
            else if (layer is IRasterLayer)
            {
                if (lang == Language.Chinese)
                {
                    txtLayer.Text = layer.Name + "(栅格图层)";
                }
                else if (lang == Language.English)
                {
                    txtLayer.Text = layer.Name + "(Raster Layer)";
                }
                string[] values = new string[1];
                if (pixel.MapTip.Contains(","))
                {
                    values = pixel.MapTip.Split(',');
                }
                else
                {
                    values[0] = pixel.MapTip;
                }
                for (int i = 0; i < values.Length; i++)
                {
                    if (i != 0)
                    {
                        if (values[i].Contains("="))
                        {
                            rtbAttribute.AppendText(values[i].Replace('=', ':').Substring(1) + "\n");
                        }
                        else
                        {
                            rtbAttribute.AppendText(values[i] + "\n");
                        }
                    }
                    else
                    {
                        if (values[i].Contains("="))
                        {
                            rtbAttribute.AppendText(values[i].Replace('=', ':') + "\n");
                        }
                        else
                        {
                            rtbAttribute.AppendText(values[i] + "\n");
                        }
                    }
                }
            }
        }
示例#2
0
 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;
             }
         }
     }
 }