Finding satellite items.
This commit is contained in:
		| @@ -8,6 +8,8 @@ using FarmmapsHaulmkilling.Models; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using Newtonsoft.Json; | ||||
|  | ||||
| using static FarmmapsApiSamples.Constants; | ||||
|  | ||||
| namespace FarmmapsHaulmkilling | ||||
| { | ||||
|     public class HaulmkillingApplication : IApplication | ||||
| @@ -78,17 +80,47 @@ namespace FarmmapsHaulmkilling | ||||
|                 cropfieldItem = await _farmmapsApiService.GetItemAsync(_settings.CropfieldItemCode); | ||||
|             } | ||||
|  | ||||
|             if (!_settings.ProcessedSatellite) | ||||
|             ItemTaskStatus taskStatus; | ||||
|             if (!string.IsNullOrEmpty(_settings.SatelliteTaskCode)) | ||||
|             { | ||||
|                 _logger.LogInformation("Gathering satellite information for cropfield, this might take a while!"); | ||||
|                 var taskStatus = await _generalService.RunAndWaitForTask(cropfieldItem, "vnd.farmmaps.task.satellite", null, 20); | ||||
|                 taskStatus = await _generalService.RunAndWaitForTask(cropfieldItem, SATELLITE_TASK, null, 20); | ||||
|  | ||||
|                 _settings.ProcessedSatellite = taskStatus.State == ItemTaskState.Ok; | ||||
|                 if (taskStatus.State == ItemTaskState.Error) | ||||
|                 { | ||||
|                     _logger.LogError($"Something went wrong when trying to process satellite data; {taskStatus.Message}"); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _settings.SatelliteTaskCode = taskStatus.Code; | ||||
|                 SaveSettings(); | ||||
|  | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 taskStatus = await _farmmapsApiService.GetTaskStatusAsync(_settings.CropfieldItemCode, _settings.SatelliteTaskCode); | ||||
|             } | ||||
|  | ||||
|             // find ndvi or wdvi satellite data geotiffs | ||||
|             var temporalITem = await _generalService.FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE, | ||||
|                 "Cropfield VRA Haulmkilling, Satellite", item => item.SourceTask == SATELLITE_TASK &&  | ||||
|                                                                  taskStatus.Finished >= item.Created &&  | ||||
|                                                                  taskStatus.Finished <= item.Created.Value.AddHours(1)); | ||||
|              | ||||
|             if (temporalITem == null) | ||||
|             { | ||||
|                 _logger.LogError($"Temporal item not found"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalITem.Code); | ||||
|             var firstSatelliteItem = satelliteTiffs.FirstOrDefault(); | ||||
|  | ||||
|             if (firstSatelliteItem == null) | ||||
|             { | ||||
|                 _logger.LogError($"Satellite item not found"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             // create haulmkilling application map | ||||
|  | ||||
|   | ||||
| @@ -3,6 +3,6 @@ namespace FarmmapsHaulmkilling.Models | ||||
|     public class Settings | ||||
|     { | ||||
|         public string CropfieldItemCode { get; set; } | ||||
|         public bool ProcessedSatellite { get; set; } | ||||
|         public string SatelliteTaskCode { get; set; } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user