使用地图工具获取所选特性的标签

104
1
3周之前
D_CGIS
通过
新的因素

d_cgis_0 - 1623926276623. - png

大家好,我在gis pro上遇到了一些问题。我想使用maptools获取当前选择的特性的标签名称,但是我只能得到特性层标签类的集合。

谢谢

标签(3)
0荣誉
1回复
狼
通过 亚博搜索yabovip28点com
亚博搜索yabovip28点com

如果你使用'default'标签选项而不是表达式,下面的maptool应该工作:

内部类SelectLabel: MapTool{公共SelectLabel() {IsSketchTool = true;SketchType = SketchGeometryType.Rectangle;SketchOutputMode = SketchOutputMode.Map;} protected override Task OnToolActivateAsync(bool active) {return base.OnToolActivateAsync(active);} protected override async Task OnSketchCompleteAsync(Geometry Geometry) {var labels = await QueuedTask.Run(() =>{//使用几何图形做一个新的选择var selectionSet = MapView.Active. async {var labels = await QueuedTask.Run(() =>{//使用几何图形做一个新的选择var selectionSet = MapView.Active。SelectFeatures(几何、SelectionCombinationMethod。新的,真实,真实的);如果(selectionSet。Count == 0)返回“没有选定”;//感兴趣的层-只使用集合中的第一层//这个例子。你可以搜索特定的层使用Linq var selectedFeatureLayer = selectionSet.Keys.FirstOrDefault()作为FeatureLayer;//获取选定的oid var oid = selectionSet[selectedFeatureLayer]; // get the CIM definition from the layer var cimFeatureDefinition = selectedFeatureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMBasicFeatureLayer; // get the view of the source table underlying the layer var cimDisplayTable = cimFeatureDefinition.FeatureTable; // this field is used as the 'label' to represent the row var displayField = cimDisplayTable.DisplayField; // collect all var sb = new StringBuilder(); // search for all selected object ids using (RowCursor rowCursor = selectedFeatureLayer.Search(new QueryFilter() { ObjectIDs = oids })) { // Iterate through the selected features var labelFieldIndex = rowCursor.FindField(displayField); while (rowCursor.MoveNext()) { using (var row = rowCursor.Current) { // Get the label field value var labelForFeature = row[labelFieldIndex].ToString(); sb.AppendLine($@"oid: {row.GetObjectID()} label: {labelForFeature}"); } } } return sb.ToString(); }); MessageBox.Show(labels); return true; } }

如果层的标签是由一个表达式定义的(例如街机),在这一点上没有解决方案。然而,Pro Dev团队正在为即将发布的API提供脚本评估。