Select to view content in your preferred language

How do I select a list on a map?

804
5
Jump to solution
03-07-2022 12:58 AM
DavidMrázek
Occasional Contributor II

Good day,
in my application I would like to search for some elements in the map, and then add them to the list. After going through all the elements, I would mark all the elements from the list on the map. but I don't know how to choose elements from the list.

Here is a code sample:

 private async Task DeletePolygonInPolygon(CancelableProgressorSource cps, uint steps, FeatureLayer polygonLayer, QueryFilter queryFilter)
        {
            await QueuedTask.Run(async () =>
            {
                var polyCursor = polygonLayer.Search(queryFilter);
                cps.Progressor.Max = (uint)steps;
                cps.Progressor.Message = "Probíhá ";
                List<Row> features = new List<Row>();
                while (polyCursor.MoveNext() && !cps.Progressor.CancellationToken.IsCancellationRequested)
                {
                    cps.Progressor.Value += 1;
                    cps.Progressor.Status = cps.Progressor.Value + @" z " + cps.Progressor.Max + @" hotovo.";
                    var lineFeature = polyCursor.Current as Feature;
                    var polygonGeometry = lineFeature.GetShape() as Polygon;
                    long oid = polyCursor.Current.GetObjectID();
                    var spatialQuery = new SpatialQueryFilter()
                    { FilterGeometry = polygonGeometry, SpatialRelationship = SpatialRelationship.Within };
                    spatialQuery.WhereClause = "OBJECTID <> " + oid;
                    
                    var rowCursor = polygonLayer.Search(spatialQuery);
                    while (rowCursor.MoveNext())
                    {
                        features.Add(rowCursor.Current);
                    }
                }
                mv.Map.SetSelection(features);//here I dont know,how to write it
                object[] listOfPara = { polygonLayer };
                await StartATask("management.DeleteFeatures", listOfPara);
            }, cps.Progressor);
        }

 

Thank you

David

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You can select direct from layer:

await QueuedTask.Run(async () =>
{
    polygonLayer.Select(queryFilter, SelectionCombinationMethod.New);
    object[] listOfPara = { polygonLayer };
    await StartATask("management.DeleteFeatures", listOfPara);
}, cps.Progressor);

 

View solution in original post

5 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You can select direct from layer:

await QueuedTask.Run(async () =>
{
    polygonLayer.Select(queryFilter, SelectionCombinationMethod.New);
    object[] listOfPara = { polygonLayer };
    await StartATask("management.DeleteFeatures", listOfPara);
}, cps.Progressor);

 

DavidMrázek
Occasional Contributor II

Thanks for the advice, but this code definitely won't display the list.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Sorry. I think you will understand that you can select layer by query directly. Full code for your realization could be like this:

private async Task DeletePolygonInPolygon(CancelableProgressorSource cps, uint steps, FeatureLayer polygonLayer, QueryFilter queryFilter)
        {
            await QueuedTask.Run(async () =>
            {
                polygonLayer.ClearSelection();
                var polyCursor = polygonLayer.Search(queryFilter);
                cps.Progressor.Max = (uint)steps;
                cps.Progressor.Message = "Probíhá ";
                List<Row> features = new List<Row>();
                while (polyCursor.MoveNext() && !cps.Progressor.CancellationToken.IsCancellationRequested)
                {
                    cps.Progressor.Value += 1;
                    cps.Progressor.Status = cps.Progressor.Value + @" z " + cps.Progressor.Max + @" hotovo.";
                    var lineFeature = polyCursor.Current as Feature;
                    var polygonGeometry = lineFeature.GetShape() as Polygon;
                    long oid = polyCursor.Current.GetObjectID();
                    var spatialQuery = new SpatialQueryFilter()
                    { FilterGeometry = polygonGeometry, SpatialRelationship = SpatialRelationship.Within };
                    spatialQuery.WhereClause = "OBJECTID <> " + oid;
                    
                    polygonLayer.Select(spatialQuery, SelectionCombinationMethod.Add);
                }
                object[] listOfPara = { polygonLayer };
                await StartATask("management.DeleteFeatures", listOfPara);
            }, cps.Progressor);
        }
DavidMrázek
Occasional Contributor II

I understood what you meant, but it's still not. But thank you.

0 Kudos
DavidMrázek
Occasional Contributor II

I'm sorry, you were right, it's correct and functional, I didn't notice that I was already rewriting things in the code ... Thank you!

0 Kudos