From e405a1dc14fa6c878525c181e0778b7e5ee78b00 Mon Sep 17 00:00:00 2001 From: KatKatKateryna Date: Mon, 24 Jun 2024 13:31:49 +0100 Subject: [PATCH] query features by ID for selection --- .../Bindings/BasicConnectorBinding.cs | 47 +++++++------------ .../Operations/Receive/HostObjectBuilder.cs | 4 +- 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/BasicConnectorBinding.cs b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/BasicConnectorBinding.cs index 888b40f71c..c1ce59e4fc 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/BasicConnectorBinding.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/BasicConnectorBinding.cs @@ -1,6 +1,5 @@ using System.Reflection; using ArcGIS.Core.Data; -using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Mapping; using Speckle.Connectors.ArcGIS.HostApp; @@ -99,11 +98,11 @@ private async void HighlightObjectsOnView(List objectIds) await QueuedTask .Run(() => { - List objectIdAndmapMembers = GetMapMembers(objectIds, mapView); + List objectIdAndMapMembers = GetMapMembers(objectIds, mapView); ClearSelectionInTOC(); ClearSelection(); - SelectMapMembersInTOC(objectIdAndmapMembers); - SelectMapMembersAndFeatures(objectIdAndmapMembers); + SelectMapMembersInTOC(objectIdAndMapMembers); + SelectMapMembersAndFeatures(objectIdAndMapMembers); mapView.ZoomToSelected(); }) .ConfigureAwait(false); @@ -111,11 +110,11 @@ await QueuedTask private List GetMapMembers(List objectIds, MapView mapView) { - List objectIdAndmapMembers = new(); + List objectIdAndMapMembers = new(); foreach (ObjectID objectId in objectIds) { - MapMember mapMember = mapView.Map.FindLayer(objectId.MappedLayerURI); + MapMember mapMember = mapView.Map.FindLayer(objectId.MappedLayerURI, true); if (mapMember is null) { mapMember = mapView.Map.FindStandaloneTable(objectId.MappedLayerURI); @@ -126,10 +125,10 @@ private List GetMapMembers(List objectIds, MapView mapView) } ObjectID newObjectId = new(objectId.MappedLayerURI, objectId.FeatureId, mapMember); - objectIdAndmapMembers.Add(newObjectId); + objectIdAndMapMembers.Add(newObjectId); } - return objectIdAndmapMembers; + return objectIdAndMapMembers; } private void ClearSelection() @@ -149,9 +148,9 @@ private void ClearSelectionInTOC() MapView.Active.ClearTOCSelection(); } - private void SelectMapMembersAndFeatures(List objectIdAndmapMembers) + private void SelectMapMembersAndFeatures(List objectIdAndMapMembers) { - foreach (ObjectID objectId in objectIdAndmapMembers) + foreach (ObjectID objectId in objectIdAndMapMembers) { if (objectId.MapMember == null) { @@ -161,42 +160,28 @@ private void SelectMapMembersAndFeatures(List objectIdAndmapMembers) MapMember member = objectId.MapMember; if (member is FeatureLayer layer) { - // select full layer if featureID not specified if (objectId.FeatureId == null) { + // select full layer if featureID not specified layer.Select(); } else { - using (RowCursor rowCursor = layer.Search()) - { - int index = 0; - while (rowCursor.MoveNext()) - { - if (index == objectId.FeatureId) - { - //Get the shape from the row and set extent - using (var feature = rowCursor.Current as Feature) - { - Geometry? geometry = feature?.GetShape(); - MapView.Active.SelectFeatures(geometry, SelectionCombinationMethod.Add); - } - break; - } - index += 1; - } - } + // query features by ID + var objectIDfield = layer.GetFeatureClass().GetDefinition().GetObjectIDField(); + QueryFilter anotherQueryFilter = new() { WhereClause = $"{objectIDfield} = {objectId.FeatureId + 1}" }; + using (Selection onlyOneSelection = layer.Select(anotherQueryFilter, SelectionCombinationMethod.New)) { } } } } } - private void SelectMapMembersInTOC(List objectIdAndmapMembers) + private void SelectMapMembersInTOC(List objectIdAndMapMembers) { List layers = new(); List tables = new(); - foreach (ObjectID objectId in objectIdAndmapMembers) + foreach (ObjectID objectId in objectIdAndMapMembers) { if (objectId.MapMember == null) { diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs index e704cdc105..4ef18a0041 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs @@ -131,7 +131,7 @@ CancellationToken cancellationToken // add layer and layer URI to tracker trackerItem.AddConvertedMapMember(value); trackerItem.AddLayerURI(value.URI); - conversionTracker[item.Key] = trackerItem; + conversionTracker[item.Key] = trackerItem; // not necessary atm, but needed if we use conversionTracker further // only add a report item AddResultsFromTracker(trackerItem, results); } @@ -143,7 +143,7 @@ CancellationToken cancellationToken // add layer and layer URI to tracker trackerItem.AddConvertedMapMember(mapMember); trackerItem.AddLayerURI(mapMember.URI); - conversionTracker[item.Key] = trackerItem; + conversionTracker[item.Key] = trackerItem; // not necessary atm, but needed if we use conversionTracker further // add layer URI to bakedIds bakedObjectIds.Add(trackerItem.MappedLayerURI == null ? "" : trackerItem.MappedLayerURI);