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
Solved! Go to Solution.
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);
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);
Thanks for the advice, but this code definitely won't display the list.
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);
}
I understood what you meant, but it's still not. But thank you.
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!