public DataTable ReadDataToDataGrid(string inputFilePath, string customParameter) { DataTable PreviewDataTable = new DataTable(); if (File.Exists(inputFilePath)) { return(DataJoinAdapter.ReadDataToDataGrid(inputFilePath, customParameter)); } return(PreviewDataTable); }
private void ReadDataColumnToAdd() { //CsvFeatureSource csvFeatureSource = new CsvFeatureSource(SelectedDataFilePath); //csvFeatureSource.Delimiter = Delimiters[SelectedDelimiter.Key]; //csvFeatureSource.Open(); //foreach (var column in csvFeatureSource.GetColumns()) //{ // DataJoinFeatureSourceColumn csvColumn = new DataJoinFeatureSourceColumn(column.ColumnName, column.TypeName, column.MaxLength); // delimitedFileColumns.Add(csvColumn); // SourceColumnsList.Add(csvColumn); //} //csvFeatureSource.Close(); Collection <FeatureSourceColumn> columns = DataJoinAdapter.GetColumnToAdd(SelectedDataFilePath, Delimiters[SelectedDelimiter.Key]); foreach (var column in columns) { delimitedFileColumns.Add(column); SourceColumnsList.Add(column); } }
private void CreateShapeFile(ObservableCollection <FeatureSourceColumn> includedColumnsList , string OutputPath, Encoding ShapeFileEncoding, string csvFilePath , List <Feature> features , bool isIncludeAllFeatures , IEnumerable <MatchCondition> matchConditions , Action <UpdatingTaskProgressEventArgs> updateAction , Dictionary <string, string> invalidColumns) { Collection <DbfColumn> includeColumns = new Collection <DbfColumn>(); RemoveUnduplicateColumn(includedColumnsList); foreach (var column in includedColumnsList) { DbfColumnType tmpDbfColumnType = DbfColumnType.Character; if (Enum.TryParse(column.TypeName, out tmpDbfColumnType)) { DbfColumn dbfColumn = new DbfColumn(column.ColumnName, tmpDbfColumnType, column.MaxLength, 0); includeColumns.Add(dbfColumn); } } ShapeFileType shapeFileType = GetShapeFileType(features.FirstOrDefault()); if (shapeFileType != ShapeFileType.Null) { ShapeFileFeatureLayer.CreateShapeFile(shapeFileType, OutputPath, includeColumns, ShapeFileEncoding, OverwriteMode.Overwrite); var dataTable = DataJoinAdapter.ReadDataToDataGrid(csvFilePath, Delimiter); var featureRows = dataTable.Rows; var index = 0; var count = features.Count; ShapeFileFeatureLayer newShapeFileFeatureLayer = new ShapeFileFeatureLayer(OutputPath, GeoFileReadWriteMode.ReadWrite); newShapeFileFeatureLayer.SafeProcess(() => { newShapeFileFeatureLayer.EditTools.BeginTransaction(); foreach (var feature in features) { index++; try { var matchedDataRow = featureRows.Cast <DataRow>().FirstOrDefault(r => matchConditions.All(tmpCondition => feature.ColumnValues[tmpCondition.SelectedLayerColumn.ColumnName] == r[tmpCondition.SelectedDelimitedColumn.ColumnName].ToString())); if (matchedDataRow != null) { SetFeatureColumnValues(feature, matchedDataRow, includedColumnsList, invalidColumns); newShapeFileFeatureLayer.EditTools.Add(feature); } else if (isIncludeAllFeatures) { newShapeFileFeatureLayer.EditTools.Add(feature); } if (UpdateProgress(updateAction, index, count)) { break; } } catch (Exception ex) { var errorEventArgs = new UpdatingTaskProgressEventArgs(TaskState.Error); errorEventArgs.Error = new ExceptionInfo(string.Format(CultureInfo.InvariantCulture, "Feature id: {0}, {1}" , feature.Id, ex.Message) , ex.StackTrace , ex.Source); GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); errorEventArgs.Message = feature.Id; updateAction(errorEventArgs); } } newShapeFileFeatureLayer.EditTools.CommitTransaction(); }); SavePrjFile(OutputPath, DisplayProjectionParameters); } }
private void DataJoinShapeFile() { var args = new UpdatingTaskProgressEventArgs(TaskState.Updating); ShapeFileFeatureSource currentSource = ShapeFileFeatureSource; if (!currentSource.IsOpen) { currentSource.Open(); } var index = 0; var count = currentSource.GetAllFeatures(ReturningColumnsType.AllColumns).Count; Collection <DbfColumn> includeColumns = new Collection <DbfColumn>(); RemoveUnduplicateColumn(IncludedColumnsList); foreach (var column in IncludedColumnsList) { DbfColumnType tmpDbfColumnType = DbfColumnType.Character; if (Enum.TryParse(column.TypeName, out tmpDbfColumnType)) { DbfColumn dbfColumn = new DbfColumn(column.ColumnName, tmpDbfColumnType, column.MaxLength, 0); includeColumns.Add(dbfColumn); } } ShapeFileType shapeFileType = GetShapeFileType(currentSource.GetAllFeatures(ReturningColumnsType.AllColumns).FirstOrDefault()); var projectionWkt = Proj4Projection.ConvertProj4ToPrj(DisplayProjectionParameters); var dataTable = DataJoinAdapter.ReadDataToDataGrid(CsvFilePath, Delimiter); var featureRows = dataTable.Rows; var helper = new ShapeFileHelper(shapeFileType, OutputPathFileName, includeColumns, projectionWkt); helper.ForEachFeatures(currentSource, (f, currentProgress, upperBound, percentage) => { try { bool canceled = false; if (f.GetWellKnownBinary() != null) { index++; try { var matchedDataRow = featureRows.Cast <DataRow>().FirstOrDefault(r => MatchConditions.All(tmpCondition => f.ColumnValues[tmpCondition.SelectedLayerColumn.ColumnName] == r[tmpCondition.SelectedDelimitedColumn.ColumnName].ToString())); if (matchedDataRow != null) { SetFeatureColumnValues(f, matchedDataRow, IncludedColumnsList, InvalidColumns); helper.Add(f); } else if (IsIncludeAllFeatures) { helper.Add(f); } if (UpdateProgress(OnUpdatingProgress, index, count)) { canceled = true; } } catch (Exception ex) { var errorEventArgs = new UpdatingTaskProgressEventArgs(TaskState.Error); errorEventArgs.Error = new ExceptionInfo(string.Format(CultureInfo.InvariantCulture, "Feature id: {0}, {1}" , f.Id, ex.Message) , ex.StackTrace , ex.Source); GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); errorEventArgs.Message = f.Id; OnUpdatingProgress(errorEventArgs); } } args = new UpdatingTaskProgressEventArgs(TaskState.Updating, percentage); args.Current = currentProgress; args.UpperBound = upperBound; OnUpdatingProgress(args); canceled = args.TaskState == TaskState.Canceled; return(canceled); } catch { return(false); } }); helper.Commit(); SavePrjFile(OutputPathFileName, DisplayProjectionParameters); }