示例#1
0
        public ISOPartfield ExportField(Field adaptField)
        {
            ISOPartfield isoField = new ISOPartfield();

            //Field ID
            string fieldID = adaptField.Id.FindIsoId() ?? GenerateId();

            isoField.PartfieldID = fieldID;
            ExportIDs(adaptField.Id, fieldID);
            ExportContextItems(adaptField.ContextItems, fieldID, "ADAPT_Context_Items:Field");

            //Customer & Farm ID
            ExportFarmAndGrower(adaptField, isoField);

            //isoField.PartfieldCode = ? //TODO ContextItem?

            //Area
            if (adaptField.Area != null)
            {
                isoField.PartfieldArea = (uint)(adaptField.Area.Value.ConvertToUnit(new CompositeUnitOfMeasure("m2")));
            }

            //Name
            isoField.PartfieldDesignator = adaptField.Description;

            //Boundary
            PolygonMapper polygonMapper = new PolygonMapper(TaskDataMapper);
            FieldBoundary boundary      = DataModel.Catalog.FieldBoundaries.SingleOrDefault(b => b.FieldId == adaptField.Id.ReferenceId);

            if (boundary != null)
            {
                IEnumerable <ISOPolygon> isoPolygons = polygonMapper.ExportPolygons(boundary.SpatialData.Polygons, ISOEnumerations.ISOPolygonType.PartfieldBoundary);
                isoField.Polygons.AddRange(isoPolygons);
            }

            //Guidance
            if (DataModel.Catalog.GuidanceGroups != null)
            {
                List <GuidanceGroup> groups = new List <GuidanceGroup>();
                foreach (int groupID in adaptField.GuidanceGroupIds)
                {
                    GuidanceGroup group = DataModel.Catalog.GuidanceGroups.SingleOrDefault(g => g.Id.ReferenceId == groupID);
                    if (group != null)
                    {
                        groups.Add(group);
                    }
                }
                GuidanceGroupMapper ggpMapper = TaskDataMapper.GuidanceGroupMapper;
                isoField.GuidanceGroups = ggpMapper.ExportGuidanceGroups(groups).ToList();
            }

            //TODO any obstacle, flag, entry, etc. data pending fixes to InteriorBoundaryAttribute class

            return(isoField);
        }
示例#2
0
        public ISOPartfield ExportCropZone(CropZone cropZone)
        {
            ISOPartfield isoField = new ISOPartfield();

            //Field ID
            string fieldID = cropZone.Id.FindIsoId() ?? GenerateId();

            isoField.PartfieldID = fieldID;
            ExportIDs(cropZone.Id, fieldID);

            //Parent Field ID
            isoField.FieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(cropZone.FieldId);

            //Customer & Farm ID
            Field field = DataModel.Catalog.Fields.FirstOrDefault(f => f.Id.ReferenceId == cropZone.FieldId);

            if (field != null)
            {
                ExportFarmAndGrower(field, isoField);
            }


            //Area
            if (cropZone.Area != null)
            {
                isoField.PartfieldArea = (uint)(cropZone.Area.Value.ConvertToUnit(new CompositeUnitOfMeasure("m2")));
            }

            //Name
            isoField.PartfieldDesignator = cropZone.Description;

            //Boundary
            if (cropZone.BoundingRegion != null)
            {
                PolygonMapper polygonMapper = new PolygonMapper(TaskDataMapper);
                isoField.Polygons = polygonMapper.ExportPolygons(cropZone.BoundingRegion.Polygons, ISOEnumerations.ISOPolygonType.PartfieldBoundary).ToList();
            }

            //Guidance
            if (DataModel.Catalog.GuidanceGroups != null)
            {
                List <GuidanceGroup> groups = new List <GuidanceGroup>();
                foreach (int groupID in cropZone.GuidanceGroupIds)
                {
                    GuidanceGroup group = DataModel.Catalog.GuidanceGroups.SingleOrDefault(g => g.Id.ReferenceId == groupID);
                    if (group != null)
                    {
                        groups.Add(group);
                    }
                }
                GuidanceGroupMapper ggpMapper = new GuidanceGroupMapper(TaskDataMapper);
                isoField.GuidanceGroups = ggpMapper.ExportGuidanceGroups(groups).ToList();
            }

            if (cropZone.CropId.HasValue)
            {
                string isoCrop = TaskDataMapper.InstanceIDMap.GetISOID(cropZone.CropId.Value);
                isoField.CropTypeIdRef = isoCrop;
            }

            return(isoField);
        }