forked from FarmMaps/FarmMapsApiClient
		
	small update on DataDownload and GenerelServices
This commit is contained in:
		@@ -348,7 +348,7 @@ namespace FarmmapsApi.Services
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode) {
 | 
			
		||||
        public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode, string FieldName = null, int selectedLayer = 0, bool allItemsStatistics = false, string DownloadFolder = null) {
 | 
			
		||||
 | 
			
		||||
            var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode);
 | 
			
		||||
 | 
			
		||||
@@ -366,30 +366,81 @@ namespace FarmmapsApi.Services
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code);
 | 
			
		||||
            
 | 
			
		||||
            if (allItemsStatistics == false) {
 | 
			
		||||
                _logger.LogInformation("Available satellite images:");
 | 
			
		||||
                var count = 0;
 | 
			
		||||
                TimeSpan.FromSeconds(0.5);
 | 
			
		||||
                foreach (var item in satelliteTiffs) {
 | 
			
		||||
 | 
			
		||||
            _logger.LogInformation("Available satellite images:");
 | 
			
		||||
            var count = 0;
 | 
			
		||||
            TimeSpan.FromSeconds(0.5);
 | 
			
		||||
            foreach (var item in satelliteTiffs) {
 | 
			
		||||
                    Console.WriteLine($"Satellite image #{count}: {item.DataDate}");
 | 
			
		||||
                    count++;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Console.WriteLine($"Satellite image #{count}: {item.DataDate}");
 | 
			
		||||
                count++;
 | 
			
		||||
                _logger.LogInformation("Enter satellite image number for NBS application");
 | 
			
		||||
                int element = Int32.Parse(Console.ReadLine());
 | 
			
		||||
                var selectedSatelliteItem = satelliteTiffs[element];
 | 
			
		||||
 | 
			
		||||
                if (selectedSatelliteItem == null) {
 | 
			
		||||
                    _logger.LogError("Satellite item not found");
 | 
			
		||||
                
 | 
			
		||||
                    return selectedSatelliteItem;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            _logger.LogInformation("Enter satellite image number for NBS application");
 | 
			
		||||
            int element = Int32.Parse(Console.ReadLine());
 | 
			
		||||
            var selectedSatelliteItem = satelliteTiffs[element];
 | 
			
		||||
            if (allItemsStatistics == true ) {
 | 
			
		||||
                var count = 0;
 | 
			
		||||
                foreach (var item in satelliteTiffs) {                    
 | 
			
		||||
                        var satellitetBand = item.Data["layers"][selectedLayer]["name"];
 | 
			
		||||
                        var SatelliteImageYear = (DateTime)item.DataDate;
 | 
			
		||||
                        var SatelliteYear = SatelliteImageYear.ToString("yyyy");
 | 
			
		||||
                        var SatelliteFile = $"{DownloadFolder}/SatelliteDataStatistics_{SatelliteYear}_{FieldName}_{satellitetBand}.csv"; 
 | 
			
		||||
                        var NewLineField = $"Field,Date,Mean,Min,Max,Standard deviation, ConfidenceInterval low, ConfidenceInterval high" + Environment.NewLine;
 | 
			
		||||
                        if (count == 0) {
 | 
			
		||||
                            File.AppendAllText(SatelliteFile, NewLineField);
 | 
			
		||||
                            var numbervandersat = satelliteTiffs.Count;
 | 
			
		||||
                            Console.WriteLine($"{numbervandersat} Satellite images found");
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
            if (selectedSatelliteItem == null) {
 | 
			
		||||
                        var SatelliteStatistics = item.Data["layers"][0]["renderer"]["band"]["statistics"];
 | 
			
		||||
                        var SatelliteImageDate = (DateTime)item.DataDate;
 | 
			
		||||
                        var satelliteDate = SatelliteImageDate.ToString("yyyy-MM-dd");
 | 
			
		||||
                        var NewLineDate = $"\"date\":{satelliteDate}" + Environment.NewLine;
 | 
			
		||||
                        if (SatelliteStatistics == null) {
 | 
			
		||||
                            Console.WriteLine($"{satelliteDate} no statistics found");
 | 
			
		||||
                            //Console.WriteLine($"Available data: {item.Data}");
 | 
			
		||||
                        } else {
 | 
			
		||||
                            File.AppendAllText(SatelliteFile, $"{FieldName},{satelliteDate},{SatelliteStatistics["mean"]},{SatelliteStatistics["min"]},{SatelliteStatistics["max"]},{SatelliteStatistics["stddev"]},{SatelliteStatistics["confidenceIntervalLow"]},{SatelliteStatistics["confidenceIntervalHigh"]}" + Environment.NewLine);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                    if (true) {
 | 
			
		||||
                        // download the geotiff of needed inputtype
 | 
			
		||||
                        var selectedSatelliteItemDate = (DateTime)item.DataDate;
 | 
			
		||||
                        var SatelliteDate = selectedSatelliteItemDate.ToString("yyyyMMdd");
 | 
			
		||||
                        _logger.LogInformation("Downloading geotiff file");
 | 
			
		||||
                        await _farmmapsApiService.DownloadItemAsync(item.Code,
 | 
			
		||||
                            Path.Combine(DownloadFolder, $"satelliteGeotiff_{FieldName}_{satellitetBand}_{SatelliteDate}.zip"));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    count++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var selectedSatelliteItemTemp = satelliteTiffs[0];
 | 
			
		||||
 | 
			
		||||
            if (selectedSatelliteItemTemp == null) {
 | 
			
		||||
                _logger.LogError("Satellite item not found");
 | 
			
		||||
 | 
			
		||||
                return selectedSatelliteItemTemp;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return selectedSatelliteItem;
 | 
			
		||||
        }
 | 
			
		||||
            return selectedSatelliteItemTemp;
 | 
			
		||||
 | 
			
		||||
        //VanDerSat
 | 
			
		||||
        public async Task<string> RunVanDerSatTask(Item cropfieldItem) {
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
            //VanDerSat
 | 
			
		||||
            public async Task<string> RunVanDerSatTask(Item cropfieldItem) {
 | 
			
		||||
 | 
			
		||||
            _logger.LogInformation("Gathering VanDerSat information for cropfield, this might take a while!");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user