Hoppa till huvudinnehållet

Remove multiple features from featureset

Kommentarer

3 kommentarer

  • Zack Robison
    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 of featuresetVar.Features = featuresetVar.Features.Where(Function(feat) feat.Attributes("FIELD").toString = "4")

     

     
    0
  • Permanently deleted user
    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,

     

    Mike
    0
  • Zack Robison

    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

Du måste logga in om du vill lämna en kommentar.