Esempio n. 1
0
        public CropZone ImportCropZone(ISOPartfield isoPartfield)
        {
            CropZone cropZone = new CropZone();

            //Cropzone ID
            ImportIDs(cropZone.Id, isoPartfield.PartfieldID);

            //Field ID
            if (!string.IsNullOrEmpty(isoPartfield.FieldIdRef))
            {
                cropZone.FieldId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPartfield.FieldIdRef).Value;  //Cropzone has a defined parent field in the ISO XML
            }
            else
            {
                cropZone.FieldId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPartfield.PartfieldID).Value;  //Field had a crop assigned and we created a single cropzone
            }

            //Area
            var numericValue = new NumericValue(new CompositeUnitOfMeasure("m2").ToModelUom(), (double)(isoPartfield.PartfieldArea));

            cropZone.Area = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), numericValue.UnitOfMeasure, numericValue);

            //Name
            cropZone.Description = isoPartfield.PartfieldDesignator;

            //Boundary
            PolygonMapper         polygonMapper    = new PolygonMapper(TaskDataMapper);
            IEnumerable <Polygon> boundaryPolygons = polygonMapper.ImportPolygons(isoPartfield.Polygons).ToList();

            if (boundaryPolygons.Any())
            {
                MultiPolygon boundary = new MultiPolygon();
                boundary.Polygons       = boundaryPolygons.ToList();
                cropZone.BoundingRegion = boundary;
            }

            //Guidance
            GuidanceGroupMapper         guidanceGroupMapper = new GuidanceGroupMapper(TaskDataMapper);
            IEnumerable <GuidanceGroup> groups = guidanceGroupMapper.ImportGuidanceGroups(isoPartfield.GuidanceGroups);

            if (groups.Any())
            {
                if (DataModel.Catalog.GuidanceGroups == null)
                {
                    DataModel.Catalog.GuidanceGroups = new List <GuidanceGroup>();
                }
                DataModel.Catalog.GuidanceGroups.AddRange(groups);
                cropZone.GuidanceGroupIds = groups.Select(g => g.Id.ReferenceId).ToList();
            }

            //Crop
            int?adaptCropID = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPartfield.CropTypeIdRef);

            if (adaptCropID.HasValue)
            {
                cropZone.CropId = adaptCropID.Value;
            }

            return(cropZone);
        }
Esempio n. 2
0
        public Field ImportField(ISOPartfield isoPartfield)
        {
            Field field = new Field();

            //Field ID
            ImportIDs(field.Id, isoPartfield.PartfieldID);

            //Farm ID
            field.FarmId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPartfield.FarmIdRef);

            //Area
            var numericValue = new NumericValue(new CompositeUnitOfMeasure("m2").ToModelUom(), (double)(isoPartfield.PartfieldArea));

            field.Area = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), numericValue.UnitOfMeasure, numericValue);

            //Name
            field.Description = isoPartfield.PartfieldDesignator;

            //Boundary
            PolygonMapper         polygonMapper    = new PolygonMapper(TaskDataMapper);
            IEnumerable <Polygon> boundaryPolygons = polygonMapper.ImportPolygons(isoPartfield.Polygons).ToList();

            if (boundaryPolygons.Any())
            {
                MultiPolygon boundary = new MultiPolygon();
                boundary.Polygons = boundaryPolygons.ToList();
                FieldBoundary fieldBoundary = new FieldBoundary
                {
                    FieldId     = field.Id.ReferenceId,
                    SpatialData = boundary,
                };

                //Add the boundary to the Catalog
                if (DataModel.Catalog.FieldBoundaries == null)
                {
                    DataModel.Catalog.FieldBoundaries = new List <FieldBoundary>();
                }
                DataModel.Catalog.FieldBoundaries.Add(fieldBoundary);

                field.ActiveBoundaryId = fieldBoundary.Id.ReferenceId;
            }

            //Guidance
            GuidanceGroupMapper         guidanceGroupMapper = new GuidanceGroupMapper(TaskDataMapper);
            IEnumerable <GuidanceGroup> groups = guidanceGroupMapper.ImportGuidanceGroups(isoPartfield.GuidanceGroups);

            if (groups.Any())
            {
                field.GuidanceGroupIds = groups.Select(g => g.Id.ReferenceId).ToList();
            }

            //TODO any obstacle, flag, entry, etc. data
            //TODO store Partfield Code as ContextItem

            return(field);
        }
