Ejemplo n.º 1
0
        /// <summary>
        /// Returns an ADAPT Polygon for ISOPolygons describing field points of interest.  Null otherwise
        /// </summary>
        /// <param name="isoPolygon"></param>
        /// <returns></returns>
        public AttributeShape ImportAttributePolygon(ISOPolygon isoPolygon)
        {
            Polygon boundaryPolygon = ImportBoundaryPolygon(isoPolygon, false)?.FirstOrDefault();

            if (boundaryPolygon != null && IsFieldAttributeType(isoPolygon))
            {
                //The data has defined an explicit PLN type that maps to an attribute type
                return(new AttributeShape()
                {
                    Shape = boundaryPolygon,
                    TypeName = Enum.GetName(typeof(ISOPolygonType), isoPolygon.PolygonType),
                    Name = isoPolygon.PolygonDesignator
                });
            }
            else if (isoPolygon.LineStrings.Count == 1)
            {
                //If no linestrings defined as interior/exterior, we expect only 1 linestring
                ISOLineString attributeLsg = isoPolygon.LineStrings.FirstOrDefault(ls => LineStringMapper.IsFieldAttributeType(ls));
                if (attributeLsg != null)
                {
                    LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);
                    Polygon          polygon   = new Polygon()
                    {
                        ExteriorRing = lsgMapper.ImportLinearRing(attributeLsg)
                    };
                    return(new AttributeShape()
                    {
                        Shape = polygon,
                        TypeName = Enum.GetName(typeof(ISOPolygonType), isoPolygon.PolygonType),
                        Name = isoPolygon.PolygonDesignator
                    });
                }
            }
            return(null);  //This polygon does not map to an InteriorBoundaryAttribute.
        }
Ejemplo n.º 2
0
        //Version 3 defines a multipolygon by a single PLN with multiple exterior linestrings and interior rings in order below their exterior
        private ISOPolygon ExportVersion3Polygon(List <Polygon> adaptPolygons, ISOPolygonType polygonType)
        {
            ISOPolygon isoPolygon = new ISOPolygon(TaskDataMapper.Version);

            if ((int)polygonType < 9)
            {
                isoPolygon.PolygonType = polygonType;
            }
            else
            {
                isoPolygon.PolygonType = ISOPolygonType.Other; //Version 3 stops at 8/Other
            }

            isoPolygon.PolygonDesignator = adaptPolygons.First().Id.ToString();
            LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);

            isoPolygon.LineStrings = new List <ISOLineString>();
            foreach (Polygon adaptPolygon in adaptPolygons)
            {
                if (adaptPolygon.ExteriorRing != null)
                {
                    isoPolygon.LineStrings.Add(lsgMapper.ExportLinearRing(adaptPolygon.ExteriorRing, ISOLineStringType.PolygonExterior));
                }
                if (adaptPolygon.InteriorRings != null)
                {
                    foreach (LinearRing interiorRing in adaptPolygon.InteriorRings)
                    {
                        isoPolygon.LineStrings.Add(lsgMapper.ExportLinearRing(interiorRing, ISOLineStringType.PolygonInterior));
                    }
                }
            }
            return(isoPolygon);
        }
