From ecfc76105fbf49584372d803228fc53888ec7f3f Mon Sep 17 00:00:00 2001 From: Sijbrandij Date: Wed, 7 Oct 2020 22:06:56 +0200 Subject: [PATCH] added option to process tiff data to NBS and Planting applicaions --- FarmmapsNbs/NbsApplication.cs | 60 +++++++++++++++++++------------ FarmmapsNbs/NitrogenService.cs | 4 +-- FarmmapsPoten/PotenApplication.cs | 13 +++++++ 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/FarmmapsNbs/NbsApplication.cs b/FarmmapsNbs/NbsApplication.cs index 51bfc21..28e8d65 100644 --- a/FarmmapsNbs/NbsApplication.cs +++ b/FarmmapsNbs/NbsApplication.cs @@ -79,31 +79,44 @@ namespace FarmmapsNbs var cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code, $"VRA NBS cropfield {input.OutputFileName}", plantingDate.Year, input.GeometryJson.ToString(Formatting.None)); - var isGeoJson = input.File.Contains("json"); - var dataPath = Path.Combine("Data", input.File); - var shapeItem = isGeoJson ? - await _generalService.UploadDataAsync(uploadedRoot, SHAPE_PROCESSED_ITEMTYPE, dataPath, Path.GetFileNameWithoutExtension(input.File)): - await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.File)); + var geotiffItem = (Item)null; + + 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, + Path.GetFileNameWithoutExtension(input.File)); + + if (geotiffItem == null) { + _logger.LogError("Could not find item for uploaded data"); + return; + } + } - if (shapeItem == null) - { - _logger.LogError("Could not find item for uploaded data"); - return; + else { + var isGeoJson = input.File.Contains("json"); + var dataPath = Path.Combine("Data", input.File); + var shapeItem = isGeoJson ? + await _generalService.UploadDataAsync(uploadedRoot, SHAPE_PROCESSED_ITEMTYPE, dataPath, Path.GetFileNameWithoutExtension(input.File)) : + await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.File)); + + if (shapeItem == null) { + _logger.LogError("Could not find item for uploaded data"); + return; + } + + _logger.LogInformation($"Converting shape to geotiff"); + geotiffItem = await _generalService.ShapeToGeotiff(shapeItem); + if (geotiffItem == null) { + _logger.LogError("Something went wrong with shape to geotiff transformation"); + return; + } + + _logger.LogInformation("Downloading geotiff file"); + await _farmmapsApiService.DownloadItemAsync(geotiffItem.Code, + Path.Combine(DownloadFolder, $"{input.OutputFileName}.input_geotiff.zip")); } - _logger.LogInformation($"Converting shape to geotiff"); - var geotiffItem = await _generalService.ShapeToGeotiff(shapeItem); - if (geotiffItem == null) - { - _logger.LogError("Something went wrong with shape to geotiff transformation"); - return; - } - - _logger.LogInformation("Downloading geotiff file"); - await _farmmapsApiService.DownloadItemAsync(geotiffItem.Code, - Path.Combine(DownloadFolder, $"{input.OutputFileName}.input_geotiff.zip")); - - _logger.LogInformation($"Calculating targetN with targetYield: {input.TargetYield}"); var targetNItem = await _nitrogenService.CreateTargetNItem(cropfieldItem); var targetNData = await _nitrogenService.CalculateTargetN(cropfieldItem, targetNItem, plantingDate, @@ -116,6 +129,9 @@ namespace FarmmapsNbs } _logger.LogInformation($"TargetN: {targetNData.TargetN}"); + ////Option to manually adjust the Target N, for test purposes only! + //targetNData.TargetN = 225; + //_logger.LogInformation($"TargetN adjusted: {targetNData.TargetN}"); var targetNDataPath = Path.Combine(DownloadFolder, $"{input.OutputFileName}.targetn.json"); await File.WriteAllTextAsync(targetNDataPath, JsonConvert.SerializeObject(targetNData, Formatting.Indented)); diff --git a/FarmmapsNbs/NitrogenService.cs b/FarmmapsNbs/NitrogenService.cs index 012325c..f4e392c 100644 --- a/FarmmapsNbs/NitrogenService.cs +++ b/FarmmapsNbs/NitrogenService.cs @@ -94,8 +94,8 @@ namespace FarmmapsNbs nbsUptakeMapRequest.attributes["inputType"] = inputType.ToLower(); nbsUptakeMapRequest.attributes["inputLayerName"] = "IRMI"; //toevoeging FS. Kolom IRMI hernoemd als IMI. Deze wordt niet automatisch herkend. En moet dus gespecificeerd worden. - var layers = inputItem.Data["layers"]; //toevoeging FS, check welke data lagen worden omgezet - _logger.LogInformation($"DataLayers: {layers}"); //toevoeging FS check welke data lagen worden omgezet + //var layers = inputItem.Data["layers"]; //toevoeging FS, check welke data lagen worden omgezet + //_logger.LogInformation($"DataLayers: {layers}"); //toevoeging FS check welke data lagen worden omgezet string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsUptakeMapRequest); diff --git a/FarmmapsPoten/PotenApplication.cs b/FarmmapsPoten/PotenApplication.cs index ea24416..0e961ed 100644 --- a/FarmmapsPoten/PotenApplication.cs +++ b/FarmmapsPoten/PotenApplication.cs @@ -128,6 +128,19 @@ namespace FarmmapsVRApoten Path.Combine(DownloadFolder, $"{input.OutputFileName}.BOFEK.zip")); } + + 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, + Path.GetFileNameWithoutExtension(input.File)); + + if (geotiffItem == null) { + _logger.LogError("Could not find item for uploaded data"); + return; + } + } + else { var isGeoJson = input.File.Contains("json");