private void GenerateExportConfig() { Collection <SplitFileModel> exportedModels = new Collection <SplitFileModel>(); SelectedLayerToSplit.SafeProcess(() => { string selectedColumnName = SelectedFeatureSourceColumn.ColumnName; Collection <Tuple <string, int> > distinctColumnValues = new Collection <Tuple <string, int> >(); if (UseSelectedFeaturesOnly) { var tmpColumnValues = HighlightFeatureLayer.InternalFeatures .Where(tmpFeature => tmpFeature.Tag.Equals(SelectedLayerToSplit)) .Select(tmpFeature => tmpFeature.ColumnValues[selectedColumnName]); foreach (var item in tmpColumnValues.GroupBy(tmpColumnValue => tmpColumnValue)) { distinctColumnValues.Add(new Tuple <string, int>(item.Key, item.Count())); } } else { var tmpShapeFileFeatureLayer = SelectedLayerToSplit as ShapeFileFeatureLayer; Collection <string> values = new Collection <string>(); if (tmpShapeFileFeatureLayer != null) { string dbfPath = Path.ChangeExtension(tmpShapeFileFeatureLayer.ShapePathFilename, ".dbf"); GeoDbf geoDbf = new GeoDbf(dbfPath, GeoFileReadWriteMode.Read, tmpShapeFileFeatureLayer.Encoding); geoDbf.Open(); for (int i = 1; i <= geoDbf.RecordCount; i++) { var columnValue = geoDbf.ReadRecordAsString(i)[selectedColumnName]; values.Add(columnValue); } geoDbf.Close(); } else { foreach (var feature in SelectedLayerToSplit.QueryTools.GetAllFeatures(new string[] { selectedColumnName })) { values.Add(feature.ColumnValues[selectedColumnName]); } } var groupedTmpColumnValues = values.GroupBy(tmpColumnValue => tmpColumnValue); foreach (var item in groupedTmpColumnValues) { distinctColumnValues.Add(new Tuple <string, int>(item.Key, item.Count())); } } foreach (var distinctValue in distinctColumnValues) { string columnValue = distinctValue.Item1; if (!String.IsNullOrEmpty(columnValue)) { Regex regex = new Regex(@"\w*"); var matches = regex.Matches(columnValue); StringBuilder fileNameBuilder = new StringBuilder(); foreach (Match match in matches) { fileNameBuilder.Append(match.Value); } columnValue = fileNameBuilder.ToString(); } SplitFileModel model = new SplitFileModel(); model.ColumnValue = String.IsNullOrEmpty(distinctValue.Item1) ? "<Blank>" : distinctValue.Item1; model.FeatureCount = distinctValue.Item2; model.OutputFileName = String.Format(CultureInfo.InvariantCulture , "{0}_{1}" , SelectedLayerToSplit.Name , String.IsNullOrEmpty(columnValue) ? "unknown" : columnValue); if (exportedModels .Any(tmpModel => tmpModel.OutputFileName.Equals(model.OutputFileName, StringComparison.OrdinalIgnoreCase))) { var count = exportedModels.Count(tmpModel => tmpModel.OutputFileName.Equals(model.OutputFileName, StringComparison.OrdinalIgnoreCase)); model.OutputFileName += String.Format(CultureInfo.InvariantCulture, "_{0}", count); //model.OutputFileName = model.OutputFileName.Replace(".shp" //, String.Format(CultureInfo.InvariantCulture, "_{0}.shp", count)); } exportedModels.Add(model); } }); #if GISEditorUnitTest foreach (var model in exportedModels) { ExportConfiguration.Add(model); } #else if (Application.Current != null) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var model in exportedModels) { ExportConfiguration.Add(model); } })); } #endif IsBusy = false; BusyContent = String.Empty; CurrentThread = null; }