C#AE实现点选查询

查询结果

 

mapControl.MousePointer = esriControlsMousePointer.esriPointerIdentify;//修改鼠标样式
            mapControl.OnMouseDown += new AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEventHandler(EsriMapEvent.MapSelection_OnMouseDown);//添加事件

 

 public static void MapSelection_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            AxMapControl map = sender as AxMapControl;
            if (e.button == 1 && map.MousePointer == esriControlsMousePointer.esriPointerIdentify)
            {
                
                #region//获取点选的属性表
                map.Map.ClearSelection();
                IPoint pt = new PointClass();
                pt.PutCoords(e.mapX, e.mapY);
                //根据像素获取实际距离
                double length = map.ActiveView.ConvertPixelsToMapUnits();
                //获取到点选的线
                ITopologicalOperator topoint = pt as ITopologicalOperator;
                //获取缓冲区
                IGeometry buffer = topoint.Buffer(length);
                //选中要素,只有一个要素
                map.Map.SelectByShape(buffer, null, true);
                map.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                IEnumFeature pEnumFeature = map.Map.FeatureSelection as IEnumFeature;
                IFeature pFeature = pEnumFeature.Next();
                if (pFeature == null)
                    return;
                IFeatureClass pfeatureClass = pFeature.Class as IFeatureClass;
                for (int i = 0; i < map.Map.LayerCount; i++)
                {
                    if (map.get_Layer(i) is IFeatureLayer)
                    {
                        IFeatureClass iFeatureCla = (map.get_Layer(i) as IFeatureLayer).FeatureClass;
                        if (iFeatureCla == pfeatureClass)
                        {
                            int OID = Convert.ToInt32(pFeature.Value[0]);
                            pFeature = iFeatureCla.GetFeature(OID);
                            break;
                        }
                    }
                }

                DataTable dt = GetFeatureDataTable(pFeature);
                Form attributeData = new Form();
                attributeData.SetBounds(150, 150, 350, 500);

//dev控件GridControl,用来存放属性数据
                GridControl gridControl = new GridControl();
                gridControl.DataSource = dt;
                attributeData.Controls.Add(gridControl);
                gridControl.Dock = DockStyle.Fill;
                attributeData.Show();
                //清除选择
                map.Map.ClearSelection();

                #endregion
            }

        }
        #region//获得Ifeature的属性及字段
        public static DataTable GetFeatureDataTable(IFeature pFeature)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("位置:");
            dt.Columns.Add("数据:");

            for (int i = 0; i < pFeature.Fields.FieldCount; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = pFeature.Fields.Field[i].Name;
                dr[1] = pFeature.Value[i];
                dt.Rows.Add(dr);
            }
            return dt;
        }
        #endregion

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
栅格计算器是一种常见的计算机应用程序,它允许用户在一个矩形的网格中输入数值,然后对这些数值进行各种计算。在本文中,我们将使用C#AE(Adobe After Effects)来实现一个简单的栅格计算器功能。 首先,在AE中创建一个新的合成(Composition),并添加一个文本层(Text Layer)。将文本层的内容设置为“栅格计算器”,并将其放置在合成的顶部。 接下来,我们需要创建一个矩形网格,以便用户可以输入数值。我们可以使用AE中的形状层(Shape Layer)来创建一个矩形。在AE中,选择“Layer”->“New”->“Shape Layer”来创建一个新的形状层。选择“Rectangle Tool”(矩形工具),并在画布上绘制一个矩形。然后,选择矩形图层,打开“Add”->“Fill”属性,选择一种颜色填充矩形。 现在,我们需要将矩形网格分成若干个小格子,以便用户可以在其中输入数值。我们可以使用C#编写一个简单的脚本来完成这个任务。在Visual Studio中创建一个新的C#控制台应用程序,并将其命名为“GridCalculator”。 在GridCalculator项目中,我们需要添加一个引用,以便我们可以访问AE中的COM(Component Object Model)对象。选择“Project”->“Add Reference”,然后在“COM”选项卡中找到“Adobe After Effects XX.X Type Library”(其中XX.X表示你的AE版本号),并添加它。 接下来,我们需要编写一个C#脚本来创建网格。以下是一个示例脚本: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AE_COM; namespace GridCalculator { class Program { static void Main(string[] args) { // Create a new AE project var ae = new Application(); var proj = ae.NewProject(); // Create a new composition var comp = proj.Items.AddComp("Grid Calculator", 1920, 1080, 1.0, 10.0, 30); // Add a new shape layer var shapeLayer = comp.Layers.AddShape(); shapeLayer.Name = "Grid"; // Create a new rectangle shape var rect = new Shape(); var rectGroup = new ShapeGroup(); rectGroup.AddShape(rect); shapeLayer.Property("Contents").AddProperty("ADBE Vector Group").SetValue(rectGroup); // Set the rectangle size rect.Size = new PointF(400, 400); // Create the grid var rows = 10; var cols = 10; var cellSize = new PointF(rect.Size.X / cols, rect.Size.Y / rows); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { // Create a new rectangle shape for each cell var cell = new Shape(); var cellGroup = new ShapeGroup(); cellGroup.AddShape(cell); shapeLayer.Property("Contents").AddProperty("ADBE Vector Group").SetValue(cellGroup); // Set the cell position and size var pos = new PointF(col * cellSize.X, row * cellSize.Y); cell.Position = pos; cell.Size = cellSize; } } // Save the project proj.Save(@"C:\GridCalculator.aep"); // Quit AE ae.Quit(); } } } ``` 在上面的脚本中,我们首先创建了一个新的AE项目和一个新的合成。然后,我们添加了一个新的形状层,并在其中创建了一个矩形。接下来,我们使用嵌套循环创建了一个网格,其中每个单元格都是一个独立的矩形。 最后,我们保存了AE项目,并退出AE应用程序。 现在,我们可以在AE中打开“GridCalculator.aep”文件,并将生成的网格图层拖放到我们之前创建的合成中。用户现在可以在每个单元格中输入数值,并使用AE中的表达式(Expressions)功能对这些数值进行计算。 总的来说,使用C#AE来创建栅格计算器功能是非常简单的。通过利用AE的COM对象和C#的编程能力,我们可以轻松地创建一个自定义的栅格计算器工具,以满足我们的具体需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值