Esempio n. 1
0
        private static void CheckBoundary(XmlNode fieldNode, Field field, Catalog catalog)
        {
            var polygons = fieldNode.SelectNodes("PLN");
            if(polygons.Count == 0)
                return;

            var boundary = catalog.FieldBoundaries.Single(b => b.Id.ReferenceId == field.ActiveBoundaryId);
            MultiPolygonAssert.AreEqual(polygons, boundary.SpatialData);
        }
Esempio n. 2
0
        private static void LoadArea(string inputValue, Field field)
        {
            long areaValue;
            if (inputValue.ParseValue(out areaValue) == false || areaValue < 0)
                return;

            var numericValue = new NumericValue(new CompositeUnitOfMeasure("m2").ToModelUom(), areaValue);
            field.Area = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), numericValue.UnitOfMeasure, numericValue);
        }
Esempio n. 3
0
        private void AssignFarm(XmlNode inputNode, Field field)
        {
            var farmId = inputNode.GetXmlNodeValue("@F");
            if (string.IsNullOrEmpty(farmId))
                return;

            var farm = _taskDocument.Farms.FindById(farmId);
            if (farm != null)
                field.FarmId = farm.Id.ReferenceId;
        }
Esempio n. 4
0
        private static void CheckArea(XmlNode fieldNode, Field field)
        {
            long areaValue;
            if (fieldNode.GetXmlAttribute("D").ParseValue(out areaValue) == false || areaValue < 0)
                return;

            Assert.AreEqual(areaValue, field.Area.Value.Value);
            Assert.AreEqual(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation().Code,
                field.Area.Representation.Code);
            Assert.AreEqual(new CompositeUnitOfMeasure("m2").ToModelUom().Code, field.Area.Value.UnitOfMeasure.Code);
            Assert.AreEqual(new CompositeUnitOfMeasure("m2").ToModelUom().Code, field.Area.UserProvidedUnitOfMeasure.Code);
        }
Esempio n. 5
0
        private static void AreEqual(XmlNode fieldNode, Field field, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            if (fieldNode.GetXmlAttribute("A") == null || fieldNode.GetXmlAttribute("C") == null || fieldNode.GetXmlAttribute("D") == null)
                return;

            UniqueIdAssert.AreEqual(linkList, fieldNode.GetXmlAttribute("A"), field.Id.UniqueIds);
            Assert.AreEqual(fieldNode.GetXmlAttribute("A"), field.Id.FindIsoId());
            Assert.AreEqual(fieldNode.GetXmlAttribute("C"), field.Description);

            CheckArea(fieldNode, field);
            CheckFarm(fieldNode, field, catalog);
            CheckBoundary(fieldNode, field, catalog);
            CheckGuidanceGroups(fieldNode, field, catalog, linkList);
            CheckCropZone(fieldNode, field, catalog);
        }
Esempio n. 6
0
        public void GivenTaskWhenMapThenFieldIdIsMapped()
        {
            _task.E = "PFD1";
            var field = new Field();
            field.Id.UniqueIds.Add(new UniqueId
            {
                Source = UniqueIdMapper.IsoSource,
                CiTypeEnum = CompoundIdentifierTypeEnum.String,
                Id = _task.E,
            });
            _dataModel.Catalog.Fields.Add(field);

            var result = MapSingle();
            Assert.AreEqual(field.Id.ReferenceId, result.FieldIds.Single());
        }
Esempio n. 7
0
        private static void CheckCropZone(XmlNode fieldNode, Field field, Catalog catalog)
        {
            var cropId = fieldNode.GetXmlAttribute("G");
            if(String.IsNullOrEmpty(cropId))
               return;

            var cropZone = catalog.CropZones.Single(cz => cz.FieldId == field.Id.ReferenceId);
            var crop = catalog.Crops.Single(c => c.Id.ReferenceId == cropZone.CropId);

            Assert.AreEqual(cropId, crop.Id.FindIsoId());
            Assert.AreEqual(field.Id.ReferenceId, cropZone.FieldId);
            Assert.AreEqual(field.Description, cropZone.Description);
            Assert.AreEqual(field.Area.Value.Value, cropZone.Area.Value.Value);

            if(field.GuidanceGroupIds != null)
                Assert.AreEqual(field.GuidanceGroupIds, cropZone.GuidanceGroupIds);
        }
Esempio n. 8
0
        private void LoadCropZone(XmlNode inputNode, Field field, string fieldId)
        {
            var cropId = inputNode.GetXmlNodeValue("@G");
            if (string.IsNullOrEmpty(cropId))
                return;

            Crop crop;
            if (!_taskDocument.Crops.TryGetValue(cropId, out crop))
                return;

            var cropZone = new CropZone();
            cropZone.CropId = crop.Id.ReferenceId;
            cropZone.FieldId = field.Id.ReferenceId;
            cropZone.Description = field.Description;
            cropZone.Area = field.Area.Copy();
            cropZone.GuidanceGroupIds = field.GuidanceGroupIds != null ? field.GuidanceGroupIds.ToList() : null;

            _taskDocument.CropZones[fieldId] = cropZone;
        }
