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

449
1
06-17-2021 03:42 am
D_CGIS
通过
新贡献者II

d_cgis_0 - 1623926276623. - png

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

谢谢

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

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

内部类SelectLabel: MapTool {public SelectLabel() {IsSketchTool = true;SketchType = sketch几何类型。矩形;SketchOutputMode = SketchOutputMode. map;} protected override Task OnToolActivateAsync(bool active){返回base.OnToolActivateAsync(active);} protected override async Task OnSketchCompleteAsync(几何几何){var labels = await QueuedTask.Run(() =>{//使用几何体做一个新的选择var selectionSet = MapView.Active。SelectFeatures(几何、SelectionCombinationMethod。新,真,真);如果(selectionSet。Count == 0)返回"nothing selected";//感兴趣的层-在这个例子中只使用集合中的第一层。你可以搜索特定的层使用Linq var selectedFeatureLayer = selectionSet.Keys.FirstOrDefault() as FeatureLayer;//获取选中的oid var Oids = 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; } }

如果层的标签是由表达式(如Arcade)定义的,那么在这一点上没有解决方案。不过,Pro Dev团队正致力于在即将发布的版本中为API提供脚本评估。