Reputation: 213
public class Vertex
{
public int FeatureClassID {get;private set;}
public int Index { get; private set; }
public int OID { get; private set; }
}
Index: Index of the vertex on the referenced Line Feature
Dictionary<string, List<Vertex>> _allVertexes
string: X,Y coordinate. So it's a collection of coordinates and for every coordinate all points that are located at the given X-Y location.
So it might look like this:
"X-Y: 839-531"
[0]
"featureClass: 1"
"OID: 59"
"index: 5"
[1]
"featureClass: 1"
"OID: 13"
"index: 3"
"X-Y: 955-649"
[0]
"featureClass: 1"
"OID: 13"
"index: 3"
[0]
"featureClass: 2"
"OID: 2"
"index: 5"
I need to find duplicates, which is pretty easy, just every coordinate that has more then 1 point. BUT I need to find all indices for the same OID for every FeatureClass at once.
So i want to have it grouped like this:
"featureClass: 1"
"feature: 59"
"index: 1"
"index: 5"
"feature: 5"
"index: 3"
"index: 6"
"index: 7"
"featureClass: 2"
"feature: 13"
"index: 2"
"index: 6"
so that's what I need. How would you do that?
Upvotes: 0
Views: 310
Reputation: 5523
Start with flattening the dictionary values.
var values = _allVertexes.Values.SelectMany(v => v);
Now that you have all the vertexes in one place, it is time to group them up by FeatureClassId and OID.
var grouped = values.GroupBy(v => new { v.FeatureClassId, v.OID });
All that is left now is iterating over the grouped collection and do whatever you want with them.
Alternatively, if you want two level grouping then do grouping on FeatureClassId, then group their elements by OID.
var grouped = values.GroupBy(v => v.FeatureClassId).Select(g => g.GroupBy(v => v.OID));
Upvotes: 2