added option to process tiff data to NBS and Planting applicaions

This commit is contained in:
Sijbrandij 2020-10-07 22:06:56 +02:00
parent b56b38c308
commit ecfc76105f
3 changed files with 53 additions and 24 deletions

View File

@ -79,22 +79,35 @@ namespace FarmmapsNbs
var cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code,
$"VRA NBS cropfield {input.OutputFileName}", plantingDate.Year, input.GeometryJson.ToString(Formatting.None));
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;
}
}
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)
{
if (shapeItem == null) {
_logger.LogError("Could not find item for uploaded data");
return;
}
_logger.LogInformation($"Converting shape to geotiff");
var geotiffItem = await _generalService.ShapeToGeotiff(shapeItem);
if (geotiffItem == null)
{
geotiffItem = await _generalService.ShapeToGeotiff(shapeItem);
if (geotiffItem == null) {
_logger.LogError("Something went wrong with shape to geotiff transformation");
return;
}
@ -102,7 +115,7 @@ namespace FarmmapsNbs
_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);
@ -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));

View File

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

View File

@ -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");