Ejemplo n.º 3
0
        public ISOGuidancePattern ExportGuidancePattern(GuidancePattern adaptGuidancePattern)
        {
            ISOGuidancePattern gpn = new ISOGuidancePattern();

            //ID
            string gpnID = adaptGuidancePattern.Id.FindIsoId() ?? GenerateId();

            gpn.GuidancePatternId = gpnID;
            ExportIDs(adaptGuidancePattern.Id, gpnID);

            gpn.GuidancePatternDesignator = adaptGuidancePattern.Description;
            gpn.GuidancePatternType       = ExportGuidancePatternType(adaptGuidancePattern.GuidancePatternType);
            gpn.PropagationDirection      = ExportPropagationDirection(adaptGuidancePattern.PropagationDirection);
            gpn.Extension = ExportExtension(adaptGuidancePattern.Extension);
            gpn.Heading   = ExportHeading(adaptGuidancePattern);
            if (adaptGuidancePattern.GpsSource != null)
            {
                gpn.GNSSMethod = ExportGNSSMethod(adaptGuidancePattern.GpsSource.SourceType);
                if (adaptGuidancePattern.GpsSource.HorizontalAccuracy != null)
                {
                    gpn.HorizontalAccuracy = (decimal)adaptGuidancePattern.GpsSource.HorizontalAccuracy.AsConvertedDouble("m").Value;
                }
                if (adaptGuidancePattern.GpsSource.VerticalAccuracy != null)
                {
                    gpn.VerticalAccuracy = (decimal)adaptGuidancePattern.GpsSource.VerticalAccuracy.AsConvertedDouble("m").Value;
                }
            }
            gpn.OriginalSRID        = adaptGuidancePattern.OriginalEpsgCode;
            gpn.NumberOfSwathsLeft  = (uint?)adaptGuidancePattern.NumbersOfSwathsLeft;
            gpn.NumberOfSwathsRight = (uint?)adaptGuidancePattern.NumbersOfSwathsRight;

            //Pattern
            LineStringMapper lineStringMapper = new LineStringMapper(TaskDataMapper);

            gpn.LineString = lineStringMapper.ExportGuidancePattern(adaptGuidancePattern);

            if (adaptGuidancePattern is PivotGuidancePattern pivot &&
                pivot.DefinitionMethod == PivotGuidanceDefinitionEnum.PivotGuidancePatternCenterRadius &&
                pivot.Radius != null)
            {
                gpn.Radius = (uint)pivot.Radius.AsConvertedInt("mm").Value;
                gpn.GuidancePatternOptions = ISOGuidancePatternOption.FullCircle;
            }

            //Boundary
            if (adaptGuidancePattern.BoundingPolygon != null)
            {
                PolygonMapper polygonMapper = new PolygonMapper(TaskDataMapper);
                gpn.BoundaryPolygons = polygonMapper.ExportMultipolygon(adaptGuidancePattern.BoundingPolygon, ISOPolygonType.Other).ToList();
            }

            return(gpn);
        }
Ejemplo n.º 4
0
        public Polygon ImportPolygon(ISOPolygon isoPolygon)
        {
            Polygon          polygon   = new Polygon();
            LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);
            ISOLineString    exterior  = isoPolygon.LineStrings.FirstOrDefault(l => l.LineStringType == ISOLineStringType.PolygonExterior);

            if (exterior != null)
            {
                polygon.ExteriorRing = lsgMapper.ImportLinearRing(exterior);
            }
            polygon.InteriorRings = new List <LinearRing>();
            polygon.InteriorRings.AddRange(lsgMapper.ImportLinearRings(isoPolygon.LineStrings.Where(l => l.LineStringType == ISOLineStringType.PolygonInterior)));
            return(polygon);
        }
