forked from FarmMaps/FarmMapsApiClient
added vrapoten and changed some nbs stuff
This commit is contained in:
10
FarmmapsNbs/FarmmapsNbs.csproj.user
Normal file
10
FarmmapsNbs/FarmmapsNbs.csproj.user
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
<ActiveDebugProfile>FarmmapsNbs</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@@ -34,6 +34,7 @@ namespace FarmmapsNbs
|
||||
public async Task RunAsync()
|
||||
{
|
||||
var nitrogenInputJson = File.ReadAllText("NitrogenInput.json");
|
||||
//var nitrogenInputJson = File.ReadAllText("fivefieldsinput.json");
|
||||
List<NitrogenInput> nitrogenInputs = JsonConvert.DeserializeObject<List<NitrogenInput>>(nitrogenInputJson);
|
||||
|
||||
if (!Directory.Exists(DownloadFolder))
|
||||
@@ -75,6 +76,7 @@ namespace FarmmapsNbs
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code,
|
||||
$"VRA NBS cropfield {input.OutputFileName}", plantingDate.Year, input.GeometryJson.ToString(Formatting.None));
|
||||
|
||||
@@ -98,6 +100,11 @@ namespace FarmmapsNbs
|
||||
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,
|
||||
@@ -127,6 +134,7 @@ namespace FarmmapsNbs
|
||||
_logger.LogInformation("Downloading uptake map");
|
||||
await _farmmapsApiService.DownloadItemAsync(uptakeMapItem.Code,
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.uptake.zip"));
|
||||
_logger.LogInformation("UptakeMap downloaded to {0}", Path.Combine(DownloadFolder, $"{input.OutputFileName}.uptake.zip"));
|
||||
|
||||
_logger.LogInformation("Calculating application map");
|
||||
var applicationMapItem =
|
||||
@@ -142,6 +150,29 @@ namespace FarmmapsNbs
|
||||
_logger.LogInformation("Downloading application map");
|
||||
await _farmmapsApiService.DownloadItemAsync(applicationMapItem.Code,
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.application.zip"));
|
||||
_logger.LogInformation("Application map can be found in {0}", Path.Combine(DownloadFolder, $"{input.OutputFileName}.application.zip"));
|
||||
|
||||
//transforming tiff to shape
|
||||
var tiffItem = applicationMapItem;
|
||||
|
||||
if (tiffItem == null)
|
||||
{
|
||||
_logger.LogError("Could not find item for uploaded data");
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation($"Converting geotiff to shape");
|
||||
var taskmap = await _generalService.GeotiffToShape(tiffItem);
|
||||
if (taskmap == null)
|
||||
{
|
||||
_logger.LogError("Something went wrong with geotiff to shape transformation");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Downloading taskmap");
|
||||
await _farmmapsApiService.DownloadItemAsync(taskmap.Code,
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.taskmap.zip"));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -51,8 +51,8 @@ namespace FarmmapsNbs
|
||||
var nbsTargetNRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
||||
nbsTargetNRequest.attributes["operation"] = "targetn";
|
||||
nbsTargetNRequest.attributes["inputCode"] = targetNItem.Code;
|
||||
nbsTargetNRequest.attributes["plantingDate"] = plantingDate.ToString();
|
||||
nbsTargetNRequest.attributes["measurementDate"] = measurementDate.ToString();
|
||||
nbsTargetNRequest.attributes["plantingDate"] = plantingDate.ToString("o");
|
||||
nbsTargetNRequest.attributes["measurementDate"] = measurementDate.ToString("o");
|
||||
nbsTargetNRequest.attributes["purposeType"] = purposeType.ToLower();
|
||||
nbsTargetNRequest.attributes["targetYield"] = targetYield.ToString();
|
||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsTargetNRequest);
|
||||
@@ -89,9 +89,14 @@ namespace FarmmapsNbs
|
||||
var nbsUptakeMapRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
||||
nbsUptakeMapRequest.attributes["operation"] = "uptake";
|
||||
nbsUptakeMapRequest.attributes["inputCode"] = inputItem.Code;
|
||||
nbsUptakeMapRequest.attributes["plantingDate"] = plantingDate.ToString();
|
||||
nbsUptakeMapRequest.attributes["measurementDate"] = measurementDate.ToString();
|
||||
nbsUptakeMapRequest.attributes["plantingDate"] = plantingDate.ToString("o");
|
||||
nbsUptakeMapRequest.attributes["measurementDate"] = measurementDate.ToString("o");
|
||||
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
|
||||
|
||||
|
||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsUptakeMapRequest);
|
||||
|
||||
@@ -140,21 +145,24 @@ namespace FarmmapsNbs
|
||||
var nbsApplicationMapRequest = new TaskRequest {TaskType = VRANBS_TASK};
|
||||
nbsApplicationMapRequest.attributes["operation"] = "application";
|
||||
nbsApplicationMapRequest.attributes["inputCode"] = inputItem.Code;
|
||||
nbsApplicationMapRequest.attributes["plantingDate"] = plantingDate.ToString();
|
||||
nbsApplicationMapRequest.attributes["measurementDate"] = measurementDate.ToString();
|
||||
nbsApplicationMapRequest.attributes["plantingDate"] = plantingDate.ToString("o");
|
||||
nbsApplicationMapRequest.attributes["measurementDate"] = measurementDate.ToString("o");
|
||||
nbsApplicationMapRequest.attributes["inputCode"] = inputItem.Code;
|
||||
nbsApplicationMapRequest.attributes["inputType"] = inputType.ToLower();
|
||||
nbsApplicationMapRequest.attributes["targetN"] = targetN.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
|
||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, nbsApplicationMapRequest);
|
||||
|
||||
|
||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
||||
{
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
|
||||
|
||||
if (itemTaskStatus.IsFinished)
|
||||
tokenSource.Cancel();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
|
||||
if(itemTask.State == ItemTaskState.Error)
|
||||
{
|
||||
|
Reference in New Issue
Block a user