关于IFeatureSelection的SelectFeatures方法

本文探讨了使用IFeatureLayer作为IFeatureSelection时遇到的问题:SelectFeatures方法返回的SelectionSet集合存在大约105,399条记录的上限,即使实际数据量远超此数。文中寻求对于该现象背后原因的专业解答。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


近期做项目时用到IFeatureLayer as IFeatureSelection,然后使用IFeatureSelection.SelectFeatures方法。可是得到的IFeatureSelection.SelectionSet集合中的Count大概有105399个,而实际上的数据有17000+,也就是说这种方法实际上的选择数据集是有上限的,并不会返回当前图层超过了105399这个上限的数据,可是我在MSDN中也并没有发现对应的说明,所以临时理解为他是有上限的,假设各位大神知道为啥,请不吝不吝赐教。

修改代码,使绘制矩形的起点为在axMC上点击第一个点 using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using System; using System.Collections.Generic; using System.Windows.Forms; namespace DEMO { public partial class SpatialQueryForm : Form { private FormMain _mainForm; private AxMapControl _mapControl; private IGeometry _queryGeometry; // 空间关系字典 private readonly Dictionary<string, esriSpatialRelEnum> spatialRelations = new Dictionary<string, esriSpatialRelEnum> { { "相交", esriSpatialRelEnum.esriSpatialRelIntersects }, { "包含", esriSpatialRelEnum.esriSpatialRelContains }, { "被包含", esriSpatialRelEnum.esriSpatialRelWithin }, { "相接", esriSpatialRelEnum.esriSpatialRelTouches } }; public SpatialQueryForm(FormMain mainForm) { InitializeComponent(); _mainForm = mainForm; _mapControl = _mainForm.MapControl; lblStatus.Text = "未绘制"; } private void SpatialQueryForm_Load(object sender, EventArgs e) { // 加载图层 LoadLayers(); // 加载空间关系 comBSpatialRel.Items.Clear(); foreach (var rel in spatialRelations.Keys) { comBSpatialRel.Items.Add(rel); } comBSpatialRel.SelectedIndex = 0; // 默认选择"相交" } private void LoadLayers() { comBLayer.Items.Clear(); for (int i = 0; i < _mapControl.LayerCount; i++) { ILayer layer = _mapControl.get_Layer(i); if (layer is IFeatureLayer) comBLayer.Items.Add(layer.Name); } if (comBLayer.Items.Count > 0) comBLayer.SelectedIndex = 0; } public void ReceiveDrawnGeometry(IGeometry geometry) { _queryGeometry = geometry; lblStatus.Text = "已接收绘制图形,点击查询按钮执行"; } private void btnDraw_Click(object sender, EventArgs e) { if (_mapControl == null) return; // 重置状态 lblStatus.Text = "未绘制"; try { _mapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "请在地图上绘制矩形..."; // 绘制矩形(起点为点击的第一个点) _queryGeometry = _mapControl.TrackRectangle(); if (_queryGeometry != null && !_queryGeometry.IsEmpty) { lblStatus.Text = "矩形绘制完成,点击查询按钮执行"; } else { lblStatus.Text = "未绘制矩形"; } } catch (Exception ex) { MessageBox.Show($"绘制错误: {ex.Message}"); lblStatus.Text = "绘制失败"; } finally { _mapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } } private void btnQuery_Click(object sender, EventArgs e) { if (comBLayer.SelectedIndex == -1) { MessageBox.Show("请选择图层"); return; } if (_queryGeometry == null || _queryGeometry.IsEmpty) { MessageBox.Show("请先绘制查询矩形"); return; } string layerName = comBLayer.SelectedItem.ToString(); IFeatureLayer featureLayer = null; for (int i = 0; i < _mapControl.LayerCount; i++) { if (_mapControl.get_Layer(i).Name == layerName) { featureLayer = _mapControl.get_Layer(i) as IFeatureLayer; break; } } if (featureLayer == null) { MessageBox.Show("未找到指定图层"); return; } // 获取选择的空间关系 string selectedRel = comBSpatialRel.SelectedItem.ToString(); esriSpatialRelEnum spatialRel = spatialRelations[selectedRel]; try { ISpatialFilter spatialFilter = new SpatialFilterClass { Geometry = _queryGeometry, SpatialRel = spatialRel, GeometryField = featureLayer.FeatureClass.ShapeFieldName }; IFeatureSelection featureSelection = (IFeatureSelection)featureLayer; featureSelection.Clear(); // 执行选择 featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); // 刷新视图 _mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); _mapControl.ActiveView.Refresh(); // 显示结果 int count = featureSelection.SelectionSet.Count; lblStatus.Text = $"查询完成,选中 {count} 个要素"; MessageBox.Show($"空间查询完成,共选中 {count} 个要素", "查询结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show($"查询失败: {ex.Message}"); lblStatus.Text = "查询失败"; } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } // 图层选择变更时清除查询结果 private void comBLayer_SelectedIndexChanged(object sender, EventArgs e) { ClearSelection(); } // 清除所有选择 private void ClearSelection() { try { for (int i = 0; i < _mapControl.LayerCount; i++) { IFeatureLayer featureLayer = _mapControl.get_Layer(i) as IFeatureLayer; if (featureLayer != null) { IFeatureSelection featureSelection = featureLayer as IFeatureSelection; featureSelection.Clear(); } } // 刷新地图 _mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); _mapControl.ActiveView.Refresh(); // 重置状态 lblStatus.Text = "未绘制"; _queryGeometry = null; } catch (Exception ex) { MessageBox.Show($"清除选择失败: {ex.Message}"); } } private void comBSpatialRel_SelectedIndexChanged(object sender, EventArgs e) { ClearSelection(); } } }
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值