forked from FarmMaps/FarmMapsApiClient
added vandersat data to sample code
This commit is contained in:
@@ -14,9 +14,7 @@ using static FarmmapsApiSamples.Constants;
|
||||
|
||||
namespace FarmmapsVRApoten
|
||||
{
|
||||
public class PotenApplication : IApplication
|
||||
|
||||
{
|
||||
public class PotenApplication : IApplication {
|
||||
private const string DownloadFolder = "Downloads";
|
||||
|
||||
private readonly ILogger<PotenApplication> _logger;
|
||||
@@ -26,16 +24,14 @@ namespace FarmmapsVRApoten
|
||||
|
||||
|
||||
public PotenApplication(ILogger<PotenApplication> logger, FarmmapsApiService farmmapsApiService,
|
||||
GeneralService generalService, PotenService potenService)
|
||||
{
|
||||
GeneralService generalService, PotenService potenService) {
|
||||
_logger = logger;
|
||||
_farmmapsApiService = farmmapsApiService;
|
||||
_generalService = generalService;
|
||||
_potenService = potenService;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
public async Task RunAsync() {
|
||||
// read field data from separate json file
|
||||
var VRAPotenInputJson = File.ReadAllText("PotenInput.json");
|
||||
List<PotenInput> potenInputs = JsonConvert.DeserializeObject<List<PotenInput>>(VRAPotenInputJson);
|
||||
@@ -48,36 +44,29 @@ namespace FarmmapsVRApoten
|
||||
await _farmmapsApiService.GetCurrentUserCodeAsync();
|
||||
var roots = await _farmmapsApiService.GetCurrentUserRootsAsync();
|
||||
|
||||
foreach (var input in potenInputs)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var input in potenInputs) {
|
||||
try {
|
||||
await Process(roots, input);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Process(List<UserRoot> roots, PotenInput input)
|
||||
{
|
||||
private async Task Process(List<UserRoot> roots, PotenInput input) {
|
||||
var meanDensity = input.MeanDensity;
|
||||
var variation = input.Variation;
|
||||
var fieldName = input.FieldName;
|
||||
bool useShadow = input.UseShadow;
|
||||
|
||||
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
|
||||
if (myDrive == null)
|
||||
{
|
||||
if (myDrive == null) {
|
||||
_logger.LogError("Could not find a needed root item");
|
||||
return;
|
||||
}
|
||||
|
||||
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
|
||||
if (uploadedRoot == null)
|
||||
{
|
||||
if (uploadedRoot == null) {
|
||||
_logger.LogError("Could not find a needed root item");
|
||||
return;
|
||||
}
|
||||
@@ -89,12 +78,10 @@ namespace FarmmapsVRApoten
|
||||
input.GeometryJson.ToString(Formatting.None));
|
||||
|
||||
//Calculating shadow map
|
||||
if (useShadow)
|
||||
{
|
||||
if (useShadow) {
|
||||
_logger.LogInformation("Calculate shadow map for field");
|
||||
var shadowItem = await _generalService.RunShadowTask(cropfieldItem);
|
||||
if (shadowItem == null)
|
||||
{
|
||||
if (shadowItem == null) {
|
||||
_logger.LogError("Something went wrong while obtaining the shadow map");
|
||||
return;
|
||||
}
|
||||
@@ -104,21 +91,30 @@ namespace FarmmapsVRApoten
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.shadow.zip"));
|
||||
}
|
||||
|
||||
//Calculating AHN map
|
||||
_logger.LogInformation("retreiving AHN map for field");
|
||||
var AHNItem = await _generalService.RunAhnTask(cropfieldItem);
|
||||
if (AHNItem == null) {
|
||||
_logger.LogError("Something went wrong while obtaining the AHN map");
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Downloading AHN map");
|
||||
await _farmmapsApiService.DownloadItemAsync(AHNItem.Code,
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}_AHN.zip"));
|
||||
|
||||
|
||||
_logger.LogInformation("Looking for local data to use");
|
||||
var localDataAvailable = input.File;
|
||||
var geotiffItem = (Item) null;
|
||||
var geotiffItem = (Item)null;
|
||||
|
||||
|
||||
if (String.IsNullOrEmpty(localDataAvailable))
|
||||
{
|
||||
if (String.IsNullOrEmpty(localDataAvailable)) {
|
||||
_logger.LogInformation("Could not find item for uploaded data, using BOFEK");
|
||||
|
||||
//Retreiving BOFEK
|
||||
_logger.LogInformation("Get BOFEK for field");
|
||||
var bofekItem = await _generalService.RunBofekTask(cropfieldItem);
|
||||
if (bofekItem == null)
|
||||
{
|
||||
if (bofekItem == null) {
|
||||
_logger.LogError("Something went wrong while obtaining the BOFEK data");
|
||||
return;
|
||||
}
|
||||
@@ -126,10 +122,7 @@ namespace FarmmapsVRApoten
|
||||
_logger.LogInformation("Downloading Bofek map");
|
||||
await _farmmapsApiService.DownloadItemAsync(bofekItem.Code,
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.BOFEK.zip"));
|
||||
}
|
||||
|
||||
|
||||
else if (input.File.Contains(".tif") || input.File.Contains(".geotiff")) {
|
||||
} else if (input.File.Contains(".tif") || input.File.Contains(".geotiff")) {
|
||||
_logger.LogInformation("input = tiff data");
|
||||
var dataPath = Path.Combine("Data", input.File);
|
||||
geotiffItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE, dataPath,
|
||||
@@ -139,10 +132,7 @@ namespace FarmmapsVRApoten
|
||||
_logger.LogError("Could not find item for uploaded data");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
var isGeoJson = input.File.Contains("json");
|
||||
var dataPath = Path.Combine("Data", input.File);
|
||||
var shapeItem = isGeoJson
|
||||
@@ -151,8 +141,7 @@ namespace FarmmapsVRApoten
|
||||
: await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath,
|
||||
Path.GetFileNameWithoutExtension(input.File));
|
||||
|
||||
if (shapeItem == null)
|
||||
{
|
||||
if (shapeItem == null) {
|
||||
_logger.LogError("Something went wrong while searching for the shape file");
|
||||
return;
|
||||
}
|
||||
@@ -161,8 +150,7 @@ namespace FarmmapsVRApoten
|
||||
_logger.LogInformation($"Converting shape to geotiff");
|
||||
|
||||
geotiffItem = await _generalService.ShapeToGeotiff(shapeItem);
|
||||
if (geotiffItem == null)
|
||||
{
|
||||
if (geotiffItem == null) {
|
||||
_logger.LogError("Something went wrong with shape to geotiff transformation");
|
||||
return;
|
||||
}
|
||||
@@ -179,8 +167,7 @@ namespace FarmmapsVRApoten
|
||||
var applianceMapItem =
|
||||
await _potenService.CalculateApplicationMapAsync(cropfieldItem, geotiffItem, meanDensity, variation);
|
||||
|
||||
if (applianceMapItem == null)
|
||||
{
|
||||
if (applianceMapItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -195,8 +182,7 @@ namespace FarmmapsVRApoten
|
||||
|
||||
_logger.LogInformation($"Converting geotiff to shape");
|
||||
var taskmap = await _generalService.GeotiffToShape(applianceMapItem);
|
||||
if (taskmap == null)
|
||||
{
|
||||
if (taskmap == null) {
|
||||
_logger.LogError("Something went wrong with geotiff to shape transformation");
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user