Ejemplo n.º 5
0
        public ISOPolygon ExportPolygon(Polygon adaptPolygon, ISOPolygonType polygonType)
        {
            ISOPolygon ISOPolygon = new ISOPolygon();

            ISOPolygon.PolygonType       = polygonType;
            ISOPolygon.PolygonDesignator = adaptPolygon.Id.ToString();

            LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);

            ISOPolygon.LineStrings = new List <ISOLineString>();
            ISOPolygon.LineStrings.Add(lsgMapper.ExportLinearRing(adaptPolygon.ExteriorRing, ISOLineStringType.PolygonExterior));
            foreach (LinearRing interiorRing in adaptPolygon.InteriorRings)
            {
                ISOPolygon.LineStrings.Add(lsgMapper.ExportLinearRing(interiorRing, ISOLineStringType.PolygonInterior));
            }

            return(ISOPolygon);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns an ADAPT Polygon for ISOPolygons defined with Exterior/Interior rings.  Null otherwise
        /// </summary>
        /// <param name="isoPolygon"></param>
        /// <returns></returns>
        public Polygon ImportBoundaryPolygon(ISOPolygon isoPolygon)
        {
            if (IsFieldAttributeType(isoPolygon))
            {
                //Polygon is defined as an area of interest and not a PFD/TZN boundary, etc.
                return(null);
            }

            ISOLineString exteriorRing = isoPolygon.LineStrings.FirstOrDefault(l => l.LineStringType == ISOLineStringType.PolygonExterior);
            IEnumerable <ISOLineString> interiorRings = isoPolygon.LineStrings.Where(l => l.LineStringType == ISOLineStringType.PolygonInterior);

            if (exteriorRing != null || interiorRings.Any())
            {
                Polygon          polygon   = new Polygon();
                LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);
                if (exteriorRing != null)
                {
                    polygon.ExteriorRing = lsgMapper.ImportLinearRing(exteriorRing);
                }
                polygon.InteriorRings = lsgMapper.ImportLinearRings(interiorRings).ToList();
                return(polygon);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public ISOGuidancePattern ExportGuidancePattern(GuidancePattern adaptGuidancePattern)
        {
            ISOGuidancePattern gpn = new ISOGuidancePattern();

            //ID
            string gpnID = adaptGuidancePattern.Id.FindIsoId() ?? GenerateId();

            gpn.GuidancePatternId = gpnID;
            ExportIDs(adaptGuidancePattern.Id, gpnID);

            gpn.GuidancePatternDesignator = adaptGuidancePattern.Description;
            gpn.GuidancePatternType       = ExportGuidancePatternType(adaptGuidancePattern.GuidancePatternType);
            gpn.PropagationDirection      = ExportPropagationDirection(adaptGuidancePattern.PropagationDirection);
            gpn.Extension           = ExportExtension(adaptGuidancePattern.Extension);
            gpn.Heading             = ExportHeading(adaptGuidancePattern);
            gpn.GNSSMethod          = ExportGNSSMethod(adaptGuidancePattern.GpsSource.SourceType);
            gpn.HorizontalAccuracy  = (decimal)adaptGuidancePattern.GpsSource.HorizontalAccuracy.AsConvertedDouble("m");
            gpn.VerticalAccuracy    = (decimal)adaptGuidancePattern.GpsSource.VerticalAccuracy.AsConvertedDouble("m");
            gpn.OriginalSRID        = adaptGuidancePattern.OriginalEpsgCode;
            gpn.NumberOfSwathsLeft  = (uint?)adaptGuidancePattern.NumbersOfSwathsLeft;
            gpn.NumberOfSwathsRight = (uint?)adaptGuidancePattern.NumbersOfSwathsRight;

            //Pattern
            LineStringMapper lineStringMapper = new LineStringMapper(TaskDataMapper);

            switch (adaptGuidancePattern.GuidancePatternType)
            {
            case GuidancePatternTypeEnum.AbCurve:
                AbCurve curve = adaptGuidancePattern as AbCurve;
                gpn.LineString = lineStringMapper.ExportLineString(curve.Shape[0], ISOLineStringType.GuidancePattern);     //Only first linestring used.
                break;

            case GuidancePatternTypeEnum.AbLine:
                AbLine     abLine = adaptGuidancePattern as AbLine;
                LineString line   = new LineString {
                    Points = new List <Point>()
                };
                line.Points.Add(abLine.A);
                line.Points.Add(abLine.B);
                gpn.LineString = lineStringMapper.ExportLineString(line, ISOLineStringType.GuidancePattern);
                break;

            case GuidancePatternTypeEnum.APlus:
                APlus      aPlus     = adaptGuidancePattern as APlus;
                LineString aPlusLine = new LineString {
                    Points = new List <Point>()
                };
                aPlusLine.Points.Add(aPlus.Point);
                gpn.LineString = lineStringMapper.ExportLineString(aPlusLine, ISOLineStringType.GuidancePattern);
                break;

            case GuidancePatternTypeEnum.CenterPivot:
                PivotGuidancePattern pivot     = adaptGuidancePattern as PivotGuidancePattern;
                LineString           pivotLine = new LineString {
                    Points = new List <Point>()
                };
                pivotLine.Points.Add(pivot.Center);

                if (pivot.StartPoint != null)
                {
                    pivotLine.Points.Add(pivot.StartPoint);
                    if (pivot.EndPoint != null)
                    {
                        pivotLine.Points.Add(pivot.EndPoint);
                    }
                }
                gpn.LineString = lineStringMapper.ExportLineString(pivotLine, ISOLineStringType.GuidancePattern);
                //gpn.Radius = ?  //Not implemented
                //gpn.GuidancePatternOptions = ? //Not implemented
                break;

            case GuidancePatternTypeEnum.Spiral:
                Spiral spiral = adaptGuidancePattern as Spiral;
                gpn.LineString = lineStringMapper.ExportLineString(spiral.Shape, ISOLineStringType.GuidancePattern);
                break;
            }

            //Boundary
            if (adaptGuidancePattern.BoundingPolygon != null)
            {
                PolygonMapper polygonMapper = new PolygonMapper(TaskDataMapper);
                gpn.BoundaryPolygons = polygonMapper.ExportPolygons(adaptGuidancePattern.BoundingPolygon.Polygons, ISOPolygonType.Other).ToList();
            }

            return(gpn);
        }
Ejemplo n.º 8
0
        public GuidancePattern ImportGuidancePattern(ISOGuidancePattern isoGuidancePattern)
        {
            GuidancePattern  pattern          = null;
            LineStringMapper lineStringMapper = new LineStringMapper(TaskDataMapper);
            PointMapper      pointMapper      = new PointMapper(TaskDataMapper);

            switch (isoGuidancePattern.GuidancePatternType)
            {
            case ISOGuidancePatternType.AB:
                pattern = new AbLine();
                AbLine abLine = pattern as AbLine;
                abLine.A = pointMapper.ImportPoint(isoGuidancePattern.LineString.Points.First());
                abLine.B = pointMapper.ImportPoint(isoGuidancePattern.LineString.Points.Last());
                break;

            case ISOGuidancePatternType.APlus:
                pattern = new APlus();
                APlus aPlus = pattern as APlus;
                aPlus.Point = pointMapper.ImportPoint(isoGuidancePattern.LineString.Points.First());
                break;

            case ISOGuidancePatternType.Curve:
                pattern = new AbCurve();
                AbCurve abCurve = pattern as AbCurve;
                abCurve.Shape = new List <LineString>()
                {
                    lineStringMapper.ImportLineString(isoGuidancePattern.LineString)
                };                                                                                                               //As with export, we only have 1 linestring.
                break;

            case ISOGuidancePatternType.Pivot:
                pattern = new PivotGuidancePattern();
                PivotGuidancePattern pivot = pattern as PivotGuidancePattern;
                pivot.Center = pointMapper.ImportPoint(isoGuidancePattern.LineString.Points.First());
                if (isoGuidancePattern.LineString.Points.Count == 3)
                {
                    pivot.StartPoint = pointMapper.ImportPoint(isoGuidancePattern.LineString.Points[1]);
                    pivot.EndPoint   = pointMapper.ImportPoint(isoGuidancePattern.LineString.Points[2]);
                }
                //Radius & GuidancePatternOptions not implemented in ADAPT
                break;

            case ISOGuidancePatternType.Spiral:
                pattern = new Spiral();
                Spiral spiral = pattern as Spiral;
                spiral.Shape = lineStringMapper.ImportLineString(isoGuidancePattern.LineString);
                break;
            }

            //ID
            ImportIDs(pattern.Id, isoGuidancePattern.GuidancePatternId);

            pattern.Description          = isoGuidancePattern.GuidancePatternDesignator;
            pattern.GuidancePatternType  = ImportGuidancePatternType(isoGuidancePattern.GuidancePatternType);
            pattern.PropagationDirection = ImportPropagationDirection(isoGuidancePattern.PropagationDirection);
            pattern.Extension            = ImportExtension(isoGuidancePattern.Extension);

            //Heading
            if (isoGuidancePattern.Heading.HasValue)
            {
                double heading = Convert.ToDouble(isoGuidancePattern.Heading.Value);
                if (pattern is AbLine)
                {
                    (pattern as AbLine).Heading = heading;
                }
                if (pattern is AbCurve)
                {
                    (pattern as AbCurve).Heading = heading;
                }
                if (pattern is APlus)
                {
                    (pattern as APlus).Heading = heading;
                }
            }

            pattern.GpsSource                    = new GpsSource();
            pattern.GpsSource.SourceType         = ImportGNSSMethod(isoGuidancePattern.GNSSMethod);
            pattern.GpsSource.HorizontalAccuracy = GetAccuracy(isoGuidancePattern.HorizontalAccuracy);
            pattern.GpsSource.VerticalAccuracy   = GetAccuracy(isoGuidancePattern.VerticalAccuracy);

            pattern.NumbersOfSwathsLeft  = (int?)(isoGuidancePattern.NumberOfSwathsLeft);
            pattern.NumbersOfSwathsRight = (int?)(isoGuidancePattern.NumberOfSwathsRight);
            pattern.OriginalEpsgCode     = isoGuidancePattern.OriginalSRID;

            return(pattern);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns an ADAPT Polygon for ISOPolygons defined with Exterior/Interior rings.  Null otherwise
        /// </summary>
        /// <param name="isoPolygon"></param>
        /// <returns></returns>
        public IEnumerable <Polygon> ImportBoundaryPolygon(ISOPolygon isoPolygon, bool isVersion3Multipolygon)
        {
            if (IsFieldAttributeType(isoPolygon))
            {
                //Polygon is defined as an area of interest and not a PFD/TZN boundary, etc.
                return(null);
            }

            LineStringMapper lsgMapper = new LineStringMapper(TaskDataMapper);
            List <Polygon>   output    = new List <Polygon>();

            if (isVersion3Multipolygon)
            {
                //Version 3 only allowed one polygon for the boundary with multiple external linestrings acting as individual polygons
                foreach (ISOLineString ls in isoPolygon.LineStrings)
                {
                    if (ls.LineStringType == ISOLineStringType.PolygonExterior)
                    {
                        Polygon polygon = new Polygon {
                            ExteriorRing = lsgMapper.ImportLinearRing(ls)
                        };
                        if (isoPolygon.PolygonDesignator != null)
                        {
                            polygon.ContextItems.Add(new ContextItem()
                            {
                                Code = "Pr_ISOXML_Attribute_Designator", Value = isoPolygon.PolygonDesignator
                            });
                        }
                        output.Add(polygon);
                    }
                    else if (ls.LineStringType == ISOLineStringType.PolygonInterior)
                    {
                        //We will interpret any interior linestrings as belonging to the preceeding external linestring
                        output.Last().InteriorRings.Add(lsgMapper.ImportLinearRing(ls));
                    }
                }
            }
            else
            {
                //Normal Polygon behavior with only one possible exterior ring.
                ISOLineString exteriorRing = isoPolygon.LineStrings.FirstOrDefault(l => l.LineStringType == ISOLineStringType.PolygonExterior);
                IEnumerable <ISOLineString> interiorRings = isoPolygon.LineStrings.Where(l => l.LineStringType == ISOLineStringType.PolygonInterior);
                if (exteriorRing != null || interiorRings.Any())
                {
                    Polygon polygon = new Polygon();
                    if (exteriorRing != null)
                    {
                        polygon.ExteriorRing = lsgMapper.ImportLinearRing(exteriorRing);
                    }
                    polygon.InteriorRings = lsgMapper.ImportLinearRings(interiorRings).ToList();
                    if (isoPolygon.PolygonDesignator != null)
                    {
                        polygon.ContextItems.Add(new ContextItem()
                        {
                            Code = "Pr_ISOXML_Attribute_Designator", Value = isoPolygon.PolygonDesignator
                        });
                    }
                    output.Add(polygon);
                }
            }
            return(output);
        }
Ejemplo n.º 10
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);
        }