Added option to use satellite data in NBS

This commit is contained in:
Riepma
2020-10-14 14:34:42 +02:00
parent 92a8e0d68f
commit 5b4888517e
6 changed files with 337 additions and 152 deletions

View File

@@ -269,44 +269,68 @@ namespace FarmmapsApi.Services
return shadowItem;
}
public async Task<Item> RunSatelliteTask(Item cropfieldItem)
{
var taskmapRequest = new TaskRequest { TaskType = SATELLITE_TASK };
public async Task<string> RunSatelliteTask(Item cropfieldItem)
{
_logger.LogInformation("Gathering satellite information for cropfield, this might take a while!");
var taskmapRequest = new TaskRequest { TaskType = SATELLITE_TASK };
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest);
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
{
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
_logger.LogInformation($"Waiting on collection satellite data; status: {itemTaskStatus.State}");
_logger.LogInformation($"Waiting on satellite data; status: {itemTaskStatus.State}");
if (itemTaskStatus.IsFinished)
tokenSource.Cancel();
});
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
if (itemTask.State == ItemTaskState.Error)
{
_logger.LogError($"Something went wrong with task execution: {itemTask.Message}");
return null;
_logger.LogError($"Something went wrong when trying to process satellite data; {itemTask.Message}");
}
//the satellite item is a child of the cropfield
var itemName = "satellite";
var satelliteItem = await FindChildItemAsync(cropfieldItem.Code,
TEMPORAL_ITEMTYPE, itemName);
if (satelliteItem == null)
return itemTask.Code;
}
public async Task<Item> FindSatelliteItems(Item cropfieldItem, string satelliteTaskCode)
{
var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode);
// find ndvi or wdvi satellite data geotiffs
var temporalItem = await FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE,
"Cropfield Satellite items", item => item.SourceTask == SATELLITE_TASK &&
taskStatus.Finished >= item.Created &&
taskStatus.Finished <= item.Created.Value.AddHours(1));
if (temporalItem == null)
{
_logger.LogError("Could not find the satellite data as a child item under the cropfield");
return null;
_logger.LogError("Temporal item not found");
}
var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code);
var firstSatelliteItem = satelliteTiffs.FirstOrDefault();
// geotiffs can be found as a item of children under the satellite item
var allSatelliteItems = await _farmmapsApiService.GetItemChildrenAsync(satelliteItem.Code);
if (firstSatelliteItem == null)
{
_logger.LogError("Satellite item not found");
}
var lastSatItem = allSatelliteItems[^1];
return firstSatelliteItem;
return lastSatItem;
}