diff --git a/FarmmapsZonering/FarmmapsZonering.csproj b/FarmmapsZonering/FarmmapsZonering.csproj
index dcc6344..10ba86c 100644
--- a/FarmmapsZonering/FarmmapsZonering.csproj
+++ b/FarmmapsZonering/FarmmapsZonering.csproj
@@ -15,6 +15,9 @@
Always
+
+ PreserveNewest
+
diff --git a/FarmmapsZonering/Models/Settings.cs b/FarmmapsZonering/Models/Settings.cs
index c3beb90..a44ce8d 100644
--- a/FarmmapsZonering/Models/Settings.cs
+++ b/FarmmapsZonering/Models/Settings.cs
@@ -3,5 +3,8 @@ namespace FarmmapsHaulmkilling.Models
public class Settings
{
public string CropfieldItemCode { get; set; }
+ public string CropfieldName { get; set; }
+
+
}
}
\ No newline at end of file
diff --git a/FarmmapsZonering/Models/ZoneringInput.cs b/FarmmapsZonering/Models/ZoneringInput.cs
new file mode 100644
index 0000000..52d022c
--- /dev/null
+++ b/FarmmapsZonering/Models/ZoneringInput.cs
@@ -0,0 +1,20 @@
+using System;
+using Newtonsoft.Json.Linq;
+
+namespace FarmmapsZonering.Models
+{
+ public class ZoneringInput
+ {
+ public string InputItemOne { get; set; }
+ public string InputItemTwo { get; set; }
+ public string Formula { get; set; }
+ public string OutputFileName { get; set; }
+ public string CropFieldName { get; set; }
+ public string LayerName { get; set; }
+ public string CalculatedQuantity { get; set; }
+ public string CalculatedUnit { get; set; }
+ public bool CreateNewCropfield { get; set; }
+ public int CropYear { get; set; }
+ public JObject GeometryJson { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/FarmmapsZonering/Services/ZoneringService.cs b/FarmmapsZonering/Services/ZoneringService.cs
index d736240..67e5e49 100644
--- a/FarmmapsZonering/Services/ZoneringService.cs
+++ b/FarmmapsZonering/Services/ZoneringService.cs
@@ -50,7 +50,7 @@ namespace FarmmapsZonering.Services
}
var itemName = $"VRAZonering";
- var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
+ 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()));
diff --git a/FarmmapsZonering/ZoneringApplication.cs b/FarmmapsZonering/ZoneringApplication.cs
index 27ace6f..0302e03 100644
--- a/FarmmapsZonering/ZoneringApplication.cs
+++ b/FarmmapsZonering/ZoneringApplication.cs
@@ -84,17 +84,14 @@ namespace FarmmapsZonering
}
Item cropfieldItem;
- if (string.IsNullOrEmpty(_settings.CropfieldItemCode))
+ if (string.IsNullOrEmpty(_settings.CropfieldItemCode) || input.CreateNewCropfield == true)
{
_logger.LogInformation("Creating cropfield");
- //var cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, input.CropFieldName, input.cropYear
- //$"VRA Poten cropfield {input.OutputFileName}",
- //input.GeometryJson.ToString(Formatting.None));
-
-
- cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, "Cropfield VRA Zonering", 2020,
- @"{ ""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 ] ] ] }");
+ cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, input.CropFieldName, input.CropYear,
+ input.GeometryJson.ToString(Formatting.None));
+
+ _settings.CropfieldName = cropfieldItem.Name;
_settings.CropfieldItemCode = cropfieldItem.Code;
SaveSettings();
}
@@ -105,24 +102,25 @@ namespace FarmmapsZonering
}
var inputOneItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
- Path.Combine("Data", "data_9001.tif"),"data_9001");
+ Path.Combine("Data", $"{input.InputItemOne}"),Path.GetFileNameWithoutExtension($"{input.InputItemOne}"));
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");
+ var inputTwoItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
+ Path.Combine("Data", $"{input.InputItemTwo}"), Path.GetFileNameWithoutExtension($"{input.InputItemTwo}"));
if (inputTwoItem == null) {
_logger.LogError("Could not find item for uploaded data");
return;
}
- var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, "if [0] >= 1.28 then [1] else 0", new Output()
+ var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, input.Formula, new Output()
{
- Name = "Remove",
- Unit = "m&m",
- Quantity = "Nonsense"
+ Name = input.LayerName,
+ Quantity = input.CalculatedQuantity,
+ Unit = input.CalculatedUnit,
+
}, new InputParameter()
{
ItemCode = inputOneItem.Code,
@@ -134,9 +132,12 @@ namespace FarmmapsZonering
LayerName = inputTwoItem.Data["layers"][0]["name"].ToString()
});
- _logger.LogInformation("Downloading output");
+ _logger.LogInformation("Downloading output");
+
+
+
await _farmmapsApiService.DownloadItemAsync(outputItem.Code,
- Path.Combine(DownloadFolder, $"NonsenseRemove.zip"));
+ Path.Combine(DownloadFolder, $"{input.OutputFileName}.zip"));
}
private void LoadSettings()
diff --git a/FarmmapsZonering/ZoneringInput.json b/FarmmapsZonering/ZoneringInput.json
new file mode 100644
index 0000000..366cd72
--- /dev/null
+++ b/FarmmapsZonering/ZoneringInput.json
@@ -0,0 +1,29 @@
+[
+ {
+ "InputItemOne": "20201106_Sentinel2_L2A_B04.tiff",
+ "InputItemTwo": "20201106_Sentinel2_L2A_B08.tiff",
+ "Formula": "([1]-[0])/([1]+[0])",
+ "CreatedLayerName": "Biomassa",
+ "CalculatedQuantity": "NDVI",
+ "CalculatedUnit": "ndviValue",
+
+ "OutputFileName": "FullField_NDVI",
+ "CropFieldName": "FullField",
+ "CreateNewCropfield": false,
+ "CropYear": 2020,
+ "geometryJson": {
+ "type": "Polygon",
+ "coordinates": [
+
+ [
+ [ 4.9593709, 52.8014339 ],
+ [ 4.9675488, 52.7943149 ],
+ [ 4.9735195, 52.7968665 ],
+ [ 4.9667833, 52.8030414 ],
+ [ 4.9593709, 52.8014339 ]
+ ]
+
+ ]
+ }
+ }
+]