private PolygonFeature GetPolygonFeatureData(PolygonFeatureGeoData featureGeoData, IEnumerable <MapData> records, DateTime date) { var code = featureGeoData.ColumnValue.Trim(); MapData data = records.FirstOrDefault(x => x.ColumnValue == code); PolygonFeature featureData = new PolygonFeature { Area = featureGeoData.Area, SampleId = Guid.NewGuid().ToString("N"), Geometry = featureGeoData.Coordinates.ToArray(), ValidityTime = date, ExtendedData = featureGeoData.ColumnValue, UserConf = 100 }; if (data == null) { _logger.Line($"Failed to map feature data - {code}"); File.AppendAllLines(_missingMapsFileName, new[] { featureGeoData.ColumnValue }); } else { featureData.LandCover = data.LandCover; featureData.CropType1 = data.CropType1; featureData.CropType2 = data.CropType2; featureData.Irrigation1 = data.Irrigation1; featureData.Irrigation2 = data.Irrigation2; featureData.Irrigation3 = data.Irrigation3; } return(featureData); }
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); }