diff --git a/FarmmapsApi/Constants.cs b/FarmmapsApi/Constants.cs index b8ed6e0..b061c18 100644 --- a/FarmmapsApi/Constants.cs +++ b/FarmmapsApi/Constants.cs @@ -18,10 +18,12 @@ namespace FarmmapsApiSamples 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 VANDERSAT_TASK = "vnd.farmmaps.task.vandersat"; public const string TASKMAP_TASK = "vnd.farmmaps.task.taskmap"; public const string WORKFLOW_TASK = "vnd.farmmaps.task.workflow"; public const string BOFEK_TASK = "vnd.farmmaps.task.bofek"; public const string SHADOW_TASK = "vnd.farmmaps.task.shadow"; public const string AHN_TASK = "vnd.farmmaps.task.ahn"; + public const string WATBAL_TASK = "vnd.farmmaps.task.watbal"; } } diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index 3a04ca2..6bb9c76 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -12,23 +12,19 @@ using static FarmmapsApiSamples.Constants; namespace FarmmapsApi.Services { - public class GeneralService - { + public class GeneralService { private readonly ILogger _logger; private readonly FarmmapsApiService _farmmapsApiService; - public GeneralService(ILogger logger, FarmmapsApiService farmmapsApiService) - { + public GeneralService(ILogger logger, FarmmapsApiService farmmapsApiService) { _logger = logger; _farmmapsApiService = farmmapsApiService; } public async Task CreateCropfieldItemAsync(string parentItemCode, string name, int year, - string fieldGeomJson, string data = "{}") - { + string fieldGeomJson, string data = "{}") { var currentYear = new DateTime(year, 1, 1); - var cropfieldItemRequest = new ItemRequest() - { + var cropfieldItemRequest = new ItemRequest() { ParentCode = parentItemCode, ItemType = CROPFIELD_ITEMTYPE, Name = name, @@ -41,8 +37,7 @@ namespace FarmmapsApi.Services return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest); } - public async Task UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) - { + public async Task UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) { var startUpload = DateTime.UtcNow; var result = await _farmmapsApiService.UploadFile(filePath, root.Code, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); @@ -55,8 +50,7 @@ namespace FarmmapsApi.Services i.Name.ToLower().Contains(itemName.ToLower())); } - public async Task UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName) - { + public async Task UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName) { var startUpload = DateTime.UtcNow; var result = await _farmmapsApiService.UploadFile(filePath, root.Code, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); @@ -66,11 +60,10 @@ namespace FarmmapsApi.Services return await FindChildItemAsync(root.Code, SHAPE_PROCESSED_ITEMTYPE, itemName, i => i.Created >= startUpload && - i.Name.ToLower().Contains(itemName.ToLower()));; + i.Name.ToLower().Contains(itemName.ToLower())); ; } - public async Task ShapeToGeotiff(Item shapeItem) - { + public async Task ShapeToGeotiff(Item shapeItem) { await RunAndWaitForTask(shapeItem, "vnd.farmmaps.task.shapetogeotiff"); // the parent of the shape item is now the tiff item @@ -79,14 +72,12 @@ namespace FarmmapsApi.Services } - public async Task GeotiffToShape(Item tiffItem) - { - var taskmapRequest = new TaskRequest {TaskType = TASKMAP_TASK}; + public async Task GeotiffToShape(Item tiffItem) { + var taskmapRequest = new TaskRequest { TaskType = TASKMAP_TASK }; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(tiffItem.Code, taskmapRequest); - await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => - { + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(tiffItem.Code, itemTaskCode); _logger.LogInformation($"Waiting on converting geotiff to shape; status: {itemTaskStatus.State}"); if (itemTaskStatus.IsFinished) @@ -94,8 +85,7 @@ namespace FarmmapsApi.Services }); var itemTask = await _farmmapsApiService.GetTaskStatusAsync(tiffItem.Code, itemTaskCode); - if (itemTask.State == ItemTaskState.Error) - { + if (itemTask.State == ItemTaskState.Error) { _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } @@ -104,8 +94,7 @@ namespace FarmmapsApi.Services var itemName = "Taskmap"; var taskMapItem = await FindChildItemAsync(tiffItem.Code, SHAPE_PROCESSED_ITEMTYPE, itemName); - if (taskMapItem == null) - { + if (taskMapItem == null) { _logger.LogError("Could not find the shape taskmap as a child item under the input"); return null; } @@ -115,18 +104,15 @@ namespace FarmmapsApi.Services public async Task RunAndWaitForTask(Item subjectItem, string taskIdentifier, - Action configureCallback = null, int retrySeconds = 3) - { - var taskRequest = new TaskRequest() - { + Action configureCallback = null, int retrySeconds = 3) { + var taskRequest = new TaskRequest() { TaskType = taskIdentifier }; configureCallback?.Invoke(taskRequest); var taskCode = await _farmmapsApiService.QueueTaskAsync(subjectItem.Code, taskRequest); - await PollTask(TimeSpan.FromSeconds(retrySeconds), async (tokenSource) => - { + await PollTask(TimeSpan.FromSeconds(retrySeconds), async (tokenSource) => { _logger.LogInformation($"Checking {taskIdentifier} task status"); var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(subjectItem.Code, taskCode); if (itemTaskStatus.IsFinished) @@ -139,28 +125,24 @@ namespace FarmmapsApi.Services } public async Task FindChildItemAsync(string parentCode, string itemType, string containsName, - Func filter = null, int maxTries = 10) - { + Func filter = null, int maxTries = 10) { Item dataItem = null; int tries = 0; - await PollTask(TimeSpan.FromSeconds(3), async source => - { + await PollTask(TimeSpan.FromSeconds(3), async source => { _logger.LogInformation($"Trying to get {containsName} data"); var uploadedFilesChildren = await _farmmapsApiService.GetItemChildrenAsync(parentCode, itemType); Func func = filter ?? (i => i.Name.ToLower().Contains(containsName.ToLower())); dataItem = uploadedFilesChildren.FirstOrDefault(func); - if (dataItem != null || tries == maxTries) - { + if (dataItem != null || tries == maxTries) { source.Cancel(); } tries++; }); - if (dataItem == null) - { + if (dataItem == null) { _logger.LogError("dataItem not found"); return null; } @@ -169,14 +151,12 @@ namespace FarmmapsApi.Services return dataItem; } - public async Task RunBofekTask(Item cropfieldItem) - { - var taskmapRequest = new TaskRequest {TaskType = BOFEK_TASK}; + public async Task RunBofekTask(Item cropfieldItem) { + var taskmapRequest = new TaskRequest { TaskType = BOFEK_TASK }; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); - await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => - { + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); _logger.LogInformation($"Waiting on retreiving BOFEK data; status: {itemTaskStatus.State}"); if (itemTaskStatus.IsFinished) @@ -184,8 +164,7 @@ namespace FarmmapsApi.Services }); var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); - if (itemTask.State == ItemTaskState.Error) - { + if (itemTask.State == ItemTaskState.Error) { _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } @@ -194,8 +173,7 @@ namespace FarmmapsApi.Services var itemName = "bofek"; var bofekItem = await FindChildItemAsync(cropfieldItem.Code, SHAPE_PROCESSED_ITEMTYPE, itemName); - if (bofekItem == null) - { + if (bofekItem == null) { _logger.LogError("Could not find the BOFEK data as a child item under the cropfield"); return null; } @@ -203,14 +181,12 @@ namespace FarmmapsApi.Services return bofekItem; } - public async Task RunAhnTask(Item cropfieldItem) - { - var taskmapRequest = new TaskRequest {TaskType = AHN_TASK}; + public async Task RunAhnTask(Item cropfieldItem) { + var taskmapRequest = new TaskRequest { TaskType = AHN_TASK }; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); - await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => - { + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); _logger.LogInformation($"Waiting on retreiving AHN data; status: {itemTaskStatus.State}"); if (itemTaskStatus.IsFinished) @@ -218,8 +194,7 @@ namespace FarmmapsApi.Services }); var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); - if (itemTask.State == ItemTaskState.Error) - { + if (itemTask.State == ItemTaskState.Error) { _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } @@ -228,8 +203,7 @@ namespace FarmmapsApi.Services var itemName = "ahn"; var ahnItem = await FindChildItemAsync(cropfieldItem.Code, GEOTIFF_PROCESSED_ITEMTYPE, itemName); - if (ahnItem == null) - { + if (ahnItem == null) { _logger.LogError("Could not find the AHN data as a child item under the cropfield"); return null; } @@ -237,14 +211,12 @@ namespace FarmmapsApi.Services return ahnItem; } - public async Task RunShadowTask(Item cropfieldItem) - { - var taskmapRequest = new TaskRequest {TaskType = SHADOW_TASK}; + public async Task RunShadowTask(Item cropfieldItem) { + var taskmapRequest = new TaskRequest { TaskType = SHADOW_TASK }; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); - await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => - { + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); _logger.LogInformation($"Waiting on calculation shadow data; status: {itemTaskStatus.State}"); if (itemTaskStatus.IsFinished) @@ -252,8 +224,7 @@ namespace FarmmapsApi.Services }); var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); - if (itemTask.State == ItemTaskState.Error) - { + if (itemTask.State == ItemTaskState.Error) { _logger.LogError($"Something went wrong with task execution: {itemTask.Message}"); return null; } @@ -262,8 +233,7 @@ namespace FarmmapsApi.Services var itemName = "shadow"; var shadowItem = await FindChildItemAsync(cropfieldItem.Code, GEOTIFF_PROCESSED_ITEMTYPE, itemName); - if (shadowItem == null) - { + if (shadowItem == null) { _logger.LogError("Could not find the shadow data as a child item under the cropfield"); return null; } @@ -272,27 +242,24 @@ namespace FarmmapsApi.Services } - public async Task RunSatelliteTask(Item cropfieldItem) - { + public async Task RunSatelliteTask(Item cropfieldItem) { _logger.LogInformation("Gathering satellite information for cropfield, this might take a while!"); var taskmapRequest = new TaskRequest { TaskType = SATELLITE_TASK }; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); - await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => - { + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); _logger.LogInformation($"Waiting on satellite data; status: {itemTaskStatus.State}"); if (itemTaskStatus.IsFinished) tokenSource.Cancel(); - + }); var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); - if (itemTask.State == ItemTaskState.Error) - { + if (itemTask.State == ItemTaskState.Error) { _logger.LogError($"Something went wrong when trying to process satellite data; {itemTask.Message}"); } @@ -301,8 +268,7 @@ namespace FarmmapsApi.Services } - public async Task FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode) - { + public async Task FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode, string FieldName, bool StoreStatistics) { var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode); @@ -314,8 +280,7 @@ namespace FarmmapsApi.Services taskStatus.Finished <= item.Created.Value.AddHours(1)); - if (temporalItem == null) - { + if (temporalItem == null) { _logger.LogError("Temporal item not found"); } @@ -325,19 +290,18 @@ namespace FarmmapsApi.Services _logger.LogInformation("Available satellite images:"); var count = 0; TimeSpan.FromSeconds(0.5); - foreach (var item in satelliteTiffs) - { + foreach (var item in satelliteTiffs) { Console.WriteLine($"Satellite image #{count}: {item.DataDate}"); count++; } + _logger.LogInformation("Enter satellite image number for NBS application"); int elment = Int32.Parse(Console.ReadLine()); var selectedSatelliteItem = satelliteTiffs[elment]; - if (selectedSatelliteItem == null) - { + if (selectedSatelliteItem == null) { _logger.LogError("Satellite item not found"); } @@ -350,8 +314,168 @@ namespace FarmmapsApi.Services } + //VanDerSat + public async Task RunVanDerSatTask(Item cropfieldItem) { + + _logger.LogInformation("Gathering VanDerSat information for cropfield, this might take a while!"); + + var taskmapRequest = new TaskRequest { TaskType = VANDERSAT_TASK }; + string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); + + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { + var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); + _logger.LogInformation($"Waiting on VanDerSat data; status: {itemTaskStatus.State}"); + if (itemTaskStatus.IsFinished) + tokenSource.Cancel(); + + }); + + var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); + + if (itemTask.State == ItemTaskState.Error) { + _logger.LogError($"Something went wrong when trying to process VanDerSat data; {itemTask.Message}"); + + } + + return itemTask.Code; + } + + public async Task RunWatBalTask(Item cropfieldItem) { + + _logger.LogInformation("Gathering WatBal information for cropfield, this might take a while!"); + + var taskmapRequest = new TaskRequest { TaskType = WATBAL_TASK }; + string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); + + await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => { + var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); + _logger.LogInformation($"Waiting on VanDerSat data; status: {itemTaskStatus.State}"); + if (itemTaskStatus.IsFinished) + tokenSource.Cancel(); + + }); + + var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode); + + if (itemTask.State == ItemTaskState.Error) { + _logger.LogError($"Something went wrong when trying to process WatBal data; {itemTask.Message}"); + + } + + return itemTask.Code; + } + + public async Task FindVanDerSatItem(Item cropfieldItem, string VanDerSatTaskCode, string FieldName, bool StoreStatistics) { + + var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, VanDerSatTaskCode); + + + // find VanDerSat data temporal + var temporalItem = await FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE, "Van der Sat"); + + + if (temporalItem == null) { + _logger.LogError("Temporal item not found"); + + } + + var VanDerSatiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code); + + _logger.LogInformation("Available VanDerSat images:"); + var count = 0; + TimeSpan.FromSeconds(0.5); + foreach (var item in VanDerSatiffs) { + + //Console.WriteLine($"Van der Sat image #{count}: {item.DataDate}"); + //if (count == 0 ) { + // Console.WriteLine($"vandersat image #{count}: {item.Data}"); + //} + + if (StoreStatistics == true) { + var VanDerSatBand = item.Data["layers"][0]["name"]; + var VanderSatFile = $"C:\\Akkerweb\\{FieldName}_{VanDerSatBand}.csv"; + var NewLineField = $"Field,Date,Mean,Min,Max,Standard deviation, ConfidenceInterval low, ConfidenceInterval high" + Environment.NewLine; + if (count == 0) { + File.AppendAllText(VanderSatFile, NewLineField); + var numbervandersat = VanDerSatiffs.Count; + Console.WriteLine($"{numbervandersat} Van der Sat images found"); + } + + + var VanderSatStatistics = item.Data["layers"][0]["renderer"]["band"]["statistics"]; + var VanDerSatImageDate = (DateTime)item.DataDate; + var VanderSatDate = VanDerSatImageDate.ToString("yyyy-MM-dd"); + var NewLineDate = $"\"date\":{VanderSatDate}" + Environment.NewLine; + if (VanderSatStatistics == null) { + Console.WriteLine($"{VanderSatDate} no statistics found"); + //Console.WriteLine($"Available data: {item.Data}"); + } else { + File.AppendAllText(VanderSatFile, $"{FieldName},{VanderSatDate},{VanderSatStatistics["mean"]},{VanderSatStatistics["min"]},{VanderSatStatistics["max"]},{VanderSatStatistics["stddev"]},{VanderSatStatistics["confidenceIntervalLow"]},{VanderSatStatistics["confidenceIntervalHigh"]}" + Environment.NewLine); + } + + + } + + count++; + } + //_logger.LogInformation("Enter VanDerSat image number"); + //int element = Int32.Parse(Console.ReadLine()); + int element = 0; + var selectedVanDerSatItem = VanDerSatiffs[element]; + + if (selectedVanDerSatItem == null) { + _logger.LogError("VanDerSat item not found"); + + } + + return selectedVanDerSatItem; + + + } + + public async Task FindWatBalItem(Item cropfieldItem, string WatBalTaskCode, string FieldName, bool StoreStatistics) { + + var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, WatBalTaskCode); + + + // find WatBal data temporal + var temporalItem = await FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE, "WatBal");//, item => item.SourceTask == VANDERSAT_TASK && + // taskStatus.Finished >= item.Created && + // taskStatus.Finished <= item.Created.Value.AddHours(1)); + + + if (temporalItem == null) { + _logger.LogError("Temporal item not found"); + + } + + var WatBalData = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code); + + _logger.LogInformation("Available WatBal Data:"); + var count = 0; + TimeSpan.FromSeconds(0.5); + foreach (var item in WatBalData) { + + Console.WriteLine($"WatBal data #{count}: {item.DataDate}"); + if (count == 0) { + Console.WriteLine($"WatBalData #{count}: {item.Data}"); + } + + count++; + } + + int element = 0; + var selectedWatBalItem = WatBalData[element]; + + if (selectedWatBalItem == null) { + _logger.LogError("WatBal item not found"); + + } + + return selectedWatBalItem; + } } } \ No newline at end of file diff --git a/FarmmapsNbs/Models/NitrogenInput.cs b/FarmmapsNbs/Models/NitrogenInput.cs index 87fb186..7d29e6e 100644 --- a/FarmmapsNbs/Models/NitrogenInput.cs +++ b/FarmmapsNbs/Models/NitrogenInput.cs @@ -14,6 +14,8 @@ namespace FarmmapsNbs.Models public int TargetYield { get; set; } public JObject GeometryJson { get; set; } public string InputLayerName { get; set; } + public string fieldName{ get; set; } + public bool storeSatelliteStatistics { get; set; } } diff --git a/FarmmapsNbs/Models/Settings.cs b/FarmmapsNbs/Models/Settings.cs index 41b3853..40cd25d 100644 --- a/FarmmapsNbs/Models/Settings.cs +++ b/FarmmapsNbs/Models/Settings.cs @@ -2,5 +2,8 @@ public class Settings { public string CropfieldItemCode { get; set; } public string SatelliteTaskCode { get; set; } + public string VanDerSatTaskCode { get; set; } + public string WatBalTaskCode { get; set; } + } } \ No newline at end of file diff --git a/FarmmapsNbs/NbsApplication.cs b/FarmmapsNbs/NbsApplication.cs index 23c4ce0..7a74696 100644 --- a/FarmmapsNbs/NbsApplication.cs +++ b/FarmmapsNbs/NbsApplication.cs @@ -38,16 +38,11 @@ namespace FarmmapsNbs public async Task RunAsync() { var nitrogenInputJson = File.ReadAllText("NitrogenInput.json"); - //var nitrogenInputJson = File.ReadAllText("fivefieldsinput.json"); List nitrogenInputs = JsonConvert.DeserializeObject>(nitrogenInputJson); if (!Directory.Exists(DownloadFolder)) Directory.CreateDirectory(DownloadFolder); - - - LoadSettings(); - // !! this call is needed the first time an api is called with a fresh clientid and secret !! await _farmmapsApiService.GetCurrentUserCodeAsync(); var roots = await _farmmapsApiService.GetCurrentUserRootsAsync(); @@ -67,10 +62,16 @@ namespace FarmmapsNbs private async Task Process(List roots, NitrogenInput input) { + // !!specify if you are using an already created cropfield: - bool useCreatedCropfield = false; + bool useCreatedCropfield = true; var plantingDate = input.PlantingDate; + var FieldName = input.fieldName; + bool StoreStatistics = input.storeSatelliteStatistics; var measurementDate = input.MeasurementDate; + string settingsfile = $"Settings_{FieldName}.json"; + + LoadSettings(settingsfile); var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded"); if (uploadedRoot == null) @@ -85,8 +86,7 @@ namespace FarmmapsNbs _logger.LogError("Could not find a needed root item"); return; } - - + // Use already created cropfield or create new one Item cropfieldItem; if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.CropfieldItemCode)) @@ -95,7 +95,7 @@ namespace FarmmapsNbs cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDriveRoot.Code, $"VRA NBS cropfield {input.OutputFileName}", plantingDate.Year, input.GeometryJson.ToString(Formatting.None)); _settings.CropfieldItemCode = cropfieldItem.Code; - SaveSettings(); + SaveSettings(settingsfile); } else { @@ -103,40 +103,59 @@ namespace FarmmapsNbs cropfieldItem = await _farmmapsApiService.GetItemAsync(_settings.CropfieldItemCode); } - - var geotiffItem = (Item)null; // No file input, use most recent satellite image - if (string.IsNullOrEmpty(input.File)) - { + if (string.IsNullOrEmpty(input.File)) { _logger.LogInformation("No specific data given, retrieving most recent satellite image"); // check if satellite task not yet done, do here and save taskcode - if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.SatelliteTaskCode)) - { + if (useCreatedCropfield == false || string.IsNullOrEmpty(_settings.SatelliteTaskCode)) { var satelliteTaskCode = await _generalService.RunSatelliteTask(cropfieldItem); _settings.SatelliteTaskCode = satelliteTaskCode; - SaveSettings(); + SaveSettings(settingsfile); } // Select a particular satellite item from satelliteTask - Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode); + Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode, FieldName, StoreStatistics); + + var satelliteBand = satalliteItem.Data["layers"][0]["name"]; + var satelliteStatistics = satalliteItem.Data["layers"][0]["renderer"]["band"]["statistics"]; + Console.WriteLine($"Satellite image date: {satalliteItem.DataDate}"); + //Console.WriteLine($"Satellite image statistics for band {satelliteBand}: {satelliteStatistics}"); + + //Store data to csv + if (StoreStatistics==true) { + var SatelliteFile = $"C:\\Akkerweb\\DataSatellite_{FieldName}.csv"; + var NewLineField = $"\"Field\":{FieldName}" + Environment.NewLine; + var NewLineDate = $"\"date\":{satalliteItem.DataDate}" + Environment.NewLine; + var i = 0; + foreach (var item in satelliteStatistics) { + //var NewLines2; + if (i == 0) { + File.AppendAllText(SatelliteFile, NewLineDate); + i++; + } + File.AppendAllText(SatelliteFile, $"{item}" + Environment.NewLine); + + } + } // must be wdvi[1] var inputType = (satalliteItem.Data["layers"] as JArray)?[1]["name"].ToString(); - if (string.IsNullOrEmpty(inputType)) - { + if (string.IsNullOrEmpty(inputType)) { _logger.LogError("Could not get the input type name from the satellite item"); return; } // download the geotiff + var SatelliteImageDate = (DateTime)satalliteItem.DataDate; + var SatelliteDate = SatelliteImageDate.ToString("yyyyMMdd"); _logger.LogInformation("Downloading geotiff file"); await _farmmapsApiService.DownloadItemAsync(satalliteItem.Code, - Path.Combine(DownloadFolder, $"nbs_inputSatelliteGeotiff_{input.OutputFileName}.zip")); + Path.Combine(DownloadFolder, $"nbs_inputSatelliteGeotiff_{input.OutputFileName}_{inputType}_{SatelliteDate}.zip")); // overwrite measurement date by date of satellite item measurementDate = satalliteItem.DataDate.Value; @@ -147,20 +166,19 @@ namespace FarmmapsNbs } - // (geo)tiff input: else if (input.File.Contains(".tif") || input.File.Contains(".geotiff")) { - _logger.LogInformation("input = tiff data"); - var dataPath = Path.Combine("Data", input.File); - geotiffItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE, dataPath, - Path.GetFileNameWithoutExtension(input.File)); + _logger.LogInformation("input = tiff data"); + var dataPath = Path.Combine("Data", input.File); + geotiffItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE, dataPath, + Path.GetFileNameWithoutExtension(input.File)); + + if (geotiffItem == null) { + _logger.LogError("Could not find item for uploaded data"); + return; + } + } - if (geotiffItem == null) { - _logger.LogError("Could not find item for uploaded data"); - return; - } - } - // json/shape input else { var isGeoJson = input.File.Contains("json"); @@ -187,22 +205,32 @@ namespace FarmmapsNbs } - - + //// 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, StoreStatistics); + //// download the geotiff + //_logger.LogInformation("Downloading geotiff file"); + //await _farmmapsApiService.DownloadItemAsync(VanDerSatItem.Code, + // Path.Combine(DownloadFolder, $"nbs_VanDerSatGeotiff_{input.OutputFileName}.zip")); _logger.LogInformation($"Calculating targetN with targetYield: {input.TargetYield}"); var targetNItem = await _nitrogenService.CreateTargetNItem(cropfieldItem); var targetNData = await _nitrogenService.CalculateTargetN(cropfieldItem, targetNItem, plantingDate, measurementDate, input.PotatoPurposeType, input.TargetYield); - if (targetNData == null) - { + if (targetNData == null) { _logger.LogError("Something went wrong with TargetN calculation"); return; } - + _logger.LogInformation($"TargetN: {targetNData.TargetN}"); ////Option to manually adjust the Target N, for test purposes only! //targetNData.TargetN = 225; @@ -215,12 +243,11 @@ namespace FarmmapsNbs var uptakeMapItem = await _nitrogenService.CalculateUptakeMap(cropfieldItem, geotiffItem, plantingDate, measurementDate, input.InputVariable, input.InputLayerName); - if (uptakeMapItem == null) - { + if (uptakeMapItem == null) { _logger.LogError("Something went wrong with creating the uptakeMap"); return; } - + _logger.LogInformation("Downloading uptake map"); await _farmmapsApiService.DownloadItemAsync(uptakeMapItem.Code, Path.Combine(DownloadFolder, $"{input.OutputFileName}.uptake.zip")); @@ -231,8 +258,7 @@ namespace FarmmapsNbs await _nitrogenService.CalculateApplicationMap(cropfieldItem, geotiffItem, plantingDate, measurementDate, input.InputVariable, targetNData.TargetN, input.InputLayerName); - if (applicationMapItem == null) - { + if (applicationMapItem == null) { _logger.LogError("Something went wrong with creating the applicationMap"); return; } @@ -244,15 +270,13 @@ namespace FarmmapsNbs //transforming tiff to shape var tiffItem = applicationMapItem; - if (tiffItem == null) - { + 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) - { + if (taskmap == null) { _logger.LogError("Something went wrong with geotiff to shape transformation"); return; } @@ -264,12 +288,13 @@ namespace FarmmapsNbs } + // Functions to save previously created cropfields - private void LoadSettings() + private void LoadSettings(string file) { - if (File.Exists(SettingsFile)) + if (File.Exists(file)) { - var jsonText = File.ReadAllText(SettingsFile); + var jsonText = File.ReadAllText(file); _settings = JsonConvert.DeserializeObject(jsonText); } else @@ -278,13 +303,22 @@ namespace FarmmapsNbs } } - 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); } - } -} \ No newline at end of file + private void SaveInfo(string file) { + if (_settings == null) + return; + + var json = JsonConvert.SerializeObject(_settings); + File.WriteAllText(file, json); + + } + + } + } \ No newline at end of file diff --git a/FarmmapsPoten/PotenApplication.cs b/FarmmapsPoten/PotenApplication.cs index 0e961ed..42a4ac3 100644 --- a/FarmmapsPoten/PotenApplication.cs +++ b/FarmmapsPoten/PotenApplication.cs @@ -14,9 +14,7 @@ using static FarmmapsApiSamples.Constants; namespace FarmmapsVRApoten { - public class PotenApplication : IApplication - - { + public class PotenApplication : IApplication { private const string DownloadFolder = "Downloads"; private readonly ILogger _logger; @@ -26,16 +24,14 @@ namespace FarmmapsVRApoten public PotenApplication(ILogger logger, FarmmapsApiService farmmapsApiService, - GeneralService generalService, PotenService potenService) - { + GeneralService generalService, PotenService potenService) { _logger = logger; _farmmapsApiService = farmmapsApiService; _generalService = generalService; _potenService = potenService; } - public async Task RunAsync() - { + public async Task RunAsync() { // read field data from separate json file var VRAPotenInputJson = File.ReadAllText("PotenInput.json"); List potenInputs = JsonConvert.DeserializeObject>(VRAPotenInputJson); @@ -48,36 +44,29 @@ namespace FarmmapsVRApoten await _farmmapsApiService.GetCurrentUserCodeAsync(); var roots = await _farmmapsApiService.GetCurrentUserRootsAsync(); - foreach (var input in potenInputs) - { - try - { + foreach (var input in potenInputs) { + try { await Process(roots, input); - } - catch (Exception ex) - { + } catch (Exception ex) { _logger.LogError(ex.Message); } } } - private async Task Process(List roots, PotenInput input) - { + private async Task Process(List roots, PotenInput input) { var meanDensity = input.MeanDensity; var variation = input.Variation; var fieldName = input.FieldName; bool useShadow = input.UseShadow; var myDrive = roots.SingleOrDefault(r => r.Name == "My drive"); - if (myDrive == null) - { + if (myDrive == null) { _logger.LogError("Could not find a needed root item"); return; } var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded"); - if (uploadedRoot == null) - { + if (uploadedRoot == null) { _logger.LogError("Could not find a needed root item"); return; } @@ -89,12 +78,10 @@ namespace FarmmapsVRApoten input.GeometryJson.ToString(Formatting.None)); //Calculating shadow map - if (useShadow) - { + if (useShadow) { _logger.LogInformation("Calculate shadow map for field"); var shadowItem = await _generalService.RunShadowTask(cropfieldItem); - if (shadowItem == null) - { + if (shadowItem == null) { _logger.LogError("Something went wrong while obtaining the shadow map"); return; } @@ -104,21 +91,30 @@ 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; - var geotiffItem = (Item) null; + var geotiffItem = (Item)null; - if (String.IsNullOrEmpty(localDataAvailable)) - { + if (String.IsNullOrEmpty(localDataAvailable)) { _logger.LogInformation("Could not find item for uploaded data, using BOFEK"); //Retreiving BOFEK _logger.LogInformation("Get BOFEK for field"); var bofekItem = await _generalService.RunBofekTask(cropfieldItem); - if (bofekItem == null) - { + if (bofekItem == null) { _logger.LogError("Something went wrong while obtaining the BOFEK data"); return; } @@ -126,10 +122,7 @@ namespace FarmmapsVRApoten _logger.LogInformation("Downloading Bofek map"); await _farmmapsApiService.DownloadItemAsync(bofekItem.Code, Path.Combine(DownloadFolder, $"{input.OutputFileName}.BOFEK.zip")); - } - - - else if (input.File.Contains(".tif") || input.File.Contains(".geotiff")) { + } else if (input.File.Contains(".tif") || input.File.Contains(".geotiff")) { _logger.LogInformation("input = tiff data"); var dataPath = Path.Combine("Data", input.File); geotiffItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE, dataPath, @@ -139,10 +132,7 @@ namespace FarmmapsVRApoten _logger.LogError("Could not find item for uploaded data"); return; } - } - - else - { + } else { var isGeoJson = input.File.Contains("json"); var dataPath = Path.Combine("Data", input.File); var shapeItem = isGeoJson @@ -151,8 +141,7 @@ namespace FarmmapsVRApoten : await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.File)); - if (shapeItem == null) - { + if (shapeItem == null) { _logger.LogError("Something went wrong while searching for the shape file"); return; } @@ -161,8 +150,7 @@ namespace FarmmapsVRApoten _logger.LogInformation($"Converting shape to geotiff"); geotiffItem = await _generalService.ShapeToGeotiff(shapeItem); - if (geotiffItem == null) - { + if (geotiffItem == null) { _logger.LogError("Something went wrong with shape to geotiff transformation"); return; } @@ -179,8 +167,7 @@ namespace FarmmapsVRApoten var applianceMapItem = await _potenService.CalculateApplicationMapAsync(cropfieldItem, geotiffItem, meanDensity, variation); - if (applianceMapItem == null) - { + if (applianceMapItem == null) { return; } @@ -195,8 +182,7 @@ namespace FarmmapsVRApoten _logger.LogInformation($"Converting geotiff to shape"); var taskmap = await _generalService.GeotiffToShape(applianceMapItem); - if (taskmap == null) - { + if (taskmap == null) { _logger.LogError("Something went wrong with geotiff to shape transformation"); return; } diff --git a/FarmmapsZonering/Models/Settings.cs b/FarmmapsZonering/Models/Settings.cs index c3beb90..8644922 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 SatelliteTaskCode { get; set; } + public string VanDerSatTaskCode { get; set; } + public string WatBalTaskCode { get; set; } } } \ No newline at end of file diff --git a/FarmmapsZonering/Models/ZoneringInput.cs b/FarmmapsZonering/Models/ZoneringInput.cs index 7ac072b..26f8414 100644 --- a/FarmmapsZonering/Models/ZoneringInput.cs +++ b/FarmmapsZonering/Models/ZoneringInput.cs @@ -4,11 +4,13 @@ using Newtonsoft.Json.Linq; namespace FarmmapsZonering { public class ZoneringInput { public bool UseShadow { get; set; } - public string File { get; set; } public string OutputFileName { get; set; } - public string FieldName { get; set; } + public string fieldName { get; set; } public JObject GeometryJson { get; set; } + public bool GetWatBal { get; set; } + public bool GetVanDerSat { get; set; } + public bool storeVanDerSatStatistics { get; set; } } } \ No newline at end of file diff --git a/FarmmapsZonering/Services/ZoneringService.cs b/FarmmapsZonering/Services/ZoneringService.cs index d736240..d45564f 100644 --- a/FarmmapsZonering/Services/ZoneringService.cs +++ b/FarmmapsZonering/Services/ZoneringService.cs @@ -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"); diff --git a/FarmmapsZonering/ZoneringApplication.cs b/FarmmapsZonering/ZoneringApplication.cs index 27ace6f..9d3f0b4 100644 --- a/FarmmapsZonering/ZoneringApplication.cs +++ b/FarmmapsZonering/ZoneringApplication.cs @@ -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 zoneringInputs = JsonConvert.DeserializeObject>(zoneringInputJson); @@ -76,6 +73,16 @@ namespace FarmmapsZonering return; } + bool useCreatedCropfield = true; + bool GetWatBal = input.GetWatBal; + bool getVanDerSat = true;// input.GetVanDerSat; + bool StoreVanDerSatStatistics = true;// input.storeVanDerSatStatistics; + var FieldName = input.fieldName; + string settingsfile = $"Settings_{FieldName}.json"; + + // Load settings from previous cropfield + LoadSettings(settingsfile); + var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded"); if (uploadedRoot == null) { @@ -91,38 +98,85 @@ namespace FarmmapsZonering //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, "Perceel mestsilo", 2020, + @"{ ""type"": ""Polygon"", ""coordinates"": [ [ [ 6.48270347, 53.25953201 ], [ 6.48257178, 53.25858122 ], [ 6.48781397, 53.25797859 ], [ 6.48793320, 53.25928036 ], [ 6.48270347, 53.25953201 ] ] ] }"); _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(); + } 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", "data_9001.tif"),"data_9001"); + + 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", "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, + + 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; } - var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, "if [0] >= 1.28 then [1] else 0", new Output() + //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 + + //if ([0] -[1])/ ([0] +[1]) < 0 then 0 + //else if ([0] -[1])/ ([0] +[1]) > 1 then 1 + //else ([0] -[1]) / ([0] +[1]) + + var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, "[0] >= 1.28 then [1] else 0", new Output() + { - Name = "Remove", - Unit = "m&m", - Quantity = "Nonsense" + Name = "Test", + Unit = "index", + Quantity = "kg" }, new InputParameter() { ItemCode = inputOneItem.Code, @@ -130,35 +184,38 @@ 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"); await _farmmapsApiService.DownloadItemAsync(outputItem.Code, - Path.Combine(DownloadFolder, $"NonsenseRemove.zip")); + Path.Combine(DownloadFolder, $"Test.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(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); + } } - } } \ No newline at end of file diff --git a/FarmmapsZonering/ZoneringInput.json b/FarmmapsZonering/ZoneringInput.json index f3ac9f6..33960da 100644 --- a/FarmmapsZonering/ZoneringInput.json +++ b/FarmmapsZonering/ZoneringInput.json @@ -4,6 +4,9 @@ "OutputFileName": "Zoning", "FieldName": "Data_whole", "UseShadow": false, + "GetWatBal": true, + "GetVanDerSat": true, + "storeVanDerSatStatistics": true, "geometryJson": { "type": "Polygon", "coordinates": [