diff --git a/FarmmapsApi/Constants.cs b/FarmmapsApi/Constants.cs
index ddb8e9c..b8ed6e0 100644
--- a/FarmmapsApi/Constants.cs
+++ b/FarmmapsApi/Constants.cs
@@ -16,6 +16,7 @@ namespace FarmmapsApiSamples
public const string VRAHERBICIDE_TASK = "vnd.farmmaps.task.vraherbicide";
public const string VRAHAULMKILLING_TASK = "vnd.farmmaps.task.vrahaulmkilling";
public const string VRAPLANTING_TASK = "vnd.farmmaps.task.vrapoten";
+ public const string VRAZONERING_TASK = "vnd.farmmaps.task.vrazonering";
public const string SATELLITE_TASK = "vnd.farmmaps.task.satellite";
public const string TASKMAP_TASK = "vnd.farmmaps.task.taskmap";
public const string WORKFLOW_TASK = "vnd.farmmaps.task.workflow";
diff --git a/FarmmapsZonering/Data/data_9001.tif b/FarmmapsZonering/Data/data_9001.tif
new file mode 100644
index 0000000..9dfe818
Binary files /dev/null and b/FarmmapsZonering/Data/data_9001.tif differ
diff --git a/FarmmapsZonering/Data/data_lowres_9001.tiff b/FarmmapsZonering/Data/data_lowres_9001.tiff
new file mode 100644
index 0000000..1495092
Binary files /dev/null and b/FarmmapsZonering/Data/data_lowres_9001.tiff differ
diff --git a/FarmmapsZonering/Data/data_times_two_4326.tiff b/FarmmapsZonering/Data/data_times_two_4326.tiff
new file mode 100644
index 0000000..36b0fcd
Binary files /dev/null and b/FarmmapsZonering/Data/data_times_two_4326.tiff differ
diff --git a/FarmmapsZonering/Data/pg.json b/FarmmapsZonering/Data/pg.json
new file mode 100644
index 0000000..d6bf61a
--- /dev/null
+++ b/FarmmapsZonering/Data/pg.json
@@ -0,0 +1,8 @@
+{
+"type": "FeatureCollection",
+"name": "neo_pg",
+"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
+"features": [
+{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 5.670991253771027, 52.796788997702613 ], [ 5.671526456638633, 52.797291618546666 ], [ 5.671275936147413, 52.797422436717852 ], [ 5.671959173850738, 52.798269302728798 ], [ 5.670649634919365, 52.798778791408822 ], [ 5.671503682048522, 52.799591206957416 ], [ 5.675159003761311, 52.798193567415474 ], [ 5.673029579585948, 52.796024727480535 ], [ 5.670991253771027, 52.796788997702613 ] ] ] } }
+]
+}
diff --git a/FarmmapsZonering/Data/pg.zip b/FarmmapsZonering/Data/pg.zip
new file mode 100644
index 0000000..7dae32a
Binary files /dev/null and b/FarmmapsZonering/Data/pg.zip differ
diff --git a/FarmmapsZonering/FarmmapsZonering.csproj b/FarmmapsZonering/FarmmapsZonering.csproj
index 6f9fc2a..dcc6344 100644
--- a/FarmmapsZonering/FarmmapsZonering.csproj
+++ b/FarmmapsZonering/FarmmapsZonering.csproj
@@ -21,4 +21,8 @@
+
+
+
+
diff --git a/FarmmapsZonering/Models/InputParameter.cs b/FarmmapsZonering/Models/InputParameter.cs
new file mode 100644
index 0000000..35f25d2
--- /dev/null
+++ b/FarmmapsZonering/Models/InputParameter.cs
@@ -0,0 +1,8 @@
+namespace FarmmapsHaulmkilling.Models
+{
+ public class InputParameter
+ {
+ public string ItemCode { get; set; }
+ public string LayerName { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/FarmmapsZonering/Models/Output.cs b/FarmmapsZonering/Models/Output.cs
new file mode 100644
index 0000000..af7b083
--- /dev/null
+++ b/FarmmapsZonering/Models/Output.cs
@@ -0,0 +1,9 @@
+namespace FarmmapsZonering.Models
+{
+ public class Output
+ {
+ public string Name { get; set; }
+ public string Quantity { get; set; }
+ public string Unit { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/FarmmapsZonering/Models/Settings.cs b/FarmmapsZonering/Models/Settings.cs
index 68925ef..c3beb90 100644
--- a/FarmmapsZonering/Models/Settings.cs
+++ b/FarmmapsZonering/Models/Settings.cs
@@ -3,6 +3,5 @@ namespace FarmmapsHaulmkilling.Models
public class Settings
{
public string CropfieldItemCode { get; set; }
- public string SatelliteTaskCode { get; set; }
}
}
\ No newline at end of file
diff --git a/FarmmapsZonering/Services/ZoneringService.cs b/FarmmapsZonering/Services/ZoneringService.cs
index c55bd6f..d736240 100644
--- a/FarmmapsZonering/Services/ZoneringService.cs
+++ b/FarmmapsZonering/Services/ZoneringService.cs
@@ -1,5 +1,13 @@
+using System;
+using System.Threading.Tasks;
+using FarmmapsApi.Models;
using FarmmapsApi.Services;
+using FarmmapsHaulmkilling.Models;
+using FarmmapsZonering.Models;
using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using static FarmmapsApi.Extensions;
+using static FarmmapsApiSamples.Constants;
namespace FarmmapsZonering.Services
{
@@ -16,5 +24,44 @@ namespace FarmmapsZonering.Services
_farmmapsApiService = farmmapsApiService;
_generalService = generalService;
}
+
+ public async Task- CreateApplicationMapAsync(Item cropfieldItem, string formula, Output output, params InputParameter[] inputItemCodes)
+ {
+ var zoneringTaskRequest = new TaskRequest() {TaskType = VRAZONERING_TASK};
+ zoneringTaskRequest.attributes["formula"] = formula;
+ zoneringTaskRequest.attributes["output"] = JsonConvert.SerializeObject(output);
+ zoneringTaskRequest.attributes["inputs"] = JsonConvert.SerializeObject(inputItemCodes);
+
+ 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 calculation of application map; 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()));
+
+ if (applianceMapItem == null)
+ {
+ _logger.LogError("Could not find the VRAZonering geotiff child item under cropfield");
+ return null;
+ }
+
+ return applianceMapItem;
+ }
}
}
\ No newline at end of file
diff --git a/FarmmapsZonering/ZoneringApplication.cs b/FarmmapsZonering/ZoneringApplication.cs
index 88e4861..5522490 100644
--- a/FarmmapsZonering/ZoneringApplication.cs
+++ b/FarmmapsZonering/ZoneringApplication.cs
@@ -5,6 +5,7 @@ using FarmmapsApi;
using FarmmapsApi.Models;
using FarmmapsApi.Services;
using FarmmapsHaulmkilling.Models;
+using FarmmapsZonering.Models;
using FarmmapsZonering.Services;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
@@ -63,7 +64,7 @@ namespace FarmmapsZonering
{
_logger.LogInformation("Creating cropfield");
cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, "Cropfield VRA Zonering", 2020,
- @"{""type"":""Polygon"",""coordinates"":[[[4.617786844284247,52.22533706956424],[4.618642601314543,52.225938364585989],[4.6192153806397,52.22563988897754],[4.619192414656403,52.2256242822442],[4.620306732153958,52.225031745661528],[4.620542019225217,52.22519855319158],[4.621157509147853,52.22487436515405],[4.623387917230182,52.22367660757213],[4.624563444939009,52.22304740241544],[4.624562779355982,52.223046635247019],[4.624534908813479,52.22302596787506],[4.627873021330343,52.221240670658399],[4.627504935938338,52.220104419135129],[4.627324878706837,52.22020569669098],[4.627320696113512,52.22020660117888],[4.626707169518044,52.22053923770041],[4.624700376420229,52.221619047547488],[4.623471571183885,52.22227447969577],[4.623471511010673,52.22227500174403],[4.623468838689317,52.22228052566992],[4.617786844284247,52.22533706956424]]]}");
+ @"{ ""type"": ""Polygon"", ""coordinates"": [ [ [ 5.670991253771027, 52.796788997702613 ], [ 5.671526456638633, 52.797291618546666 ], [ 5.671275936147413, 52.797422436717852 ], [ 5.671959173850738, 52.798269302728798 ], [ 5.670649634919365, 52.798778791408822 ], [ 5.671503682048522, 52.799591206957416 ], [ 5.675159003761311, 52.798193567415474 ], [ 5.673029579585948, 52.796024727480535 ], [ 5.670991253771027, 52.796788997702613 ] ] ] }");
_settings.CropfieldItemCode = cropfieldItem.Code;
SaveSettings();
}
@@ -72,27 +73,40 @@ namespace FarmmapsZonering
_logger.LogInformation("Cropfield already exists trying to get");
cropfieldItem = await _farmmapsApiService.GetItemAsync(_settings.CropfieldItemCode);
}
+
+ var inputOneItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
+ Path.Combine("Data", "data_9001.tif"),"data_9001");
+ if (inputOneItem == null) {
+ _logger.LogError("Could not find item for uploaded data");
+ return;
+ }
+
+ var inputTwoItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
+ Path.Combine("Data", "data_times_two_4326.tiff"), "data_times_two_4326");
+ if (inputTwoItem == null) {
+ _logger.LogError("Could not find item for uploaded data");
+ return;
+ }
- ItemTaskStatus taskStatus;
- if (string.IsNullOrEmpty(_settings.SatelliteTaskCode))
- {
- _logger.LogInformation("Gathering satellite information for cropfield, this might take a while!");
- taskStatus = await _generalService.RunAndWaitForTask(cropfieldItem, SATELLITE_TASK, null, 20);
-
- if (taskStatus.State == ItemTaskState.Error)
+ var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, "[0] + [1]", new Output()
{
- _logger.LogError($"Something went wrong when trying to process satellite data; {taskStatus.Message}");
- return;
- }
-
- _settings.SatelliteTaskCode = taskStatus.Code;
- SaveSettings();
-
- }
- else
- {
- taskStatus = await _farmmapsApiService.GetTaskStatusAsync(_settings.CropfieldItemCode, _settings.SatelliteTaskCode);
- }
+ Name = "add",
+ Unit = "n/kg",
+ Quantity = "Nitrogen"
+ }, new InputParameter()
+ {
+ ItemCode = inputOneItem.Code,
+ LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
+ },
+ new InputParameter()
+ {
+ ItemCode = inputTwoItem.Code,
+ LayerName = inputTwoItem.Data["layers"][0]["name"].ToString()
+ });
+
+ _logger.LogInformation("Downloading output");
+ await _farmmapsApiService.DownloadItemAsync(outputItem.Code,
+ Path.Combine(DownloadFolder, $"times_2_zonering.zip"));
}
private void LoadSettings()