private void CreateMetaDataReadTask(string shpFilePath, long endIndex, ConcurrentDictionary <string, FeatureMetaData> concurrentDictionary, long startIndex) { _logger.Line( $"{Environment.CurrentManagedThreadId} - S-{startIndex} E-{endIndex} Total-{endIndex - startIndex}"); using var gdalWrapper = new GdalWrapper(); gdalWrapper.Configure(); gdalWrapper.InitializeDatasetForRead(shpFilePath, _config.InputDriverName); IEnumerable <LayerWrapper> layers = gdalWrapper.GetLayers(); LayerWrapper layerWrapper = layers.First(); for (; startIndex < endIndex; startIndex++) { var featureWrapper = layerWrapper.GetFeature(startIndex); if (featureWrapper == null) { continue; } var area = featureWrapper.GetArea(); var columnValue = featureWrapper.GetFieldAsString(_config.ColNameToRead); var extData = ""; foreach (var colName in _config.ColsToReadAsExtendedData) { extData += featureWrapper.GetFieldAsString(colName) + ";"; } concurrentDictionary.AddOrUpdate(columnValue, new FeatureMetaData { Area = area, Count = 1, ColumnValue = columnValue, ExtendedData = extData }, (key, value) => { value.Count++; value.Area += area; return(value); }); if ((endIndex - startIndex) % 1000 == 0) { var sum = concurrentDictionary.Values.Sum(x => x.Count); _logger.Line( $"{Environment.CurrentManagedThreadId} S-{startIndex} E-{endIndex} Remaining-{endIndex - startIndex}, TotalRead-{sum}"); if (sum > _config.MaxFeatureToReadFromShp) { break; } } } }
private long GetFeatureCount(string shpFilePath) { long featureCount = 0; using (var gdalWrapper = new GdalWrapper()) { gdalWrapper.Configure(); gdalWrapper.InitializeDatasetForRead(shpFilePath, _config.InputDriverName); IEnumerable <LayerWrapper> layers = gdalWrapper.GetLayers(); LayerWrapper layerWrapper = layers.First(); var layerData = layerWrapper.GetData(); _logger.Line($"Layer Feature count - {featureCount}"); _logger.Line($"Layer Projection - {layerData.ProjectionName}"); featureCount = layerData.FeatureCount; layerWrapper.Dispose(); } return(featureCount); }
private Task CreateFeatureReadTask(string shpPath, DateTime dateTime, BlockingCollection <BaseFeature> featureList, long endIndex, MapData[] mapDataList, long startIndex) { var task = Task.Factory.StartNew(() => { _logger.Line( $"{Environment.CurrentManagedThreadId} -Read Start S-{startIndex} E-{endIndex} Total-{endIndex - startIndex}"); using (var gdalWrapper = new GdalWrapper()) { gdalWrapper.Configure(); gdalWrapper.InitializeDatasetForRead(shpPath, _config.InputDriverName); IEnumerable <LayerWrapper> layers = gdalWrapper.GetLayers(); LayerWrapper layerWrapper = layers.First(); for (; startIndex < endIndex; startIndex++) { var featureWrapper = layerWrapper.GetFeature(startIndex); if (featureWrapper == null) { continue; } PolygonFeatureGeoData featureData = featureWrapper.GetFieldGeo(); featureData.ColumnValue = featureWrapper.GetFieldAsString(_config.ColNameToRead); featureList.Add(GetPolygonFeatureData(featureData, mapDataList, dateTime)); if ((endIndex - startIndex) % 1000 == 0) { _logger.Line( $"{Environment.CurrentManagedThreadId} S-{startIndex} E-{endIndex} Remaining-{endIndex - startIndex}"); } } } } ); return(task); }