forked from FarmMaps/FarmMapsApiClient
some adjustments to zoning, included vandersat among others
This commit is contained in:
@@ -4,7 +4,8 @@ namespace FarmmapsHaulmkilling.Models
|
||||
{
|
||||
public string CropfieldItemCode { get; set; }
|
||||
public string CropfieldName { get; set; }
|
||||
|
||||
|
||||
public string SatelliteTaskCode { get; set; }
|
||||
public string VanDerSatTaskCode { get; set; }
|
||||
public string WatBalTaskCode { get; set; }
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
namespace FarmmapsZonering.Models
|
||||
{
|
||||
public class ZoneringInput
|
||||
@@ -17,6 +16,9 @@ namespace FarmmapsZonering.Models
|
||||
public bool CreateNewCropfield { get; set; }
|
||||
public int CropYear { get; set; }
|
||||
public JObject GeometryJson { get; set; }
|
||||
public bool GetWatBal { get; set; }
|
||||
public bool GetVanDerSat { get; set; }
|
||||
public bool storeVanDerSatStatistics { get; set; }
|
||||
|
||||
}
|
||||
}
|
@@ -52,9 +52,10 @@ namespace FarmmapsZonering.Services
|
||||
var itemName = $"VRAZonering";
|
||||
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
||||
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
|
||||
i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) &&
|
||||
//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 VRAZonering geotiff child item under cropfield");
|
||||
|
@@ -41,9 +41,6 @@ namespace FarmmapsZonering
|
||||
if (!Directory.Exists(DownloadFolder))
|
||||
Directory.CreateDirectory(DownloadFolder);
|
||||
|
||||
// Load settings from previous cropfield
|
||||
LoadSettings();
|
||||
|
||||
// Read input data from separate file
|
||||
var zoneringInputJson = File.ReadAllText("ZoneringInput.json");
|
||||
List<ZoneringInput> zoneringInputs = JsonConvert.DeserializeObject<List<ZoneringInput>>(zoneringInputJson);
|
||||
@@ -76,6 +73,16 @@ namespace FarmmapsZonering
|
||||
return;
|
||||
}
|
||||
|
||||
bool useCreatedCropfield = true;
|
||||
bool GetWatBal = input.GetWatBal;
|
||||
bool getVanDerSat = input.GetVanDerSat;
|
||||
bool StoreVanDerSatStatistics = input.storeVanDerSatStatistics;
|
||||
var FieldName = input.CropFieldName;
|
||||
string settingsfile = $"Settings_{FieldName}.json";
|
||||
|
||||
// Load settings from previous cropfield
|
||||
LoadSettings(settingsfile);
|
||||
|
||||
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
|
||||
if (uploadedRoot == null)
|
||||
{
|
||||
@@ -88,28 +95,67 @@ namespace FarmmapsZonering
|
||||
{
|
||||
_logger.LogInformation("Creating cropfield");
|
||||
|
||||
|
||||
cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, input.CropFieldName, input.CropYear,
|
||||
input.GeometryJson.ToString(Formatting.None));
|
||||
|
||||
_settings.CropfieldName = cropfieldItem.Name;
|
||||
_settings.CropfieldItemCode = cropfieldItem.Code;
|
||||
SaveSettings();
|
||||
}
|
||||
SaveSettings(settingsfile);
|
||||
|
||||
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 ] ] ] }");
|
||||
_settings.CropfieldItemCode = cropfieldItem.Code;
|
||||
SaveSettings(settingsfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
_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", $"{input.InputItemOne}"),Path.GetFileNameWithoutExtension($"{input.InputItemOne}"));
|
||||
if (GetWatBal==true) {
|
||||
////Run watbal
|
||||
//if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.WatBalTaskCode)) {
|
||||
// var WatBalTaskCode = await _generalService.RunWatBalTask(cropfieldItem);
|
||||
// _settings.WatBalTaskCode = WatBalTaskCode;
|
||||
// SaveSettings(settingsfile);
|
||||
//}
|
||||
|
||||
//// Get watbal data
|
||||
//Item WatBalItem = await _generalService.FindWatBalItem(cropfieldItem, _settings.WatBalTaskCode, FieldName, StoreStatistics);
|
||||
}
|
||||
|
||||
if (getVanDerSat==true) {
|
||||
// check if vandersat task not yet done, do here and save taskcode
|
||||
if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.VanDerSatTaskCode)) {
|
||||
var VanDerSatTaskCode = await _generalService.RunVanDerSatTask(cropfieldItem);
|
||||
_settings.VanDerSatTaskCode = VanDerSatTaskCode;
|
||||
SaveSettings(settingsfile);
|
||||
}
|
||||
|
||||
// Select a particular image item from VanDerSat
|
||||
Item VanDerSatItem = await _generalService.FindVanDerSatItem(cropfieldItem, _settings.VanDerSatTaskCode, FieldName, StoreVanDerSatStatistics);
|
||||
|
||||
|
||||
// download the geotiff
|
||||
_logger.LogInformation("Downloading geotiff file");
|
||||
await _farmmapsApiService.DownloadItemAsync(VanDerSatItem.Code,
|
||||
Path.Combine(DownloadFolder, $"nbs_VanDerSatGeotiff_{input.OutputFileName}.zip"));
|
||||
}
|
||||
|
||||
var inputOneItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
|
||||
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", $"{input.InputItemTwo}"), Path.GetFileNameWithoutExtension($"{input.InputItemTwo}"));
|
||||
|
||||
if (inputTwoItem == null) {
|
||||
_logger.LogError("Could not find item for uploaded data");
|
||||
return;
|
||||
@@ -120,7 +166,8 @@ namespace FarmmapsZonering
|
||||
Name = input.LayerName,
|
||||
Quantity = input.CalculatedQuantity,
|
||||
Unit = input.CalculatedUnit,
|
||||
|
||||
|
||||
|
||||
}, new InputParameter()
|
||||
{
|
||||
ItemCode = inputOneItem.Code,
|
||||
@@ -128,8 +175,8 @@ namespace FarmmapsZonering
|
||||
},
|
||||
new InputParameter()
|
||||
{
|
||||
ItemCode = inputTwoItem.Code,
|
||||
LayerName = inputTwoItem.Data["layers"][0]["name"].ToString()
|
||||
ItemCode = inputOneItem.Code,
|
||||
LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
||||
});
|
||||
|
||||
_logger.LogInformation("Downloading output");
|
||||
@@ -137,29 +184,33 @@ namespace FarmmapsZonering
|
||||
|
||||
|
||||
await _farmmapsApiService.DownloadItemAsync(outputItem.Code,
|
||||
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.zip"));
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
if (File.Exists(SettingsFile))
|
||||
{
|
||||
var jsonText = File.ReadAllText(SettingsFile);
|
||||
// Functions to save previously created cropfields
|
||||
private void LoadSettings(string file) {
|
||||
if (File.Exists(file)) {
|
||||
var jsonText = File.ReadAllText(file);
|
||||
_settings = JsonConvert.DeserializeObject<Settings>(jsonText);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_settings = new Settings();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
private void SaveSettings(string file) {
|
||||
if (_settings == null)
|
||||
return;
|
||||
|
||||
var json = JsonConvert.SerializeObject(_settings);
|
||||
File.WriteAllText(SettingsFile, json);
|
||||
File.WriteAllText(file, json);
|
||||
}
|
||||
private void SaveInfo(string file) {
|
||||
if (_settings == null)
|
||||
return;
|
||||
|
||||
var json = JsonConvert.SerializeObject(_settings);
|
||||
File.WriteAllText(file, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,47 +1,71 @@
|
||||
[
|
||||
//Formule kan meerdere inputs aan
|
||||
// Met blokhaken en een nummer specificeer je een input:
|
||||
//[0], [10]. etc...
|
||||
// Aan de hand van de volgorde van input wordt momenteel bepaald welk nummer bij welk input hoort.
|
||||
//[0] is dus de eerst tiff opgegeven.Als het goed is maakt het nummer nu niks uit, dus als er 2 inputs zijn en in de formule staan[0] en[10] dan zal die nog steeds werken.
|
||||
//De volgorde van de tiff kun je verslepen, bij de formule inputs kun je de input van het ene[0] slot naar het andere slepen[10]
|
||||
//Functies: abs, min en max
|
||||
//Constanten: pi en e
|
||||
|
||||
{
|
||||
"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 ]
|
||||
]
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
//if ([0] -[1])/ ([0] +[1]) < 0 then 0
|
||||
//else if ([0] -[1])/ ([0] +[1]) > 1 then 1
|
||||
//else ([0] -[1]) / ([0] +[1])
|
||||
|
||||
//{
|
||||
// "File": "Points.json",
|
||||
// "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": [
|
||||
// [
|
||||
// [ 5.66886041703652044, 52.52929999060298627 ],
|
||||
// [ 5.6716230923214912, 52.52946316399909676 ],
|
||||
// [ 5.67185376229668581, 52.5280565894154563 ],
|
||||
// [ 5.66903207841337231, 52.52790646510525363 ],
|
||||
// [ 5.66886041703652044, 52.52929999060298627 ]
|
||||
// ]
|
||||
// ]
|
||||
// }
|
||||
//}
|
||||
|
||||
// [
|
||||
// [ 4.9593709, 52.8014339 ],
|
||||
// [ 4.9675488, 52.7943149 ],
|
||||
// [ 4.9735195, 52.7968665 ],
|
||||
// [ 4.9667833, 52.8030414 ],
|
||||
// [ 4.9593709, 52.8014339 ]
|
||||
// ]
|
||||
|
||||
// ]
|
||||
// },
|
||||
|
||||
{
|
||||
"InputItemOne": "data_9001.tif",
|
||||
"InputItemTwo": "data_times_two_4326.tiff",
|
||||
"Formula": "([1]-[0])/([1]+[0])",
|
||||
"CreatedLayerName": "Biomassa",
|
||||
"CalculatedQuantity": "NDVI",
|
||||
"CalculatedUnit": "ndviValue",
|
||||
"OutputFileName": "Zoning",
|
||||
"CropFieldName": "Data_whole",
|
||||
"UseShadow": false,
|
||||
"GetWatBal": false,
|
||||
"GetVanDerSat": true,
|
||||
"storeVanDerSatStatistics": true,
|
||||
"CropYear": 2020,
|
||||
"geometryJson": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[ 5.66886041703652044, 52.52929999060298627 ],
|
||||
[ 5.6716230923214912, 52.52946316399909676 ],
|
||||
[ 5.67185376229668581, 52.5280565894154563 ],
|
||||
[ 5.66903207841337231, 52.52790646510525363 ],
|
||||
[ 5.66886041703652044, 52.52929999060298627 ]
|
||||
]
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
|
Reference in New Issue
Block a user