Update zonering to find the right output files
Added taskmap creator to NBS
This commit is contained in:
parent
c02b232837
commit
101b683daa
@ -107,26 +107,27 @@ namespace FarmmapsApi.Services
|
||||
}
|
||||
|
||||
// Create taskmap based on width, height and direction
|
||||
public async Task<Item> CreateTaskmap(Item tiffItem, string cellWidth, string cellHeight, string startPoint, string endPoint = null, string angle = null)
|
||||
public async Task<Item> CreateTaskmap(Item cropfieldItem, Item tiffItem, string cellWidth, string cellHeight, string startPoint, string endPoint = null, string angle = null)
|
||||
{
|
||||
var taskmapRequest = new TaskRequest { TaskType = TASKMAP_TASK };
|
||||
taskmapRequest.attributes["inputCode"] = tiffItem.Code;
|
||||
taskmapRequest.attributes["operation"] = "shape"; // Currently onlye "shape" supported, if ISOXML is supported this should be an input
|
||||
taskmapRequest.attributes["cellWidth"] = cellWidth; //metres
|
||||
taskmapRequest.attributes["cellHeight"] = cellHeight; //metres
|
||||
taskmapRequest.attributes["startPoint"] = startPoint; // Coordinates WGS84
|
||||
if (angle == null) taskmapRequest.attributes["endPoint"] = endPoint; // Coordinates WGS84
|
||||
if (endPoint == null) taskmapRequest.attributes["angle"] = angle; // degrees between 0.0 and 360.0
|
||||
|
||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(tiffItem.Code, taskmapRequest);
|
||||
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest);
|
||||
|
||||
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => {
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(tiffItem.Code, itemTaskCode);
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
|
||||
_logger.LogInformation($"Waiting on conversion to Taskmap; status: {itemTaskStatus.State}");
|
||||
if (itemTaskStatus.IsFinished)
|
||||
tokenSource.Cancel();
|
||||
});
|
||||
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(tiffItem.Code, itemTaskCode);
|
||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
|
||||
if (itemTask.State == ItemTaskState.Error)
|
||||
{
|
||||
_logger.LogError($"Something went wrong with task execution: {itemTask.Message}");
|
||||
|
40
FarmmapsNbs/InputData-NBS.json
Normal file
40
FarmmapsNbs/InputData-NBS.json
Normal file
@ -0,0 +1,40 @@
|
||||
[
|
||||
{
|
||||
"UseCreatedCropfield": false,
|
||||
"storeStatistics": false,
|
||||
"file": "20210127_WDVI_plus03.tif",
|
||||
"inputVariable": "wdvi",
|
||||
//"InputLayerName": "Band 1",
|
||||
"outputFileName": "2021.02.15.Hapreet_Singh_0127-wdvi03_2",
|
||||
"plantingDate": "2020-04-15",
|
||||
"measurementDate": "2020-06-27",
|
||||
"potatoPurposeType": "consumption",
|
||||
"targetYield": 27,
|
||||
"fieldName": "Mahindra-Hapreet-Singh",
|
||||
"geometryJson": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[ 75.929090780177305, 31.639314978348551 ],
|
||||
[ 75.931353489378182, 31.639409065494881 ],
|
||||
[ 75.931432810729120, 31.638956841735819 ],
|
||||
[ 75.929072617175663, 31.638879365370279 ],
|
||||
[ 75.929090780177305, 31.639314978348551 ]
|
||||
]
|
||||
]
|
||||
},
|
||||
"GenerateTaskmap": true,
|
||||
"CellWidth": "3",
|
||||
"CellHeight": "10",
|
||||
"StartPoint": {
|
||||
"type": "Point",
|
||||
"coordinates": [ 75.931432810729120, 31.638956841735819 ]
|
||||
},
|
||||
"EndPoint": {
|
||||
"type": "Point",
|
||||
"coordinates": [ 75.929072617175663, 31.638879365370279 ]
|
||||
} // if no angle
|
||||
|
||||
//"Angle": "317.0" // if no endpoint
|
||||
}
|
||||
]
|
@ -5,6 +5,7 @@ namespace FarmmapsNbs.Models
|
||||
{
|
||||
public class NitrogenInput
|
||||
{
|
||||
public bool UseCreatedCropfield { get; set; }
|
||||
public string File { get; set; }
|
||||
public string InputVariable { get; set; }
|
||||
public string OutputFileName { get; set; }
|
||||
@ -16,6 +17,12 @@ namespace FarmmapsNbs.Models
|
||||
public string InputLayerName { get; set; }
|
||||
public string fieldName{ get; set; }
|
||||
public bool storeSatelliteStatistics { get; set; }
|
||||
public bool GenerateTaskmap { get; set; }
|
||||
public string CellWidth { get; set; }
|
||||
public string CellHeight { get; set; }
|
||||
public JObject StartPoint { get; set; }
|
||||
public JObject EndPoint { get; set; }
|
||||
public string Angle { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace FarmmapsNbs
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
var nitrogenInputJson = File.ReadAllText("NitrogenInput.json");
|
||||
var nitrogenInputJson = File.ReadAllText("InputData-NBS.json"); //NitrogenInput.json
|
||||
List<NitrogenInput> nitrogenInputs = JsonConvert.DeserializeObject<List<NitrogenInput>>(nitrogenInputJson);
|
||||
|
||||
if (!Directory.Exists(DownloadFolder))
|
||||
@ -64,7 +64,7 @@ namespace FarmmapsNbs
|
||||
{
|
||||
|
||||
// !!specify if you are using an already created cropfield:
|
||||
bool useCreatedCropfield = true;
|
||||
bool useCreatedCropfield = input. UseCreatedCropfield;
|
||||
var plantingDate = input.PlantingDate;
|
||||
var FieldName = input.fieldName;
|
||||
bool StoreStatistics = input.storeSatelliteStatistics;
|
||||
@ -274,13 +274,25 @@ namespace FarmmapsNbs
|
||||
_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) {
|
||||
|
||||
//_logger.LogInformation($"Converting geotiff to shape");
|
||||
//var taskmap = await _generalService.GeotiffToShape(tiffItem);
|
||||
//if (taskmap == null) {
|
||||
// _logger.LogError("Something went wrong with geotiff to shape transformation");
|
||||
// return;
|
||||
//}
|
||||
|
||||
//ApplicationMap (GEOTIFF) To Taskmap
|
||||
_logger.LogInformation($"Converting geotiff to taskmap");
|
||||
var taskmap = await _generalService.CreateTaskmap(cropfieldItem, tiffItem, input.CellWidth, input.CellHeight, input.StartPoint.ToString(Formatting.None),
|
||||
input.EndPoint.ToString(Formatting.None), input.Angle);
|
||||
if (taskmap == null)
|
||||
{
|
||||
_logger.LogError("Something went wrong with geotiff to shape transformation");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_logger.LogInformation("Downloading taskmap");
|
||||
await _farmmapsApiService.DownloadItemAsync(taskmap.Code,
|
||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.taskmap.zip"));
|
||||
|
Binary file not shown.
@ -23,5 +23,9 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FarmmapsApi\FarmmapsApi.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Data" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
@ -49,13 +49,11 @@ namespace FarmmapsZonering.Services
|
||||
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()));
|
||||
i =>
|
||||
i.Name.ToLower().Contains(itemName.ToLower()));
|
||||
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
||||
GEOTIFF_PROCESSED_ITEMTYPE, output.Name,
|
||||
i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) &&
|
||||
i.Name.ToLower().Contains(output.Name.ToLower()));
|
||||
|
||||
if (applianceMapItem == null)
|
||||
{
|
||||
_logger.LogError("Could not find the VRAZonering geotiff child item under cropfield");
|
||||
|
@ -73,7 +73,7 @@ namespace FarmmapsZonering
|
||||
return;
|
||||
}
|
||||
|
||||
bool useCreatedCropfield = true;
|
||||
bool useCreatedCropfield = false;
|
||||
bool GetWatBal = input.GetWatBal;
|
||||
bool getVanDerSat = input.GetVanDerSat;
|
||||
bool StoreVanDerSatStatistics = input.storeVanDerSatStatistics;
|
||||
@ -91,7 +91,7 @@ namespace FarmmapsZonering
|
||||
}
|
||||
|
||||
Item cropfieldItem;
|
||||
if (string.IsNullOrEmpty(_settings.CropfieldItemCode) || input.CreateNewCropfield == true)
|
||||
if (input.CreateNewCropfield == true) // || string.IsNullOrEmpty(_settings.CropfieldItemCode) ## CHECK IT!!
|
||||
{
|
||||
_logger.LogInformation("Creating cropfield");
|
||||
|
||||
@ -103,8 +103,8 @@ namespace FarmmapsZonering
|
||||
_settings.CropfieldItemCode = cropfieldItem.Code;
|
||||
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 ] ] ] }");
|
||||
//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);
|
||||
}
|
||||
@ -147,19 +147,24 @@ namespace FarmmapsZonering
|
||||
var inputOneItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
|
||||
Path.Combine("Data", $"{input.InputItemOne}"), Path.GetFileNameWithoutExtension($"{input.InputItemOne}"));
|
||||
|
||||
if (inputOneItem == null) {
|
||||
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;
|
||||
}
|
||||
//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 inputOneItem = input.InputItemOne;
|
||||
//var inputTwoItem = input.InputItemTwo;
|
||||
|
||||
var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, input.Formula, new Output()
|
||||
{
|
||||
@ -172,12 +177,14 @@ namespace FarmmapsZonering
|
||||
{
|
||||
ItemCode = inputOneItem.Code,
|
||||
LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
||||
},
|
||||
new InputParameter()
|
||||
{
|
||||
ItemCode = inputOneItem.Code,
|
||||
LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
||||
});
|
||||
}
|
||||
//,
|
||||
//new InputParameter()
|
||||
//{
|
||||
// //ItemCode = inputOneItem.Code,
|
||||
// //LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
||||
//}
|
||||
);;
|
||||
|
||||
_logger.LogInformation("Downloading output");
|
||||
|
||||
|
@ -1,71 +1,101 @@
|
||||
[
|
||||
|
||||
//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
|
||||
//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])
|
||||
//if ([0] -[1])/ ([0] +[1]) < 0 then 0
|
||||
//else if ([0] -[1])/ ([0] +[1]) > 1 then 1
|
||||
//else ([0] -[1]) / ([0] +[1])
|
||||
|
||||
//{
|
||||
// "InputItemOne": "20201106_Sentinel2_L2A_B04.tiff",
|
||||
// "InputItemTwo": "20201106_Sentinel2_L2A_B08.tiff",
|
||||
// "Formula": "([1]-[0])/([1]+[0])",
|
||||
// "CreatedLayerName": "Biomassa",
|
||||
// "CalculatedQuantity": "NDVI",
|
||||
// "CalculatedUnit": "ndviValue",
|
||||
//{
|
||||
// "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": [
|
||||
// "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 ]
|
||||
// ]
|
||||
// [
|
||||
// [ 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": "if [0] >= 1.28 then [1] else 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 ]
|
||||
]
|
||||
]
|
||||
// ]
|
||||
// }
|
||||
//,
|
||||
//{
|
||||
// "InputItemOne": "data_9001.tif",
|
||||
// "InputItemTwo": "data_times_two_4326.tiff",
|
||||
// "Formula": "if [0] >= 1.28 then [1] else 0",
|
||||
// "CreatedLayerName": "Biomassa",
|
||||
// "CalculatedQuantity": "NDVI",
|
||||
// "CalculatedUnit": "ndviValue",
|
||||
// "OutputFileName": "Zoning",
|
||||
// "CropFieldName": "Data_whole",
|
||||
// "UseShadow": false,
|
||||
// "GetWatBal": false,
|
||||
// "GetVanDerSat": false,
|
||||
// "storeVanDerSatStatistics": 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 ]
|
||||
// ]
|
||||
// ]
|
||||
|
||||
// }
|
||||
//},
|
||||
{
|
||||
"InputItemOne": "VRApoten_appliancemap_20210215_vraPoten_SampleData_CovertArea.tif",
|
||||
//"InputItemTwo": "",
|
||||
"Formula": "((100/[0])/0.75)",
|
||||
"LayerName": "CountPerAreaConversion",
|
||||
"CalculatedQuantity": "CountPerArea",
|
||||
"CalculatedUnit": "#/m2",
|
||||
"OutputFileName": "CountPerAreaConversionOutput",
|
||||
"CropFieldName": "ZoningCpA",
|
||||
"CreateNewCropfield": true,
|
||||
"UseShadow": false,
|
||||
"GetWatBal": false,
|
||||
"GetVanDerSat": false,
|
||||
"storeVanDerSatStatistics": 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 ]
|
||||
]
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user