Esempio n. 9
0
        private string WriteField(XmlWriter writer, Field field)
        {
            var fieldId = field.Id.FindIsoId() ?? GenerateId();
            TaskWriter.Ids.Add(fieldId, field.Id);

            writer.WriteStartElement(XmlPrefix);
            writer.WriteAttributeString("A", fieldId);
            writer.WriteAttributeString("C", field.Description);

            WriteArea(writer, field.Area);
            WriteCropZone(writer, field.Id);

            WriteFarmReference(writer, field.FarmId);
            WriteBoundary(writer, field.ActiveBoundaryId);
            WriteGuidance(writer, field.GuidanceGroupIds);

            writer.WriteEndElement();

            return fieldId;
        }
Esempio n. 10
0
        private static void CheckGuidanceGroups(XmlNode fieldNode, Field field, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            var ggps = fieldNode.SelectNodes("GGP");
            if(ggps.Count == 0)
                return;

            var guidanceGroups = catalog.GuidanceGroups.Where(gg => field.GuidanceGroupIds.Contains(gg.Id.ReferenceId));
            GuidanceGroupAssert.AreEqual(ggps, guidanceGroups, catalog, linkList);
        }
Esempio n. 11
0
        private static void CheckFarm(XmlNode fieldNode, Field field, Catalog catalog)
        {
            var farmId = fieldNode.GetXmlAttribute("F");
            if (String.IsNullOrEmpty(farmId))
                return;

            var farm = catalog.Farms.Single(f => f.Id.ReferenceId == field.FarmId);
            Assert.AreEqual(farmId, farm.Id.FindIsoId());
        }
Esempio n. 12
0
        private PFD MapField(Field field, Dictionary<int, string> keyToIsoId, int fieldIndex, Catalog setupCatalog)
        {
            var isoField = new PFD
            {
                C = field.Description,
                D = (ulong) Math.Round(field.Area.Value.Value, 0)
            };
            isoField.A = isoField.GetIsoId(fieldIndex);
            if (field.FarmId != null)
            {
                isoField.F = keyToIsoId[field.FarmId.Value];
                var farm = setupCatalog.Farms.First(f => f.Id.ReferenceId == field.FarmId.Value);
                if (farm.GrowerId != null)
                {
                    isoField.E = keyToIsoId[farm.GrowerId.Value];
                }
            }
            if (field.ActiveBoundaryId != null)
            {
                var boundary = setupCatalog.FieldBoundaries.Single(b => b.Id.ReferenceId == field.ActiveBoundaryId.Value);
                isoField.Items = new IWriter[] {_boundaryMapper.Map(boundary.SpatialData, BoundaryType.Field, boundary.Description)};
            }

            keyToIsoId.Add(field.Id.ReferenceId, isoField.A);
            return isoField;
        }
Esempio n. 13
0
        public void GivenLoggedDataWithFieldIdWhenMapThenEIsMapped()
        {
            var field = new Field();
            field.Id.UniqueIds.Add(new UniqueId
            {
                CiTypeEnum = CompoundIdentifierTypeEnum.String,
                Id = "PFD3",
                Source = UniqueIdMapper.IsoSource,
            });
            _catalog.Fields = new List<Field> {field};

            _loggedData.FieldId = field.Id.ReferenceId;

            var result = MapSingle();

            Assert.AreEqual("PFD3", result.E);
        }
Esempio n. 14
0
        private Field LoadField(XmlNode inputNode, out string fieldId)
        {
            var field = new Field();

            // Required fields. Do not proceed if they are missing
            fieldId = inputNode.GetXmlNodeValue("@A");
            field.Description = inputNode.GetXmlNodeValue("@C");
            LoadArea(inputNode.GetXmlNodeValue("@D"), field);
            if (fieldId == null || field.Description == null || field.Area == null)
                return null;

            field.Id.UniqueIds.Add(ImportHelper.CreateUniqueId(fieldId));

            // Optional fields
            AssignFarm(inputNode, field);
            LoadFieldBoundary(inputNode, field);

            LoadGuidance(inputNode, field);

            LoadCropZone(inputNode, field, fieldId);

            _taskDocument.LoadLinkedIds(fieldId, field.Id);
            return field;
        }
Esempio n. 15
0
        private void LoadGuidance(XmlNode inputNode, Field field)
        {
            var guidanceGroups = GuidanceGroupLoader.LoadGuidanceGroups(inputNode.SelectNodes("GGP"));
            if (guidanceGroups != null)
            {
                foreach (var guidanceGroup in guidanceGroups)
                {
                    _taskDocument.GuidanceGroups.Add(guidanceGroup.Key, guidanceGroup.Value);
                    field.GuidanceGroupIds = guidanceGroups.Values.Select(x => x.Group.Id.ReferenceId).ToList();

                    _taskDocument.LoadLinkedIds(guidanceGroup.Key, guidanceGroup.Value.Group.Id);

                    guidanceGroup.Value.Patterns.All(x => { _taskDocument.LoadLinkedIds(x.Key, x.Value.Id); return true; });
                }
            }
        }
Esempio n. 16
0
        private void LoadFieldBoundary(XmlNode inputNode, Field field)
        {
            var polygon = ShapeLoader.LoadPolygon(inputNode.SelectNodes("PLN"));
            if (polygon != null)
            {
                var fieldBoundary = new FieldBoundary
                {
                    FieldId = field.Id.ReferenceId,
                    SpatialData = polygon,
                };

                _taskDocument.FieldBoundaries.Add(fieldBoundary);

                field.ActiveBoundaryId = fieldBoundary.Id.ReferenceId;
            }
        }