public ISOLineString ExportLinearRing(LinearRing ring, ISOLineStringType lsgType)
        {
            ISOLineString lineString = new ISOLineString();

            lineString.LineStringType = lsgType;

            ISOPointType pointType = ISOPointType.Other;

            switch (lsgType)
            {
            case ISOLineStringType.PolygonExterior:
            case ISOLineStringType.PolygonInterior:
                pointType = ISOPointType.PartfieldReference;
                break;

            case ISOLineStringType.GuidancePattern:
                pointType = ISOPointType.GuidancePoint;
                break;

            case ISOLineStringType.Flag:
                pointType = ISOPointType.Flag;
                break;

            case ISOLineStringType.Obstacle:
                pointType = ISOPointType.Obstacle;
                break;
            }

            PointMapper pointMapper = new PointMapper(TaskDataMapper);

            lineString.Points = pointMapper.ExportPoints(ring.Points, pointType).ToList();
            return(lineString);
        }
        public LineString ImportLineString(ISOLineString isoLineString)
        {
            LineString  lineString  = new LineString();
            PointMapper pointMapper = new PointMapper(TaskDataMapper);

            lineString.Points = pointMapper.ImportPoints(isoLineString.Points).ToList();
            return(lineString);
        }
        public ISOLineString ExportLinearRing(LinearRing ring, ISOLineStringType lsgType)
        {
            ISOLineString lineString = new ISOLineString(TaskDataMapper.Version);

            lineString.LineStringType = lsgType;

            ISOPointType pointType = ISOPointType.Other;

            if (TaskDataMapper.Version > 3)
            {
                switch (lsgType)
                {
                case ISOLineStringType.PolygonExterior:
                case ISOLineStringType.PolygonInterior:
                    pointType = ISOPointType.PartfieldReference;
                    break;

                case ISOLineStringType.GuidancePattern:
                    pointType = ISOPointType.GuidancePoint;
                    break;

                case ISOLineStringType.Flag:
                    pointType = ISOPointType.Flag;
                    break;

                case ISOLineStringType.Obstacle:
                    pointType = ISOPointType.Obstacle;
                    break;
                }
            }
            else if (lineString.LineStringType == ISOLineStringType.Flag)
            {
                //Flag & Other (default) are the only 2 options for version 3
                pointType = ISOPointType.Flag;
            }

            PointMapper pointMapper = new PointMapper(TaskDataMapper);

            lineString.Points = pointMapper.ExportPoints(ring.Points, pointType).ToList();
            return(lineString);
        }
Exemple #4
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);
        }
        public ISOLineString ExportGuidancePattern(GuidancePattern adaptGuidancePattern)
        {
            ISOLineString lineString = new ISOLineString(TaskDataMapper.Version);

            lineString.LineStringType = ISOLineStringType.GuidancePattern;

            PointMapper pointMapper = new PointMapper(TaskDataMapper);

            List <Point> adaptPoints;

            switch (adaptGuidancePattern.GuidancePatternType)
            {
            case GuidancePatternTypeEnum.AbCurve:
                AbCurve curve = adaptGuidancePattern as AbCurve;
                adaptPoints = curve.Shape[0].Points;     //Only first linestring used.
                break;

            case GuidancePatternTypeEnum.AbLine:
                AbLine abLine = adaptGuidancePattern as AbLine;
                adaptPoints = new List <Point>();
                adaptPoints.Add(abLine.A);
                adaptPoints.Add(abLine.B);
                break;

            case GuidancePatternTypeEnum.APlus:
                APlus aPlus = adaptGuidancePattern as APlus;
                adaptPoints = new List <Point>();
                adaptPoints.Add(aPlus.Point);
                break;

            case GuidancePatternTypeEnum.CenterPivot:
                PivotGuidancePattern pivot = adaptGuidancePattern as PivotGuidancePattern;
                adaptPoints = new List <Point>();
                lineString.Points.Add(pointMapper.ExportPoint(pivot.Center, ISOPointType.GuidanceReferenceCenter));

                if (pivot.DefinitionMethod == PivotGuidanceDefinitionEnum.PivotGuidancePatternStartEndCenter &&
                    pivot.StartPoint != null &&
                    pivot.EndPoint != null)
                {
                    adaptPoints.Add(pivot.StartPoint);
                    adaptPoints.Add(pivot.EndPoint);
                }
                break;

            case GuidancePatternTypeEnum.Spiral:
                Spiral spiral = adaptGuidancePattern as Spiral;
                adaptPoints = spiral.Shape.Points;
                break;

            default:
                return(null);
            }

            for (int i = 0; i < adaptPoints.Count; i++)
            {
                ISOPointType pointType = i == 0
                    ? ISOPointType.GuidanceReferenceA
                    : (i == adaptPoints.Count - 1
                        ? ISOPointType.GuidanceReferenceB
                        : ISOPointType.GuidancePoint);

                lineString.Points.Add(pointMapper.ExportPoint(adaptPoints[i], pointType));
            }

            return(lineString);
        }
Exemple #6
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);
        }