Finding satellite items.

master
Mark van der Wal 2020-04-28 12:37:56 +02:00
parent 276cce1808
commit a331437433
3 changed files with 41 additions and 4 deletions

View File

@ -3,11 +3,16 @@ namespace FarmmapsApiSamples
public static class Constants
{
public const string USERINPUT_ITEMTYPE = "vnd.farmmaps.itemtype.user.input";
public const string TEMPORAL_ITEMTYPE = "vnd.farmmaps.itemtype.temporal";
public const string GEOTIFF_ITEMTYPE = "vnd.farmmaps.itemtype.geotiff";
public const string GEOTIFF_PROCESSED_ITEMTYPE = "vnd.farmmaps.itemtype.geotiff.processed";
public const string CROPFIELD_ITEMTYPE = "vnd.farmmaps.itemtype.cropfield";
public const string SHAPE_PROCESSED_ITEMTYPE = "vnd.farmmaps.itemtype.shape.processed";
public const string SHAPE_ITEMTYPE = "vnd.farmmaps.itemtype.shape";
public const string VRANBS_TASK = "vnd.farmmaps.task.vranbs";
public const string VRAHERBICIDE_TASK = "vnd.farmmaps.task.vraherbicide";
public const string VRAHAULMKILLING_TASK = "vnd.farmmaps.task.vrahaulmkilling";
public const string SATELLITE_TASK = "vnd.farmmaps.task.satellite";
}
}

View File

@ -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

View File

@ -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; }
}
}