forked from FarmMaps/FarmMapsApiClient
Created separate project for areaConversion VRA poten
Updated VRA poten sample code
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
<None Update="Data\**\*">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="PotenInput.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -5,6 +5,7 @@ namespace FarmmapsPoten.Models
|
||||
{
|
||||
public class PotenInput
|
||||
{
|
||||
|
||||
public string File { get; set; }
|
||||
public string OutputFileName { get; set; }
|
||||
public string FieldName { get; set; }
|
||||
@@ -12,8 +13,6 @@ namespace FarmmapsPoten.Models
|
||||
public string MeanDensity { get; set; }
|
||||
public string Variation { get; set; }
|
||||
public bool UseShadow { get; set; }
|
||||
public bool ConvertToCountPerArea { get; set; }
|
||||
public float Rijbreedte_m { get; set; }
|
||||
public JObject GeometryJson { get; set; }
|
||||
|
||||
public bool GenerateTaskmap { get; set; }
|
||||
|
@@ -58,8 +58,6 @@ namespace FarmmapsVRApoten
|
||||
var variation = input.Variation;
|
||||
var fieldName = input.FieldName;
|
||||
bool useShadow = input.UseShadow;
|
||||
bool convertToCountPerArea = input.ConvertToCountPerArea;
|
||||
float rijBreedte_m = input.Rijbreedte_m;
|
||||
|
||||
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
|
||||
if (myDrive == null) {
|
||||
@@ -93,18 +91,6 @@ 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;
|
||||
@@ -185,23 +171,14 @@ namespace FarmmapsVRApoten
|
||||
? "Download application map completed."
|
||||
: "Something went wrong while downloading.");
|
||||
|
||||
|
||||
// if convertToCountPerArea == True, than recalculate pootafstand in cm to # of poters/m2 from the geotiffItem with the use of the zoneringsTask
|
||||
if (convertToCountPerArea)
|
||||
{
|
||||
applianceMapItem =
|
||||
await _potenService.ConvertToCountPerAreaTroughZonering(cropfieldItem, applianceMapItem, input.Rijbreedte_m);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//GEOTIFF TO Taskmap
|
||||
_logger.LogInformation($"Converting geotiff to taskmap");
|
||||
var taskmap = await _generalService.CreateTaskmap(applianceMapItem, input.CellWidth, input.CellHeight, input.StartPoint.ToString(Formatting.None),
|
||||
var taskmap = await _generalService.CreateTaskmap(cropfieldItem, applianceMapItem, input.CellWidth, input.CellHeight, input.StartPoint.ToString(Formatting.None),
|
||||
input.EndPoint.ToString(Formatting.None), input.Angle);
|
||||
if (taskmap == null)
|
||||
{
|
||||
_logger.LogError("Something went wrong with geotiff to shape transformation");
|
||||
_logger.LogError("Something went wrong with geotiff to taskmap transformation");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,12 @@
|
||||
[
|
||||
{
|
||||
"File": "PlantingSampleDataLutum.zip",
|
||||
//"File": "Lutum_SampleDataPlanting.zip",
|
||||
"OutputFileName": "20210212_vraPoten_SampleData_TASKMAP_ENDPOINT",
|
||||
"OutputFileName": "20210216_vraPoten_SampleData",
|
||||
"FieldName": "lutum",
|
||||
"PlantingYear": 2020,
|
||||
"MeanDensity": "30",
|
||||
"Variation": "20",
|
||||
"UseShadow": false,
|
||||
"ConvertToCountPerArea": false,
|
||||
"Rijbreedte_m": 0.75,
|
||||
"geometryJson": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
|
@@ -25,24 +25,13 @@ namespace FarmmapsVRApoten
|
||||
_generalService = generalService;
|
||||
}
|
||||
|
||||
public async Task<Item> CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem,string meanDensity, string variation)
|
||||
public async Task<Item> CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem, string meanDensity, string variation)
|
||||
{
|
||||
var potenApplicationMapRequest = new TaskRequest() { TaskType = VRAPLANTING_TASK };
|
||||
if (inputItem != null) {potenApplicationMapRequest.attributes["inputCode"] = inputItem.Code; }
|
||||
potenApplicationMapRequest.attributes["meanDensity"] = meanDensity;
|
||||
potenApplicationMapRequest.attributes["variation"] = variation;
|
||||
|
||||
//var taskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, potenApplicationMapRequest);
|
||||
//await PollTask(TimeSpan.FromSeconds(3), async (tokenSource) =>
|
||||
//{
|
||||
// _logger.LogInformation("Checking VRAPoten task status");
|
||||
// var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
// // Code
|
||||
// if (itemTaskStatus.IsFinished)
|
||||
// tokenSource.Cancel();
|
||||
//});
|
||||
|
||||
|
||||
|
||||
var taskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, potenApplicationMapRequest);
|
||||
_logger.LogInformation($"itemTaskCode: {taskCode}");
|
||||
@@ -50,8 +39,6 @@ namespace FarmmapsVRApoten
|
||||
_logger.LogInformation($"potenTaskmapRequest type: {potenApplicationMapRequest.TaskType}");
|
||||
_logger.LogInformation($"cropfieldItemCode: {cropfieldItem.Code}");
|
||||
|
||||
|
||||
|
||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => {
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
_logger.LogInformation($"Waiting on calculation of application map; Status: {itemTaskStatus.State}");
|
||||
@@ -60,7 +47,6 @@ namespace FarmmapsVRApoten
|
||||
});
|
||||
|
||||
|
||||
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
if (itemTask.State == ItemTaskState.Error)
|
||||
{
|
||||
@@ -84,49 +70,6 @@ namespace FarmmapsVRApoten
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Extra task making use of the zonering task to convert the planting distance in cm to number of seeds per m2
|
||||
public async Task<Item> ConvertToCountPerAreaTroughZonering(Item cropfieldItem, Item geotiffItem, float rijBreedte_m)
|
||||
{
|
||||
var zoneringTaskRequest = new TaskRequest() { TaskType = VRAZONERING_TASK };
|
||||
zoneringTaskRequest.attributes["formula"] = $"((100/[0])/{rijBreedte_m.ToString()})";
|
||||
zoneringTaskRequest.attributes["output"] = "{\"Name\":\"CountPerAreaConversion\",\"Quantity\":\"CountPerArea\",\"Unit\":\"#/m2\"}";
|
||||
zoneringTaskRequest.attributes["inputs"] = $"{{\"ItemCode\":{geotiffItem.Code},\"LayerName\":null\"}}";
|
||||
|
||||
var taskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, zoneringTaskRequest);
|
||||
|
||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
|
||||
{
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
_logger.LogInformation($"Waiting on convertion to Count per area through zoneringTast; Status: {itemTaskStatus.State}");
|
||||
if (itemTaskStatus.IsFinished)
|
||||
tokenSource.Cancel();
|
||||
});
|
||||
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, taskCode);
|
||||
if (itemTask.State == ItemTaskState.Error)
|
||||
{
|
||||
_logger.LogError($"Something went wrong with task execution: {itemTask.Message}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var itemName = $"VRAZonering";
|
||||
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
||||
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
|
||||
//i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) &&
|
||||
// i.Name.ToLower().Contains(itemName.ToLower()));
|
||||
i =>
|
||||
i.Name.ToLower().Contains(itemName.ToLower()));
|
||||
if (applianceMapItem == null)
|
||||
{
|
||||
_logger.LogError("Could not find the converted to count per area geotiff child item under cropfield");
|
||||
return null;
|
||||
}
|
||||
|
||||
return applianceMapItem;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user