Esempio n. 3
0
        public Field ImportField(ISOPartfield isoPartfield)
        {
            Field field = new Field();

            //Field ID
            ImportIDs(field.Id, isoPartfield.PartfieldID);
            field.ContextItems = ImportContextItems(isoPartfield.PartfieldID, "ADAPT_Context_Items:Field");

            //Farm ID
            field.FarmId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoPartfield.FarmIdRef);

            //Area
            var numericValue = new NumericValue(new CompositeUnitOfMeasure("m2").ToModelUom(), (double)(isoPartfield.PartfieldArea));

            field.Area = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), numericValue.UnitOfMeasure, numericValue);

            //Name
            field.Description = isoPartfield.PartfieldDesignator;

            //Boundary
            FieldBoundary         fieldBoundary    = null;
            PolygonMapper         polygonMapper    = new PolygonMapper(TaskDataMapper);
            IEnumerable <Polygon> boundaryPolygons = polygonMapper.ImportBoundaryPolygons(isoPartfield.Polygons);

            if (boundaryPolygons.Any())
            {
                MultiPolygon boundary = new MultiPolygon();
                boundary.Polygons = boundaryPolygons.ToList();
                fieldBoundary     = new FieldBoundary
                {
                    FieldId     = field.Id.ReferenceId,
                    SpatialData = boundary,
                };

                //Add the boundary to the Catalog
                if (DataModel.Catalog.FieldBoundaries == null)
                {
                    DataModel.Catalog.FieldBoundaries = new List <FieldBoundary>();
                }
                DataModel.Catalog.FieldBoundaries.Add(fieldBoundary);

                field.ActiveBoundaryId = fieldBoundary.Id.ReferenceId;
            }

            //Guidance
            GuidanceGroupMapper         guidanceGroupMapper = new GuidanceGroupMapper(TaskDataMapper);
            IEnumerable <GuidanceGroup> groups = guidanceGroupMapper.ImportGuidanceGroups(isoPartfield.GuidanceGroups);

            if (groups.Any())
            {
                field.GuidanceGroupIds = groups.Select(g => g.Id.ReferenceId).ToList();
            }

            //Obstacles, flags, etc.
            if (fieldBoundary != null)
            {
                foreach (AttributeShape attributePolygon in polygonMapper.ImportAttributePolygons(isoPartfield.Polygons))
                {
                    fieldBoundary.InteriorBoundaryAttributes.Add(
                        new InteriorBoundaryAttribute()
                    {
                        Description  = attributePolygon.Name,
                        ContextItems = new List <ContextItem>()
                        {
                            new ContextItem()
                            {
                                Code = "Pr_ISOXML_Attribute_Type", Value = attributePolygon.TypeName
                            }
                        },
                        Shape = attributePolygon.Shape
                    });
                }
                if (isoPartfield.LineStrings.Any())
                {
                    LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);
                    foreach (AttributeShape attributeLsg in lsgMapper.ImportAttributeLineStrings(isoPartfield.LineStrings))
                    {
                        fieldBoundary.InteriorBoundaryAttributes.Add(
                            new InteriorBoundaryAttribute()
                        {
                            Description  = attributeLsg.Name,
                            ContextItems = new List <ContextItem>()
                            {
                                new ContextItem()
                                {
                                    Code = "Pr_ISOXML_Attribute_Type", Value = attributeLsg.TypeName
                                }
                            },
                            Shape = attributeLsg.Shape
                        });
                    }
                }
                if (isoPartfield.Points.Any())
                {
                    PointMapper pointMapper = new PointMapper(TaskDataMapper);
                    foreach (AttributeShape attributePoint in pointMapper.ImportAttributePoints(isoPartfield.Points))
                    {
                        fieldBoundary.InteriorBoundaryAttributes.Add(
                            new InteriorBoundaryAttribute()
                        {
                            Description  = attributePoint.Name,
                            ContextItems = new List <ContextItem>()
                            {
                                new ContextItem()
                                {
                                    Code = "Pr_ISOXML_Attribute_Type", Value = attributePoint.TypeName
                                }
                            },
                            Shape = attributePoint.Shape
                        });
                    }
                }
            }

            //TODO store Partfield Code as ContextItem

            return(field);
        }