当前位置>>知识集锦

有时在基于AE二次开发时,需要用到点选查询的功能,这个原理和实现都比较简单。只需先根据鼠标位置建立一个缓冲区,与图层进行叠加分析就可以了。以下是一段由C#编写的基于空间位置查询的代码,实现的功能是用户在界面用鼠标点选,对话框弹出选择的要素,基于Arcgis Engine 10.0以及VS2010调试成功。

 

if (DoQueryIndex == 1)        // DoQueryIndex控制是否进行查询

            {

                ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as ESRI.ArcGIS.Carto.IFeatureLayer; //get_layer决定查找哪些图层

                ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();

                point.PutCoords(e.mapX, e.mapY);

                ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();

                spatialFilter.Geometry = point;

                spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;

                ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = pFeatureLayer.Search(spatialFilter, false);

                ESRI.ArcGIS.Geodatabase.IFeature pFeature;

                while ((pFeature = featureCursor.NextFeature()) != null)

                {

                    axMapControl1.FlashShape(pFeature.Shape);

                    MessageBox.Show(pFeature.get_Value(2).ToString()); //获取要素属性

                }

            }





评论