Veranderingen jits, fedde en pepijn. #9
@ -107,26 +107,27 @@ namespace FarmmapsApi.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create taskmap based on width, height and direction
|
// 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 };
|
var taskmapRequest = new TaskRequest { TaskType = TASKMAP_TASK };
|
||||||
taskmapRequest.attributes["inputCode"] = tiffItem.Code;
|
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["cellWidth"] = cellWidth; //metres
|
||||||
taskmapRequest.attributes["cellHeight"] = cellHeight; //metres
|
taskmapRequest.attributes["cellHeight"] = cellHeight; //metres
|
||||||
taskmapRequest.attributes["startPoint"] = startPoint; // Coordinates WGS84
|
taskmapRequest.attributes["startPoint"] = startPoint; // Coordinates WGS84
|
||||||
if (angle == null) taskmapRequest.attributes["endPoint"] = endPoint; // 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
|
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) => {
|
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}");
|
_logger.LogInformation($"Waiting on conversion to Taskmap; status: {itemTaskStatus.State}");
|
||||||
if (itemTaskStatus.IsFinished)
|
if (itemTaskStatus.IsFinished)
|
||||||
tokenSource.Cancel();
|
tokenSource.Cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(tiffItem.Code, itemTaskCode);
|
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}");
|
_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 class NitrogenInput
|
||||||
{
|
{
|
||||||
|
public bool UseCreatedCropfield { get; set; }
|
||||||
public string File { get; set; }
|
public string File { get; set; }
|
||||||
public string InputVariable { get; set; }
|
public string InputVariable { get; set; }
|
||||||
public string OutputFileName { get; set; }
|
public string OutputFileName { get; set; }
|
||||||
@ -16,6 +17,12 @@ namespace FarmmapsNbs.Models
|
|||||||
public string InputLayerName { get; set; }
|
public string InputLayerName { get; set; }
|
||||||
public string fieldName{ get; set; }
|
public string fieldName{ get; set; }
|
||||||
public bool storeSatelliteStatistics { 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()
|
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);
|
List<NitrogenInput> nitrogenInputs = JsonConvert.DeserializeObject<List<NitrogenInput>>(nitrogenInputJson);
|
||||||
|
|
||||||
if (!Directory.Exists(DownloadFolder))
|
if (!Directory.Exists(DownloadFolder))
|
||||||
@ -64,7 +64,7 @@ namespace FarmmapsNbs
|
|||||||
{
|
{
|
||||||
|
|
||||||
// !!specify if you are using an already created cropfield:
|
// !!specify if you are using an already created cropfield:
|
||||||
bool useCreatedCropfield = true;
|
bool useCreatedCropfield = input. UseCreatedCropfield;
|
||||||
var plantingDate = input.PlantingDate;
|
var plantingDate = input.PlantingDate;
|
||||||
var FieldName = input.fieldName;
|
var FieldName = input.fieldName;
|
||||||
bool StoreStatistics = input.storeSatelliteStatistics;
|
bool StoreStatistics = input.storeSatelliteStatistics;
|
||||||
@ -274,13 +274,25 @@ namespace FarmmapsNbs
|
|||||||
_logger.LogError("Could not find item for uploaded data");
|
_logger.LogError("Could not find item for uploaded data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"Converting geotiff to shape");
|
|
||||||
var taskmap = await _generalService.GeotiffToShape(tiffItem);
|
//_logger.LogInformation($"Converting geotiff to shape");
|
||||||
if (taskmap == null) {
|
//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");
|
_logger.LogError("Something went wrong with geotiff to shape transformation");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_logger.LogInformation("Downloading taskmap");
|
_logger.LogInformation("Downloading taskmap");
|
||||||
await _farmmapsApiService.DownloadItemAsync(taskmap.Code,
|
await _farmmapsApiService.DownloadItemAsync(taskmap.Code,
|
||||||
Path.Combine(DownloadFolder, $"{input.OutputFileName}.taskmap.zip"));
|
Path.Combine(DownloadFolder, $"{input.OutputFileName}.taskmap.zip"));
|
||||||
|
Binary file not shown.
@ -23,5 +23,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\FarmmapsApi\FarmmapsApi.csproj" />
|
<ProjectReference Include="..\FarmmapsApi\FarmmapsApi.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Data" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -49,13 +49,11 @@ namespace FarmmapsZonering.Services
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemName = $"VRAZonering";
|
|
||||||
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code,
|
||||||
GEOTIFF_PROCESSED_ITEMTYPE, itemName,
|
GEOTIFF_PROCESSED_ITEMTYPE, output.Name,
|
||||||
//i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) &&
|
i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) &&
|
||||||
// i.Name.ToLower().Contains(itemName.ToLower()));
|
i.Name.ToLower().Contains(output.Name.ToLower()));
|
||||||
i =>
|
|
||||||
i.Name.ToLower().Contains(itemName.ToLower()));
|
|
||||||
if (applianceMapItem == null)
|
if (applianceMapItem == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("Could not find the VRAZonering geotiff child item under cropfield");
|
_logger.LogError("Could not find the VRAZonering geotiff child item under cropfield");
|
||||||
|
@ -73,7 +73,7 @@ namespace FarmmapsZonering
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool useCreatedCropfield = true;
|
bool useCreatedCropfield = false;
|
||||||
bool GetWatBal = input.GetWatBal;
|
bool GetWatBal = input.GetWatBal;
|
||||||
bool getVanDerSat = input.GetVanDerSat;
|
bool getVanDerSat = input.GetVanDerSat;
|
||||||
bool StoreVanDerSatStatistics = input.storeVanDerSatStatistics;
|
bool StoreVanDerSatStatistics = input.storeVanDerSatStatistics;
|
||||||
@ -91,7 +91,7 @@ namespace FarmmapsZonering
|
|||||||
}
|
}
|
||||||
|
|
||||||
Item cropfieldItem;
|
Item cropfieldItem;
|
||||||
if (string.IsNullOrEmpty(_settings.CropfieldItemCode) || input.CreateNewCropfield == true)
|
if (input.CreateNewCropfield == true) // || string.IsNullOrEmpty(_settings.CropfieldItemCode) ## CHECK IT!!
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Creating cropfield");
|
_logger.LogInformation("Creating cropfield");
|
||||||
|
|
||||||
@ -103,8 +103,8 @@ namespace FarmmapsZonering
|
|||||||
_settings.CropfieldItemCode = cropfieldItem.Code;
|
_settings.CropfieldItemCode = cropfieldItem.Code;
|
||||||
SaveSettings(settingsfile);
|
SaveSettings(settingsfile);
|
||||||
|
|
||||||
cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, "Cropfield VRA Zonering", 2020,
|
//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 ] ] ] }");
|
// @"{ ""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;
|
_settings.CropfieldItemCode = cropfieldItem.Code;
|
||||||
SaveSettings(settingsfile);
|
SaveSettings(settingsfile);
|
||||||
}
|
}
|
||||||
@ -147,19 +147,24 @@ namespace FarmmapsZonering
|
|||||||
var inputOneItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
|
var inputOneItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
|
||||||
Path.Combine("Data", $"{input.InputItemOne}"), Path.GetFileNameWithoutExtension($"{input.InputItemOne}"));
|
Path.Combine("Data", $"{input.InputItemOne}"), Path.GetFileNameWithoutExtension($"{input.InputItemOne}"));
|
||||||
|
|
||||||
if (inputOneItem == null) {
|
if (inputOneItem == null)
|
||||||
|
{
|
||||||
_logger.LogError("Could not find item for uploaded data");
|
_logger.LogError("Could not find item for uploaded data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var inputTwoItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
|
//var inputTwoItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE,
|
||||||
Path.Combine("Data", $"{input.InputItemTwo}"), Path.GetFileNameWithoutExtension($"{input.InputItemTwo}"));
|
// Path.Combine("Data", $"{input.InputItemTwo}"), Path.GetFileNameWithoutExtension($"{input.InputItemTwo}"));
|
||||||
|
|
||||||
if (inputTwoItem == null) {
|
//if (inputTwoItem == null)
|
||||||
_logger.LogError("Could not find item for uploaded data");
|
//{
|
||||||
return;
|
// _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()
|
var outputItem = await _zoneringService.CreateApplicationMapAsync(cropfieldItem, input.Formula, new Output()
|
||||||
{
|
{
|
||||||
@ -172,12 +177,14 @@ namespace FarmmapsZonering
|
|||||||
{
|
{
|
||||||
ItemCode = inputOneItem.Code,
|
ItemCode = inputOneItem.Code,
|
||||||
LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
||||||
},
|
}
|
||||||
new InputParameter()
|
//,
|
||||||
{
|
//new InputParameter()
|
||||||
ItemCode = inputOneItem.Code,
|
//{
|
||||||
LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
// //ItemCode = inputOneItem.Code,
|
||||||
});
|
// //LayerName = inputOneItem.Data["layers"][0]["name"].ToString()
|
||||||
|
//}
|
||||||
|
);;
|
||||||
|
|
||||||
_logger.LogInformation("Downloading output");
|
_logger.LogInformation("Downloading output");
|
||||||
|
|
||||||
|
@ -38,20 +38,50 @@
|
|||||||
// ]
|
// ]
|
||||||
|
|
||||||
// ]
|
// ]
|
||||||
|
// }
|
||||||
|
//,
|
||||||
|
//{
|
||||||
|
// "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": "data_9001.tif",
|
"InputItemOne": "VRApoten_appliancemap_20210215_vraPoten_SampleData_CovertArea.tif",
|
||||||
"InputItemTwo": "data_times_two_4326.tiff",
|
//"InputItemTwo": "",
|
||||||
"Formula": "if [0] >= 1.28 then [1] else 0",
|
"Formula": "((100/[0])/0.75)",
|
||||||
"CreatedLayerName": "Biomassa",
|
"LayerName": "CountPerAreaConversion",
|
||||||
"CalculatedQuantity": "NDVI",
|
"CalculatedQuantity": "CountPerArea",
|
||||||
"CalculatedUnit": "ndviValue",
|
"CalculatedUnit": "#/m2",
|
||||||
"OutputFileName": "Zoning",
|
"OutputFileName": "CountPerAreaConversionOutput",
|
||||||
"CropFieldName": "Data_whole",
|
"CropFieldName": "ZoningCpA",
|
||||||
|
"CreateNewCropfield": true,
|
||||||
"UseShadow": false,
|
"UseShadow": false,
|
||||||
"GetWatBal": false,
|
"GetWatBal": false,
|
||||||
"GetVanDerSat": true,
|
"GetVanDerSat": false,
|
||||||
"storeVanDerSatStatistics": true,
|
"storeVanDerSatStatistics": false,
|
||||||
"CropYear": 2020,
|
"CropYear": 2020,
|
||||||
"geometryJson": {
|
"geometryJson": {
|
||||||
"type": "Polygon",
|
"type": "Polygon",
|
||||||
|
Loading…
Reference in New Issue
Block a user