Remove multiple features from featureset
I have a workflow where any number of parcels might be in a featureset. I would like to remove all parcels where a specific field is not equal to "4" and then use the modified featureset later in the workflow.
I found this post
(https://support.geocortex.com/customer/essentialsGSCForum?sub-nav=forum&main-nav=essentials&#!/feedtype=SINGLE_QUESTION_DETAIL&criteria=ALLQUESTIONS&id=90660000000062bAAA) that uses RemoveFromCollection to remove one feature. I can't figure out how to loop through to remove more than one. If I put the RemoveFromCollection into a ForEach, I get an error after the first item is removed saying that the collection has been modified, so it won't continue.
Any help is greatly appreciated,
Mike
0
-
You can't modify a collection while you iterate it. If you created a duplicate featureset, iterated the first and removed from the new, then you'd be fine. It's not how I'd do it, but it will work and you're pretty close to that already.
If you're interested, I'd use a LINQ expression for this. Something to the tune offeaturesetVar.Features = featuresetVar.Features.Where(Function(feat) feat.Attributes("FIELD").toString = "4")0 -
Zack,
Thank you for the answer.
I would be interested in a cleaner way to accomplish this, but I'm unsure how/where to include the LINQ expression. Do I still need to somehow loop through the featureset?
Do you have or know of an example workflow that I could look at?
Thanks again,
Mike0 -
I don't have an example at this time (sorry), but intend to do a blog post sometime this summer to outline how to take advantage of LINQ in wpf applications like workflow. What I provided above would go into an assignment activity with L value featureset.Features and R value of the stuff on the right hand of the equals sign.
Iteration is handled by the .Where method, which can only be called on an enumerable object (such as a .Features property, which is itelf a collection of Graphics IIRC). The compiler takes your query from the arguments of the .Where method and builds its own foreach loop for you, which is pretty clean code and in my experience runs faster than writing a bunch of WPF activities.
What the expression that I gave you does is provide the compiler the instructions that it needs to construct the query for you from a data source (featureset.features) and a query (feat.Attributes("FIELD").toString = "4"). If you want to get a better understanding of what's happening, check out the "Where and Select" section of this lovely MSDN article (https://www.codeproject.com/Articles/383749/How-does-it-work-in-Csharp-Part-Csharp-LINQ-in-d#paraIdWhereSelect) , I personally found the graphic to be illuminating WRT the way in which our simple interface with LINQ turns into a more complex function in the .NET CLR.0
Please sign in to leave a comment.
Comments
3 comments