forked from FarmMaps/FarmMapsApiClient
		
	update Blight
This commit is contained in:
		@@ -74,6 +74,10 @@ namespace FarmmapsApi.Services
 | 
			
		||||
 | 
			
		||||
        public async Task<Item> GeotiffToShape(Item tiffItem) {
 | 
			
		||||
            var taskmapRequest = new TaskRequest { TaskType = TASKMAP_TASK };
 | 
			
		||||
            
 | 
			
		||||
            taskmapRequest.attributes["cellWidth"] = "3";
 | 
			
		||||
            taskmapRequest.attributes["cellHeight"] = "1";
 | 
			
		||||
            taskmapRequest.attributes["angle"] = "0";
 | 
			
		||||
 | 
			
		||||
            string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(tiffItem.Code, taskmapRequest);
 | 
			
		||||
 | 
			
		||||
@@ -102,6 +106,47 @@ namespace FarmmapsApi.Services
 | 
			
		||||
            return taskMapItem;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Create taskmap based on width, height and direction
 | 
			
		||||
        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(cropfieldItem.Code, taskmapRequest);
 | 
			
		||||
 | 
			
		||||
            await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) => {
 | 
			
		||||
                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(cropfieldItem.Code, itemTaskCode);
 | 
			
		||||
            if (itemTask.State == ItemTaskState.Error)
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogError($"Something went wrong with task execution: {itemTask.Message}");
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //the taskmap is a child of the input tiff
 | 
			
		||||
            var itemName = "Taskmap";
 | 
			
		||||
            var taskMapItem = await FindChildItemAsync(tiffItem.ParentCode,
 | 
			
		||||
                SHAPE_PROCESSED_ITEMTYPE, itemName);
 | 
			
		||||
            if (taskMapItem == null)
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogError("Could not find the shape taskmap as a child item under the input");
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return taskMapItem;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public async Task<ItemTaskStatus> RunAndWaitForTask(Item subjectItem, string taskIdentifier,
 | 
			
		||||
            Action<TaskRequest> configureCallback = null, int retrySeconds = 3) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user