added field polygon to data upload

This commit is contained in:
Sijbrandij 2021-04-02 16:15:44 +02:00
parent b758913693
commit 760f3fad64
5 changed files with 16 additions and 11 deletions

View File

@ -283,7 +283,7 @@ namespace FarmmapsApi.Services
/// <param name="progressCallback"></param> /// <param name="progressCallback"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="FileNotFoundException"></exception> /// <exception cref="FileNotFoundException"></exception>
public async Task<UploadResults> UploadFile(string filePath, string parentItemCode, public async Task<UploadResults> UploadFile(string filePath, string parentItemCode, string geoJsonString,
Action<IUploadProgress> progressCallback = null) Action<IUploadProgress> progressCallback = null)
{ {
if (!File.Exists(filePath)) if (!File.Exists(filePath))
@ -300,7 +300,8 @@ namespace FarmmapsApi.Services
{ {
Name = Path.GetFileName(filePath), Name = Path.GetFileName(filePath),
ParentCode = parentItemCode, ParentCode = parentItemCode,
Size = uploadStream.Length Size = uploadStream.Length,
Geometry = JObject.Parse(geoJsonString)
}; };
using var httpClient = CreateConfigurableHttpClient(_httpClient); using var httpClient = CreateConfigurableHttpClient(_httpClient);

View File

@ -37,9 +37,9 @@ namespace FarmmapsApi.Services
return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest); return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest);
} }
public async Task<Item> UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) { public async Task<Item> UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName, string fieldGeomJson = null) {
var startUpload = DateTime.UtcNow.AddSeconds(-3); var startUpload = DateTime.UtcNow.AddSeconds(-3);
var result = await _farmmapsApiService.UploadFile(filePath, root.Code, var result = await _farmmapsApiService.UploadFile(filePath, root.Code, fieldGeomJson,
progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}"));
if (result.Progress.Status == UploadStatus.Failed) if (result.Progress.Status == UploadStatus.Failed)
@ -50,9 +50,9 @@ namespace FarmmapsApi.Services
i.Name.ToLower().Contains(itemName.ToLower())); i.Name.ToLower().Contains(itemName.ToLower()));
} }
public async Task<Item> UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName) { public async Task<Item> UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName, string fieldGeomJson = null) {
var startUpload = DateTime.UtcNow; var startUpload = DateTime.UtcNow;
var result = await _farmmapsApiService.UploadFile(filePath, root.Code, var result = await _farmmapsApiService.UploadFile(filePath, root.Code, fieldGeomJson,
progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}"));
if (result.Progress.Status == UploadStatus.Failed) if (result.Progress.Status == UploadStatus.Failed)
@ -108,7 +108,7 @@ 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 cropfieldItem, Item tiffItem, string cellWidth, string cellHeight, string startPoint, string centered = "false", string endPoint = null, string angle = null) public async Task<Item> CreateTaskmap(Item cropfieldItem, Item tiffItem, string cellWidth, string cellHeight, string startPoint, string centered = "false", string endPoint = null, string angle = null, string precision = 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;
@ -119,6 +119,7 @@ namespace FarmmapsApi.Services
taskmapRequest.attributes["centered"] = centered; taskmapRequest.attributes["centered"] = centered;
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
taskmapRequest.attributes["precision"] = precision;
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest); string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest);

View File

@ -14,6 +14,9 @@
</None> </None>
<None Update="NitrogenInput.json"> <None Update="NitrogenInput.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="InputData-NBS.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>

View File

@ -171,7 +171,7 @@ namespace FarmmapsNbs
_logger.LogInformation("input = tiff data"); _logger.LogInformation("input = tiff data");
var dataPath = Path.Combine("Data", input.File); var dataPath = Path.Combine("Data", input.File);
geotiffItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE, dataPath, geotiffItem = await _generalService.UploadDataAsync(uploadedRoot, GEOTIFF_PROCESSED_ITEMTYPE, dataPath,
Path.GetFileNameWithoutExtension(input.File)); Path.GetFileNameWithoutExtension(input.File), input.GeometryJson.ToString(Formatting.None));
if (geotiffItem == null) { if (geotiffItem == null) {
_logger.LogError("Could not find item for uploaded data"); _logger.LogError("Could not find item for uploaded data");
@ -184,8 +184,8 @@ namespace FarmmapsNbs
var isGeoJson = input.File.Contains("json"); var isGeoJson = input.File.Contains("json");
var dataPath = Path.Combine("Data", input.File); var dataPath = Path.Combine("Data", input.File);
var shapeItem = isGeoJson ? var shapeItem = isGeoJson ?
await _generalService.UploadDataAsync(uploadedRoot, SHAPE_PROCESSED_ITEMTYPE, dataPath, Path.GetFileNameWithoutExtension(input.File)) : await _generalService.UploadDataAsync(uploadedRoot, SHAPE_PROCESSED_ITEMTYPE, dataPath, Path.GetFileNameWithoutExtension(input.File), input.GeometryJson.ToString(Formatting.None)) :
await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.File)); await _generalService.UploadZipWithShapeAsync(uploadedRoot, dataPath, Path.GetFileNameWithoutExtension(input.File), input.GeometryJson.ToString(Formatting.None));
if (shapeItem == null) { if (shapeItem == null) {
_logger.LogError("Could not find item for uploaded data"); _logger.LogError("Could not find item for uploaded data");

View File

@ -176,7 +176,7 @@ namespace FarmmapsVRApoten
//GEOTIFF TO Taskmap //GEOTIFF TO Taskmap
_logger.LogInformation($"Converting geotiff to taskmap"); _logger.LogInformation($"Converting geotiff to taskmap");
var taskmap = await _generalService.CreateTaskmap(cropfieldItem, applianceMapItem, input.CellWidth, input.CellHeight, input.StartPoint.ToString(Formatting.None), var taskmap = await _generalService.CreateTaskmap(cropfieldItem, applianceMapItem, input.CellWidth, input.CellHeight, input.StartPoint.ToString(Formatting.None),
input.Centered, input.EndPoint.ToString(Formatting.None), input.Angle); input.Centered, input.EndPoint.ToString(Formatting.None), input.Angle, input.Precision);
if (taskmap == null) if (taskmap == null)
{ {
_logger.LogError("Something went wrong with geotiff to taskmap transformation"); _logger.LogError("Something went wrong with geotiff to taskmap transformation");