Updated receiving of root items

This commit is contained in:
Mark van der Wal 2022-02-28 14:29:56 +01:00
parent 5c38ff99dc
commit 0f9fe0a433
9 changed files with 38 additions and 25 deletions

View File

@ -44,14 +44,14 @@ namespace FarmMapsBlight
await _farmmapsApiService.GetCurrentUserCodeAsync();
var roots = await _farmmapsApiService.GetCurrentUserRootsAsync();
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
var myDrive = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDrive == null)
{
_logger.LogError("Could not find a needed root item");
return;
}
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");
@ -61,12 +61,12 @@ namespace FarmMapsBlight
Item cropfieldItem;
if (string.IsNullOrEmpty(_settings.CropfieldItemCode))
{
_logger.LogInformation("Creating cropfield");
int year = DateTime.Now.Year;
string emergenDate = new DateTime(year, 4, 25).ToString("o");
string cropFieldData = "{\"area\":10.96,\"final\":true,\"soilCode\":\"1\",\"soilName\":\"Zand\",\"varietyCode\":\"10019\",\"varietyName\":\"Abana\",\"cropTypeCode\":\"1010101\",\"cropTypeName\":\"Aardappel\",\"rootDepthMax\":45,\"emergenceDate\":\"" + emergenDate + "\",\"productionPurposeCode\":\"003\",\"productionPurposeName\":\"Consumptie\"}";
_logger.LogInformation("Creating cropfield");
int year = DateTime.Now.Year;
string emergenDate = new DateTime(year, 4, 25).ToString("o");
string cropFieldData = "{\"area\":10.96,\"final\":true,\"soilCode\":\"1\",\"soilName\":\"Zand\",\"varietyCode\":\"10019\",\"varietyName\":\"Abana\",\"cropTypeCode\":\"1010101\",\"cropTypeName\":\"Aardappel\",\"rootDepthMax\":45,\"emergenceDate\":\"" + emergenDate + "\",\"productionPurposeCode\":\"003\",\"productionPurposeName\":\"Consumptie\"}";
cropfieldItem = await _generalService.CreateCropfieldItemAsync(myDrive.Code, "Cropfield Blight", year,
@"{""type"":""Polygon"",""coordinates"":[[[4.617786844284247,52.22533706956424],[4.618642601314543,52.225938364585989],[4.6192153806397,52.22563988897754],[4.619192414656403,52.2256242822442],[4.620306732153958,52.225031745661528],[4.620542019225217,52.22519855319158],[4.621157509147853,52.22487436515405],[4.623387917230182,52.22367660757213],[4.624563444939009,52.22304740241544],[4.624562779355982,52.223046635247019],[4.624534908813479,52.22302596787506],[4.627873021330343,52.221240670658399],[4.627504935938338,52.220104419135129],[4.627324878706837,52.22020569669098],[4.627320696113512,52.22020660117888],[4.626707169518044,52.22053923770041],[4.624700376420229,52.221619047547488],[4.623471571183885,52.22227447969577],[4.623471511010673,52.22227500174403],[4.623468838689317,52.22228052566992],[4.617786844284247,52.22533706956424]]]}", cropFieldData);
@"{""type"":""Polygon"",""coordinates"":[[[4.617786844284247,52.22533706956424],[4.618642601314543,52.225938364585989],[4.6192153806397,52.22563988897754],[4.619192414656403,52.2256242822442],[4.620306732153958,52.225031745661528],[4.620542019225217,52.22519855319158],[4.621157509147853,52.22487436515405],[4.623387917230182,52.22367660757213],[4.624563444939009,52.22304740241544],[4.624562779355982,52.223046635247019],[4.624534908813479,52.22302596787506],[4.627873021330343,52.221240670658399],[4.627504935938338,52.220104419135129],[4.627324878706837,52.22020569669098],[4.627320696113512,52.22020660117888],[4.626707169518044,52.22053923770041],[4.624700376420229,52.221619047547488],[4.623471571183885,52.22227447969577],[4.623471511010673,52.22227500174403],[4.623468838689317,52.22228052566992],[4.617786844284247,52.22533706956424]]]}", cropFieldData);
_settings.CropfieldItemCode = cropfieldItem.Code;
SaveSettings();
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
@ -95,7 +96,19 @@ namespace FarmmapsApi.Services
var jsonString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<UserRoot>>(jsonString);
var roots = JsonConvert.DeserializeObject<List<UserRoot>>(jsonString);
roots.ForEach(v =>
{
v.Name = GetSuffixFromSystemItemCode(v.Code);
});
return roots;
}
private static string GetSuffixFromSystemItemCode(string itemCode)
{
string[] strArray = itemCode.Split(":");
return strArray.Length == 2 ? strArray[1] : throw new ArgumentException("No system item code :" + itemCode);
}
public async Task<Item> GetItemAsync(string itemCode, string itemType = null, JObject dataFilter = null)

