Skip to content

Commit

Permalink
query features by ID for selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jun 24, 2024
1 parent 1d3987d commit e405a1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -99,23 +98,23 @@ private async void HighlightObjectsOnView(List<ObjectID> objectIds)
await QueuedTask
.Run(() =>
{
List<ObjectID> objectIdAndmapMembers = GetMapMembers(objectIds, mapView);
List<ObjectID> objectIdAndMapMembers = GetMapMembers(objectIds, mapView);
ClearSelectionInTOC();
ClearSelection();
SelectMapMembersInTOC(objectIdAndmapMembers);
SelectMapMembersAndFeatures(objectIdAndmapMembers);
SelectMapMembersInTOC(objectIdAndMapMembers);
SelectMapMembersAndFeatures(objectIdAndMapMembers);
mapView.ZoomToSelected();
})
.ConfigureAwait(false);
}

private List<ObjectID> GetMapMembers(List<ObjectID> objectIds, MapView mapView)
{
List<ObjectID> objectIdAndmapMembers = new();
List<ObjectID> 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);
Expand All @@ -126,10 +125,10 @@ private List<ObjectID> GetMapMembers(List<ObjectID> objectIds, MapView mapView)
}

ObjectID newObjectId = new(objectId.MappedLayerURI, objectId.FeatureId, mapMember);
objectIdAndmapMembers.Add(newObjectId);
objectIdAndMapMembers.Add(newObjectId);
}

return objectIdAndmapMembers;
return objectIdAndMapMembers;
}

private void ClearSelection()
Expand All @@ -149,9 +148,9 @@ private void ClearSelectionInTOC()
MapView.Active.ClearTOCSelection();
}

private void SelectMapMembersAndFeatures(List<ObjectID> objectIdAndmapMembers)
private void SelectMapMembersAndFeatures(List<ObjectID> objectIdAndMapMembers)
{
foreach (ObjectID objectId in objectIdAndmapMembers)
foreach (ObjectID objectId in objectIdAndMapMembers)
{
if (objectId.MapMember == null)
{
Expand All @@ -161,42 +160,28 @@ private void SelectMapMembersAndFeatures(List<ObjectID> 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<ObjectID> objectIdAndmapMembers)
private void SelectMapMembersInTOC(List<ObjectID> objectIdAndMapMembers)
{
List<Layer> layers = new();
List<StandaloneTable> tables = new();

foreach (ObjectID objectId in objectIdAndmapMembers)
foreach (ObjectID objectId in objectIdAndMapMembers)
{
if (objectId.MapMember == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down

0 comments on commit e405a1d

Please sign in to comment.