Added create applicationmap.

fixed to flow.
This commit is contained in:
2020-05-05 16:08:32 +02:00
parent a331437433
commit 38cb1e27a5
3 changed files with 94 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -7,7 +8,7 @@ using FarmmapsApi.Services;
using FarmmapsHaulmkilling.Models;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static FarmmapsApiSamples.Constants;
namespace FarmmapsHaulmkilling
@@ -59,7 +60,7 @@ namespace FarmmapsHaulmkilling
}
var agents = await _haulmkillingService.GetHaulmkillingAgents();
if (agents == null)
if (agents == null || agents.Count == 0)
{
_logger.LogError("No valid agents found for haulmkilling");
return;
@@ -81,7 +82,7 @@ namespace FarmmapsHaulmkilling
}
ItemTaskStatus taskStatus;
if (!string.IsNullOrEmpty(_settings.SatelliteTaskCode))
if (string.IsNullOrEmpty(_settings.SatelliteTaskCode))
{
_logger.LogInformation("Gathering satellite information for cropfield, this might take a while!");
taskStatus = await _generalService.RunAndWaitForTask(cropfieldItem, SATELLITE_TASK, null, 20);
@@ -102,29 +103,48 @@ namespace FarmmapsHaulmkilling
}
// find ndvi or wdvi satellite data geotiffs
var temporalITem = await _generalService.FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE,
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)
if (temporalItem == null)
{
_logger.LogError($"Temporal item not found");
_logger.LogError("Temporal item not found");
return;
}
var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalITem.Code);
var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code);
var firstSatelliteItem = satelliteTiffs.FirstOrDefault();
if (firstSatelliteItem == null)
{
_logger.LogError($"Satellite item not found");
_logger.LogError("Satellite item not found");
return;
}
// create haulmkilling application map
// download application map
// must be ndvi or wdvi
var inputType = (firstSatelliteItem.Data["layers"] as JArray)?[0]["name"].ToString();
if (string.IsNullOrEmpty(inputType))
{
_logger.LogError("Could not get the input type name from the satellite item");
return;
}
var selectedAgent = agents[0];
var selectedOption = selectedAgent.SupportedOptions[0];
_logger.LogInformation("Calculating application map");
var applianceMapItem = await _haulmkillingService.CalculateApplicationMapAsync(cropfieldItem,
firstSatelliteItem, inputType, selectedAgent.Name, selectedOption);
if (applianceMapItem == null)
{
return;
}
_logger.LogInformation("Downloading application map");
await _farmmapsApiService.DownloadItemAsync(applianceMapItem.Code, Path.Combine(DownloadFolder,
$"{applianceMapItem.Name}_{Guid.NewGuid():N}.zip"));
}
private void LoadSettings()