View File

@ -225,14 +225,14 @@ LIMIT 5;", schemaname, parceltablename, groenmonitorlatestviewname); //LIMIT x
LoadSettings(settingsfile);
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");
return;
}
var myDriveRoot = roots.SingleOrDefault(r => r.Name == "My drive");
var myDriveRoot = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDriveRoot == null)
{
_logger.LogError("Could not find a needed root item");

View File

@ -82,14 +82,14 @@ namespace FarmmapsDataDownload
LoadSettings(settingsfile);
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");
return;
}
var myDriveRoot = roots.SingleOrDefault(r => r.Name == "My drive");
var myDriveRoot = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDriveRoot == null)
{
_logger.LogError("Could not find a needed root item");

View File

@ -45,14 +45,14 @@ namespace FarmmapsHaulmkilling
await _farmmapsApiService.GetCurrentUserCodeAsync();
var roots = await _farmmapsApiService.GetCurrentUserRootsAsync();
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
var myDrive = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDrive == null)
{
_logger.LogError("Could not find a needed root item");
return;
}
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");

View File

@ -50,14 +50,14 @@ namespace FarmmapsHerbicide
private async Task SingleLutumTiffFlow(List<UserRoot> roots)
{
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
var myDrive = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDrive == null)
{
_logger.LogError("Could not find a needed root item");
return;
}
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");
@ -91,14 +91,14 @@ namespace FarmmapsHerbicide
private async Task MultiVanDenBorneShapeFlow(List<UserRoot> roots)
{
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
var myDrive = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDrive == null)
{
_logger.LogError("Could not find a needed root item");
return;
}
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");

View File

@ -64,13 +64,13 @@ namespace FarmmapsNbs {
LoadSettings(settingsfile);
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null) {
_logger.LogError("Could not find a needed root item");
return;
}
var myDriveRoot = roots.SingleOrDefault(r => r.Name == "My drive");
var myDriveRoot = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDriveRoot == null) {
_logger.LogError("Could not find a needed root item");
return;
@ -308,4 +308,4 @@ namespace FarmmapsNbs {
}
}
}
}

View File

@ -61,13 +61,13 @@ namespace FarmmapsVRApoten
bool countPerArea = input.CountPerArea;
var inputLayerName = input.InputLayerName;
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
var myDrive = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDrive == null) {
_logger.LogError("Could not find a needed root item");
return;
}
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null) {
_logger.LogError("Could not find a needed root item");
return;

View File

@ -66,7 +66,7 @@ namespace FarmmapsZonering
private async Task ZoningAsync(List<UserRoot> roots, ZoneringInput input)
{
var myDrive = roots.SingleOrDefault(r => r.Name == "My drive");
var myDrive = roots.SingleOrDefault(r => r.Name == "USER_FILES");
if (myDrive == null)
{
_logger.LogError("Could not find a needed root item");
@ -83,7 +83,7 @@ namespace FarmmapsZonering
// Load settings from previous cropfield
LoadSettings(settingsfile);
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "Uploaded");
var uploadedRoot = roots.SingleOrDefault(r => r.Name == "USER_IN");
if (uploadedRoot == null)
{
_logger.LogError("Could not find a needed root item");