NetMap中选择要素

来源:互联网 发布:遗传算法中的objv 编辑:程序博客网 时间:2024/05/18 02:34

选择工具本质上就是图形关系的查询工具,一般分为:按框选择、按圆选择、按多边形选择、按套索选择等。

按结果集的种类又分为:新建、添加、移除等。

选择工具从图形界面发起,内部调用GIS的空间查询,将选择结果添加到选择集,最后地图渲染时将选择集绘制出来。

以下是NetMap中按框选择工具的核心代码:

                IDisplayTransformation trans = View.DisplayTransformation;                //构建范围                double x1 = 0, y1 = 0, x2 = 0, y2 = 0;                trans.ToMapPoint(_downx, _downy, ref x1, ref y1);                trans.ToMapPoint(e.X, e.Y, ref x2, ref y2);                IEnvelope box = new Envelope(x1, y1, x2, y2);                //构建查询器                ISpatialFilter filter = new SpatialFilter();                filter.Geometry = box as IGeometry;                filter.SpatialRelationship = geoSpatialRelationship.GEO_SPATIALRELATIONSHIP_ENVELOPEINTERSECTS;                //选择                IMapDocument document = View.MapDocument;                ILayer layer = null;                for (int i = 0; i < document.LayerCount; i++)                {                    layer = document.GetLayer(i);                    if (layer.Visible                    && trans.ScaleRatio >= layer.MinScale                    && trans.ScaleRatio <= layer.MaxScale                    && (layer is IFeatureSelection))                    {                        IFeatureSelection featureSelection = layer as IFeatureSelection;                        featureSelection.Select(filter, geoSelectionResultEnum.GEO_SELECTIONRESULT_NEW);                    }                }                View.Invalidate();

选择的效果如下:


0 0
原创粉丝点击