fixed to store statistics of satellite images
This commit is contained in:
		| @@ -345,7 +345,7 @@ namespace FarmmapsApi.Services | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode, string FieldName, bool StoreStatistics) { | ||||
|         public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode) { | ||||
|  | ||||
|             var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode); | ||||
|  | ||||
| @@ -384,11 +384,6 @@ namespace FarmmapsApi.Services | ||||
|             } | ||||
|  | ||||
|             return selectedSatelliteItem; | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         } | ||||
|  | ||||
|         //VanDerSat | ||||
| @@ -416,32 +411,6 @@ namespace FarmmapsApi.Services | ||||
|  | ||||
|             return itemTask.Code; | ||||
|         } | ||||
|  | ||||
|         public async Task<string> 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<Item> FindVanDerSatItem(Item cropfieldItem, string VanDerSatTaskCode, string FieldName, bool StoreStatistics) { | ||||
|  | ||||
|             var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, VanDerSatTaskCode); | ||||
| @@ -478,7 +447,6 @@ namespace FarmmapsApi.Services | ||||
|                         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"); | ||||
| @@ -512,6 +480,32 @@ namespace FarmmapsApi.Services | ||||
|  | ||||
|  | ||||
|         } | ||||
|         public async Task<string> 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<Item> FindWatBalItem(Item cropfieldItem, string WatBalTaskCode, string FieldName, bool StoreStatistics) { | ||||
|  | ||||
| @@ -519,10 +513,8 @@ namespace FarmmapsApi.Services | ||||
|  | ||||
|  | ||||
|             // 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)); | ||||
|  | ||||
|             var temporalItem = await FindChildItemAsync(cropfieldItem.Code, TEMPORAL_ITEMTYPE, "Watbal", | ||||
|                 item => item.SourceTask == WATBAL_TASK && taskStatus.Finished >= item.Created && taskStatus.Finished <= item.Created.Value.AddHours(1)); | ||||
|  | ||||
|             if (temporalItem == null) { | ||||
|                 _logger.LogError("Temporal item not found"); | ||||
|   | ||||
| @@ -120,7 +120,7 @@ namespace FarmmapsNbs | ||||
|  | ||||
|  | ||||
|                 // Select a particular satellite item from satelliteTask | ||||
|                 Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode, FieldName, StoreStatistics); | ||||
|                 Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode); | ||||
|  | ||||
|                 var satelliteBand = satalliteItem.Data["layers"][0]["name"]; | ||||
|                 var satelliteStatistics = satalliteItem.Data["layers"][0]["renderer"]["band"]["statistics"]; | ||||
| @@ -130,22 +130,19 @@ namespace FarmmapsNbs | ||||
|                 //Store data to csv  | ||||
|                 if (StoreStatistics == true) | ||||
|                 { | ||||
|                     var SatelliteFile = $"\\Downloads\\DataSatellite_{FieldName}.csv"; | ||||
|                     var NewLineField = $"\"Field\":{FieldName}" + Environment.NewLine; | ||||
|                     var NewLineDate = $"\"date\":{satalliteItem.DataDate}" + Environment.NewLine; | ||||
|                     var i = 0; | ||||
|  | ||||
|                     var SatelliteStatsFile = $"{DownloadFolder}/SatelliteDataStatistics_{FieldName}_{satalliteItem.DataDate.Value:d}.csv"; | ||||
|                     using var w = new StreamWriter(SatelliteStatsFile); | ||||
|                     { | ||||
|                         foreach (var item in satelliteStatistics) | ||||
|                         { | ||||
|                         //var NewLines2; | ||||
|                         if (i == 0) | ||||
|                         { | ||||
|                             File.AppendAllText(SatelliteFile, NewLineDate); | ||||
|                             i++; | ||||
|                             var line = string.Format("{0}", item); | ||||
|                             w.WriteLine(line); | ||||
|                             w.Flush(); | ||||
|                         } | ||||
|                     } | ||||
|                         File.AppendAllText(SatelliteFile, $"{item}" + Environment.NewLine); | ||||
|  | ||||
|                 } | ||||
|                 } | ||||
|  | ||||
|  | ||||
|                 // must be wdvi[1] | ||||
| @@ -216,22 +213,6 @@ 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, | ||||
|   | ||||
| @@ -1,83 +1,42 @@ | ||||
| [ | ||||
|     { | ||||
|         "file": "Scan_1_20190605.json", | ||||
|         "inputVariable": "irmi", | ||||
|         "inputLayerName": "", | ||||
|         "outputFileName": "vranbs1", | ||||
|         "plantingDate": "2019-04-18", | ||||
|         "measurementDate": "2019-06-05", | ||||
|         "potatoPurposeType": "consumption", | ||||
|         "targetYield": 45, | ||||
|         "geometryJson": { | ||||
|             "type": "Polygon", | ||||
|             "coordinates": [ | ||||
|                 [ | ||||
|                     [ 3.40843828875524, 50.638966444680605 ], | ||||
|                     [ 3.408953272886064, 50.639197789621612 ], | ||||
|                     [ 3.409242951459603, 50.639469958681836 ], | ||||
|                     [ 3.409328782148028, 50.639612846807708 ], | ||||
|                     [ 3.409457528180712, 50.639789755314411 ], | ||||
|                     [ 3.409639918393741, 50.640014292074966 ], | ||||
|                     [ 3.409833037442765, 50.640211611372706 ], | ||||
|                     [ 3.410069071836049, 50.640395321698435 ], | ||||
|                     [ 3.410380208081761, 50.640572227259661 ], | ||||
|                     [ 3.410605513638958, 50.640715112034222 ], | ||||
|                     [ 3.411925160474145, 50.641177783561204 ], | ||||
|                     [ 3.411935889310142, 50.640728720085136 ], | ||||
|                     [ 3.412590348309737, 50.63948356709389 ], | ||||
|                     [ 3.413244807309242, 50.638224772339846 ], | ||||
|                     [ 3.413400375432099, 50.637901562841307 ], | ||||
|                     [ 3.413539850300779, 50.637449065809889 ], | ||||
|                     [ 3.413475477284437, 50.637418445552932 ], | ||||
|                     [ 3.40999396998362, 50.637449065810451 ], | ||||
|                     [ 3.409940325803365, 50.638102293212661 ], | ||||
|                     [ 3.409575545377398, 50.638483338338325 ], | ||||
|                     [ 3.409060561246574, 50.638707881340494 ], | ||||
|                     [ 3.40843828875524, 50.638966444680605 ] | ||||
|                 ] | ||||
|             ] | ||||
|         }, | ||||
|  | ||||
|         "GenerateTaskmap": true, | ||||
|         "OutputType": "shape", // "shape" or "isoxml" if isoxml also add ddiCode | ||||
|         "Precision": "2", | ||||
|         "MaximumClasses": "4", | ||||
|         "DdiCode": "0006", | ||||
|         "CellWidth": "3", | ||||
|         "CellHeight": "10", | ||||
|         "Centered": "true", | ||||
|         "StartPoint": { | ||||
|             "type": "Point", | ||||
|             "coordinates": [ 3.409341600000000, 50.638991900000001 ] | ||||
|         }, | ||||
|         "EndPoint": { // if no angle | ||||
|             "type": "Point", | ||||
|             "coordinates": [ 3.411897000000000, 50.638981500000000 ] | ||||
|         }  | ||||
|         //"Angle": "317.0" // if no endpoint | ||||
|  | ||||
|     }, | ||||
|  | ||||
|     //{ | ||||
|     //    "file": "", // keep emptpy to use satellite image | ||||
|     //    "inputVariable": "wdvi", | ||||
|     //    "InputLayerName": "wdvi", | ||||
|     //    "outputFileName": "rtest1", | ||||
|     //    "plantingDate": "2020-05-01", | ||||
|     //    "measurementDate": "2020-06-14", | ||||
|     //    "UseCreatedCropfield": true, | ||||
|     //    "file": "Scan_1_20190605.json", | ||||
|     //    "inputVariable": "irmi", | ||||
|     //    "inputLayerName": "", | ||||
|     //    "outputFileName": "vranbs1", | ||||
|     //    "fieldName": "testJson_irmi", | ||||
|     //    "storeSatelliteStatistics": true, | ||||
|     //    "plantingDate": "2019-04-18", | ||||
|     //    "measurementDate": "2019-06-05", | ||||
|     //    "potatoPurposeType": "consumption", | ||||
|     //    "targetYield": 60, | ||||
|     //    "targetYield": 45, | ||||
|     //    "geometryJson": { | ||||
|     //        "type": "Polygon", | ||||
|     //        "coordinates": [ | ||||
|     //            [ | ||||
|     //                [ 4.960707146896585, 52.800583669708487 ], | ||||
|     //                [ 4.960645975538824, 52.800470217610922 ], | ||||
|     //                [ 4.962140695752897, 52.799177147194797 ], | ||||
|     //                [ 4.967523821195745, 52.801502400041208 ], | ||||
|     //                [ 4.966336768950911, 52.802543735879809 ], | ||||
|     //                [ 4.961711880764330, 52.801009996856429 ], | ||||
|     //                [ 4.960707146896585, 52.800583669708487 ] | ||||
|     //                [ 3.40843828875524, 50.638966444680605 ], | ||||
|     //                [ 3.408953272886064, 50.639197789621612 ], | ||||
|     //                [ 3.409242951459603, 50.639469958681836 ], | ||||
|     //                [ 3.409328782148028, 50.639612846807708 ], | ||||
|     //                [ 3.409457528180712, 50.639789755314411 ], | ||||
|     //                [ 3.409639918393741, 50.640014292074966 ], | ||||
|     //                [ 3.409833037442765, 50.640211611372706 ], | ||||
|     //                [ 3.410069071836049, 50.640395321698435 ], | ||||
|     //                [ 3.410380208081761, 50.640572227259661 ], | ||||
|     //                [ 3.410605513638958, 50.640715112034222 ], | ||||
|     //                [ 3.411925160474145, 50.641177783561204 ], | ||||
|     //                [ 3.411935889310142, 50.640728720085136 ], | ||||
|     //                [ 3.412590348309737, 50.63948356709389 ], | ||||
|     //                [ 3.413244807309242, 50.638224772339846 ], | ||||
|     //                [ 3.413400375432099, 50.637901562841307 ], | ||||
|     //                [ 3.413539850300779, 50.637449065809889 ], | ||||
|     //                [ 3.413475477284437, 50.637418445552932 ], | ||||
|     //                [ 3.40999396998362, 50.637449065810451 ], | ||||
|     //                [ 3.409940325803365, 50.638102293212661 ], | ||||
|     //                [ 3.409575545377398, 50.638483338338325 ], | ||||
|     //                [ 3.409060561246574, 50.638707881340494 ], | ||||
|     //                [ 3.40843828875524, 50.638966444680605 ] | ||||
|     //            ] | ||||
|     //        ] | ||||
|     //    }, | ||||
| @@ -92,14 +51,61 @@ | ||||
|     //    "Centered": "true", | ||||
|     //    "StartPoint": { | ||||
|     //        "type": "Point", | ||||
|     //        "coordinates": [ 4.960707146896585, 52.800583669708487 ] | ||||
|     //        "coordinates": [ 3.409341600000000, 50.638991900000001 ] | ||||
|     //    }, | ||||
|     //    "EndPoint": { // if no angle | ||||
|     //        "type": "Point", | ||||
|     //        "coordinates": [ 4.961711880764330, 52.801009996856429 ] | ||||
|     //        "coordinates": [ 3.411897000000000, 50.638981500000000 ] | ||||
|     //    } | ||||
|     //    //"Angle": "317.0" // if no endpoint | ||||
|     //} | ||||
|  | ||||
|     //}, | ||||
|  | ||||
|     { | ||||
|         "UseCreatedCropfield": true, | ||||
|         "file": "", // keep emptpy to use satellite image | ||||
|         "inputVariable": "wdvi", | ||||
|         "InputLayerName": "wdvi", | ||||
|         "outputFileName": "rtest1", | ||||
|         "fieldName": "test_satelliteWDVI", | ||||
|         "storeSatelliteStatistics": true, | ||||
|         "plantingDate": "2020-05-01", | ||||
|         "measurementDate": "2020-06-14", | ||||
|         "potatoPurposeType": "consumption", | ||||
|         "targetYield": 60, | ||||
|         "geometryJson": { | ||||
|             "type": "Polygon", | ||||
|             "coordinates": [ | ||||
|                 [ | ||||
|                     [ 4.960707146896585, 52.800583669708487 ], | ||||
|                     [ 4.960645975538824, 52.800470217610922 ], | ||||
|                     [ 4.962140695752897, 52.799177147194797 ], | ||||
|                     [ 4.967523821195745, 52.801502400041208 ], | ||||
|                     [ 4.966336768950911, 52.802543735879809 ], | ||||
|                     [ 4.961711880764330, 52.801009996856429 ], | ||||
|                     [ 4.960707146896585, 52.800583669708487 ] | ||||
|                 ] | ||||
|             ] | ||||
|         }, | ||||
|  | ||||
|         "GenerateTaskmap": true, | ||||
|         "OutputType": "shape", // "shape" or "isoxml" if isoxml also add ddiCode | ||||
|         "Precision": "2", | ||||
|         "MaximumClasses": "4", | ||||
|         "DdiCode": "0006", | ||||
|         "CellWidth": "3", | ||||
|         "CellHeight": "10", | ||||
|         "Centered": "true", | ||||
|         "StartPoint": { | ||||
|             "type": "Point", | ||||
|             "coordinates": [ 4.960707146896585, 52.800583669708487 ] | ||||
|         }, | ||||
|         "EndPoint": { // if no angle | ||||
|             "type": "Point", | ||||
|             "coordinates": [ 4.961711880764330, 52.801009996856429 ] | ||||
|         } | ||||
|         //"Angle": "317.0" // if no endpoint | ||||
|     } | ||||
|      | ||||
|  | ||||
| ] | ||||
		Reference in New Issue
	
	Block a user