private IEnumerable <Feature> IntersectFeatures(IEnumerable <Feature> features) { List <Feature> featuresList = features.ToList(); var results = new ConcurrentStack <Feature>(); var featureGroups = featuresList.GroupBy(feature => feature.Tag).ToList(); int index = 1; for (int i = 0; i < featureGroups.Count; i++) { var group = featureGroups[i]; foreach (var feature in group) { int progress = index * 100 / featuresList.Count; ReportProgress(progress); var otherFeatures = featureGroups.Where(g => featureGroups.IndexOf(g) > i).SelectMany(f => f); Parallel.ForEach(otherFeatures, otherFeature => { try { AreaBaseShape originalShape = (AreaBaseShape)feature.GetShape(); AreaBaseShape matchShape = (AreaBaseShape)otherFeature.GetShape(); if (originalShape.Intersects(matchShape)) { AreaBaseShape resultShape = originalShape.GetIntersection(matchShape); if (resultShape != null) { var columnValues = GetColumnValues(feature, otherFeature); Feature resultFeature = new Feature(resultShape, columnValues); results.Push(resultFeature); } } } catch (Exception ex) { HandleExceptionFromInvalidFeature(feature.Id, ex.Message); } }); index++; } } return(results); }