From 760f3fad6409a2809e3fa377db9c5b0d5e8d85ab Mon Sep 17 00:00:00 2001 From: Sijbrandij Date: Fri, 2 Apr 2021 16:15:44 +0200 Subject: [PATCH] added field polygon to data upload --- FarmmapsApi/Services/FarmmapsApiService.cs | 5 +++-- FarmmapsApi/Services/GeneralService.cs | 11 ++++++----- FarmmapsNbs/FarmmapsNbs.csproj | 3 +++ FarmmapsNbs/NbsApplication.cs | 6 +++--- FarmmapsPoten/PotenApplication.cs | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/FarmmapsApi/Services/FarmmapsApiService.cs b/FarmmapsApi/Services/FarmmapsApiService.cs index 1a2770b..2d6a7d7 100644 --- a/FarmmapsApi/Services/FarmmapsApiService.cs +++ b/FarmmapsApi/Services/FarmmapsApiService.cs @@ -283,7 +283,7 @@ namespace FarmmapsApi.Services /// /// /// - public async Task UploadFile(string filePath, string parentItemCode, + public async Task UploadFile(string filePath, string parentItemCode, string geoJsonString, Action progressCallback = null) { if (!File.Exists(filePath)) @@ -300,7 +300,8 @@ namespace FarmmapsApi.Services { Name = Path.GetFileName(filePath), ParentCode = parentItemCode, - Size = uploadStream.Length + Size = uploadStream.Length, + Geometry = JObject.Parse(geoJsonString) }; using var httpClient = CreateConfigurableHttpClient(_httpClient); diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index b494fce..db0aacf 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -37,9 +37,9 @@ 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, string fieldGeomJson = null) { 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}")); if (result.Progress.Status == UploadStatus.Failed) @@ -50,9 +50,9 @@ 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, string fieldGeomJson = null) { 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}")); if (result.Progress.Status == UploadStatus.Failed) @@ -108,7 +108,7 @@ namespace FarmmapsApi.Services } // Create taskmap based on width, height and direction - public async Task CreateTaskmap(Item cropfieldItem, Item tiffItem, string cellWidth, string cellHeight, string startPoint, string centered = "false", string endPoint = null, string angle = null) + public async Task 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 }; taskmapRequest.attributes["inputCode"] = tiffItem.Code; @@ -119,6 +119,7 @@ namespace FarmmapsApi.Services taskmapRequest.attributes["centered"] = centered; if (angle == null) taskmapRequest.attributes["endPoint"] = endPoint; // Coordinates WGS84 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); diff --git a/FarmmapsNbs/FarmmapsNbs.csproj b/FarmmapsNbs/FarmmapsNbs.csproj index 05c7803..7f211f6 100644 --- a/FarmmapsNbs/FarmmapsNbs.csproj +++ b/FarmmapsNbs/FarmmapsNbs.csproj @@ -14,6 +14,9 @@ Always + + + Always diff --git a/FarmmapsNbs/NbsApplication.cs b/FarmmapsNbs/NbsApplication.cs index 109843c..fe63c2b 100644 --- a/FarmmapsNbs/NbsApplication.cs +++ b/FarmmapsNbs/NbsApplication.cs @@ -171,7 +171,7 @@ namespace FarmmapsNbs _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)); + Path.GetFileNameWithoutExtension(input.File), input.GeometryJson.ToString(Formatting.None)); if (geotiffItem == null) { _logger.LogError("Could not find item for uploaded data"); @@ -184,8 +184,8 @@ namespace FarmmapsNbs var isGeoJson = input.File.Contains("json"); var dataPath = Path.Combine("Data", input.File); var shapeItem = isGeoJson ? - await _generalService.UploadDataAsync(uploadedRoot, SHAPE_PROCESSED_ITEMTYPE, dataPath, Path.GetFileNameWithoutExtension(input.File)) : - await _generalService.UploadZipWithShapeAsync(uploadedRoot, 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), input.GeometryJson.ToString(Formatting.None)); if (shapeItem == null) { _logger.LogError("Could not find item for uploaded data"); diff --git a/FarmmapsPoten/PotenApplication.cs b/FarmmapsPoten/PotenApplication.cs index 712dd9f..79c0192 100644 --- a/FarmmapsPoten/PotenApplication.cs +++ b/FarmmapsPoten/PotenApplication.cs @@ -176,7 +176,7 @@ namespace FarmmapsVRApoten //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), - input.Centered, input.EndPoint.ToString(Formatting.None), input.Angle); + input.Centered, input.EndPoint.ToString(Formatting.None), input.Angle, input.Precision); if (taskmap == null) { _logger.LogError("Something went wrong with geotiff to taskmap transformation");