Ejemplo n.º 1
0
        private static void AddRate(int productId, double productRate, RxRates rates, RasterGridPrescription prescription, UnitOfMeasure uom)
        {
            RxProductLookup rxProductLookup;

            if (prescription.RxProductLookups.Any(x => x.ProductId == productId))
            {
                rxProductLookup = prescription.RxProductLookups.Single(x => x.ProductId == productId);
            }
            else
            {
                rxProductLookup = new RxProductLookup
                {
                    ProductId     = productId,
                    UnitOfMeasure = uom
                };
                prescription.RxProductLookups.Add(rxProductLookup);
            }

            var rxRate = new RxRate
            {
                Rate = productRate,
                RxProductLookupId = rxProductLookup.Id.ReferenceId,
            };

            rates.RxRate.Add(rxRate);
        }
Ejemplo n.º 2
0
        private void LoadRateUnits(TreatmentZone treatmentZone, RasterGridPrescription prescription)
        {
            if (prescription.RxProductLookups == null)
            {
                prescription.RxProductLookups = new List <RxProductLookup>();
            }

            var rxRates = new List <RxRate>();

            foreach (var dataVariable in treatmentZone.Variables)
            {
                var product         = _taskDocument.Products.FindById(dataVariable.ProductId) ?? _taskDocument.ProductMixes.FindById(dataVariable.ProductId);
                var rxProductLookup = new RxProductLookup
                {
                    ProductId     = product == null ? 0 : product.Id.FindIntIsoId(),
                    UnitOfMeasure = dataVariable.IsoUnit.ToAdaptUnit(),
                };
                prescription.RxProductLookups.Add(rxProductLookup);
                var rxRate = new RxRate
                {
                    Rate = dataVariable.Value,
                    RxProductLookupId = rxProductLookup.Id.ReferenceId,
                };
                rxRates.Add(rxRate);
            }
            prescription.Rates = new List <RxRates> {
                new RxRates {
                    RxRate = rxRates
                }
            };
        }
Ejemplo n.º 3
0
        internal static RxRate ImportRate(int productId, double productRate, Prescription prescription)
        {
            RxProductLookup rxProductLookup = prescription.RxProductLookups.SingleOrDefault(x => x.ProductId == productId);

            return(new RxRate()
            {
                Rate = productRate,
                RxProductLookupId = rxProductLookup?.Id?.ReferenceId ?? 0
            });
        }
        private List <Feature> MapMultiple(VectorPrescription prescription)
        {
            List <Feature> features = new List <Feature>();

            double outOfFieldRate = -1.0;               // something save to compare with

            if (prescription.OutOfFieldRate != null)
            {
                outOfFieldRate = prescription.OutOfFieldRate.Value.Value;
            }

            foreach (var shaperate in prescription.RxShapeLookups)
            {
                int index = 0;
                if (shaperate.Shape != null && shaperate.Shape.Polygons.Count > 0)
                {
                    foreach (var adaptPolygon in shaperate.Shape.Polygons)
                    {
                        Dictionary <string, object> properties = new Dictionary <string, object>();
                        RxProductLookup             product    = prescription.RxProductLookups.Where(r => r.Id.ReferenceId == shaperate.Rates[index].RxProductLookupId).FirstOrDefault();
                        if (product != null)
                        {
                            properties.Add("productId", product.ProductId);
                            Product adaptProduct = _dataModel.Catalog.Products.Where(p => p.Id.ReferenceId == product.ProductId).FirstOrDefault();
                            if (adaptProduct != null)
                            {
                                properties.Add("productDescription", adaptProduct.Description);
                                properties.Add("productType", adaptProduct.ProductType.ToString());
                            }
                            properties.Add("productCode", product.Representation.Code);
                            properties.Add("productUom", product.UnitOfMeasure.Code);
                        }
                        else
                        {
                            properties.Add("productId", shaperate.Rates[index].RxProductLookupId);
                        }
                        properties.Add("rate", shaperate.Rates[index++].Rate);

                        features.Add(new Feature(PolygonMapper.MapPolygon(adaptPolygon, _properties.AffineTransformation), properties));
                    }
                }
            }

            return(features);
        }
Ejemplo n.º 5
0
        internal static RxRate ImportRate(int productId, double productRate, Prescription prescription)
        {
            RxProductLookup rxProductLookup = prescription.RxProductLookups.SingleOrDefault(x => x.ProductId == productId);

            if (rxProductLookup != null)
            {
                var rxRate = new RxRate
                {
                    Rate = productRate,
                    RxProductLookupId = rxProductLookup.Id.ReferenceId,
                };

                return(rxRate);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        private ISOProcessDataVariable ExportProcessDataVariable(RxRate rxRate, Prescription rx)
        {
            ISOProcessDataVariable processDataVariable = new ISOProcessDataVariable();
            RxProductLookup        lookup = rx.RxProductLookups.FirstOrDefault(l => l.Id.ReferenceId == rxRate.RxProductLookupId);

            if (lookup != null)
            {
                processDataVariable.ProductIdRef   = TaskDataMapper.InstanceIDMap.GetISOID(lookup.ProductId.Value);
                processDataVariable.ProcessDataDDI = DetermineVariableDDI(lookup.Representation, lookup.UnitOfMeasure).AsHexDDI();
                ISOUnit unit = UnitFactory.Instance.GetUnitByDDI(processDataVariable.ProcessDataDDI.AsInt32DDI());
                if (unit != null)
                {
                    processDataVariable.ProcessDataValue = (int)unit.ConvertToIsoUnit(rxRate.Rate);
                }
                else
                {
                    throw new ApplicationException("Missing unit on rate calculation from PDV.");
                }
            }
            return(processDataVariable);
        }
Ejemplo n.º 7
0
        private NumericRepresentationValue ImportTreatmentZoneAsNumericRepValue(ISOTreatmentZone treatmentZone, RxProductLookup productLookup)
        {
            if (treatmentZone.ProcessDataVariables == null || treatmentZone.ProcessDataVariables.Count == 0)
            {
                return(null);
            }

            if (productLookup == null)                                                                                              //This clause supports the obsolete placement of default rates on the prescription
            {
                return(treatmentZone.ProcessDataVariables.First().AsNumericRepresentationValue(RepresentationMapper, ISOTaskData)); //In this situation, there should be only one PDV
            }
            else
            {
                ISOProcessDataVariable productPDV = treatmentZone.ProcessDataVariables.FirstOrDefault(pdv => productLookup.ProductId == TaskDataMapper.InstanceIDMap.GetADAPTID(pdv.ProductIdRef));
                return(productPDV?.AsNumericRepresentationValue(RepresentationMapper, ISOTaskData));
            }
        }
Ejemplo n.º 8
0
        internal void ImportSharedPrescriptionProperties(ISOTask task, WorkItem workItem, Prescription prescription)
        {
            //Description
            prescription.Description = task.TaskDesignator;

            //CropZone/Field
            if (workItem.CropZoneId.HasValue)
            {
                prescription.CropZoneId = workItem.CropZoneId.Value;
            }
            else if (workItem.FieldId.HasValue)
            {
                prescription.FieldId = workItem.FieldId.Value;
            }

            //Products
            prescription.ProductIds = new List <int>();
            foreach (ISOTreatmentZone treatmentZone in task.TreatmentZones)
            {
                foreach (var dataVariable in treatmentZone.ProcessDataVariables)
                {
                    if (!string.IsNullOrEmpty(dataVariable.ProductIdRef))
                    {
                        int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(dataVariable.ProductIdRef);
                        if (productID.HasValue)
                        {
                            //ProductIDs
                            if (!prescription.ProductIds.Contains(productID.Value))
                            {
                                prescription.ProductIds.Add(productID.Value);
                            }

                            //Product Lookups
                            int ddi             = dataVariable.ProcessDataDDI.AsInt32DDI();
                            var rxProductLookup = new RxProductLookup
                            {
                                ProductId      = productID,
                                UnitOfMeasure  = UnitFactory.Instance.GetUnitByDDI(ddi).ToAdaptUnit(),
                                Representation = (NumericRepresentation)RepresentationMapper.Map(ddi)
                            };

                            if (!prescription.RxProductLookups.Any(r => r.ProductId == rxProductLookup.ProductId))
                            {
                                prescription.RxProductLookups.Add(rxProductLookup);
                            }
                        }
                    }
                }
            }

            //Connections
            if (task.Connections.Any())
            {
                IEnumerable <EquipmentConfiguration> equipConfigs = _connectionMapper.ImportConnections(task);

                workItem.EquipmentConfigurationGroup = new EquipmentConfigurationGroup();
                workItem.EquipmentConfigurationGroup.EquipmentConfigurations = equipConfigs.ToList();

                DataModel.Catalog.EquipmentConfigurations.AddRange(equipConfigs);
            }
        }
        private Feature Map(VectorPrescription prescription)
        {
            Feature feature = null;
            Dictionary <string, object> properties = new Dictionary <string, object>();

            // SpatialPrescription: not sure these rates mean anything for the geojson output
            double outOfFieldRate = -1.0;               // something save to compare with

            if (prescription.OutOfFieldRate != null)
            {
                properties.Add("OutOfFieldRate", prescription.OutOfFieldRate.Value.Value);
                outOfFieldRate = prescription.OutOfFieldRate.Value.Value;
            }
            if (prescription.LossOfGpsRate != null)
            {
                properties.Add("LossOfGpsRate", prescription.LossOfGpsRate.Value.Value);
            }

            double minRate = double.MaxValue;
            double maxRate = -1;

            foreach (var shaperate in prescription.RxShapeLookups)
            {
                if (shaperate.Shape != null && shaperate.Shape.Polygons.Count > 0)
                {
                    foreach (var rate in shaperate.Rates)
                    {
                        if (rate.Rate != outOfFieldRate)
                        {
                            minRate = Math.Min(minRate, rate.Rate);
                            maxRate = Math.Max(maxRate, rate.Rate);
                        }
                    }
                }
                else                 // outoffield
                {
                    foreach (var rate in shaperate.Rates)
                    {
                        RxProductLookup product = prescription.RxProductLookups.Where(r => r.Id.ReferenceId == rate.RxProductLookupId).FirstOrDefault();
                        if (product == null)
                        {
                            Console.WriteLine("outoffield rate? " + rate.Rate + " " + rate.RxProductLookupId);
                        }
                        else
                        {
                            Console.WriteLine("outoffield rate? " + rate.Rate + " " + rate.RxProductLookupId + " " + product.Representation.Code);
                        }
                    }
                }
            }
            properties.Add("MinRate", minRate);
            properties.Add("MaxRate", maxRate);
            List <Dictionary <string, object> > products = new List <Dictionary <string, object> > {
            };

            foreach (var rxproduct in prescription.RxProductLookups)
            {
                if (products.Where(p => p.ContainsKey("productId") && (int)p["productId"] == rxproduct.ProductId).FirstOrDefault() == null)
                {
                    Dictionary <string, object> product = new Dictionary <string, object>();
                    product.Add("productId", rxproduct.ProductId);
                    product.Add("productCode", rxproduct.Representation.Code);
                    product.Add("productUom", rxproduct.UnitOfMeasure.Code);
                    Product adaptProduct = _dataModel.Catalog.Products.Where(p => p.Id.ReferenceId == rxproduct.ProductId).FirstOrDefault();
                    if (adaptProduct != null)
                    {
                        product.Add("productDescription", adaptProduct.Description);
                        product.Add("productType", adaptProduct.ProductType.ToString());                         // or via GetName?
                    }
                    products.Add(product);
                }
            }
            properties.Add("Products", products.ToArray());

            if (prescription.BoundingBox != null)
            {
                GeoJSON.Net.Geometry.Polygon polygon = PolygonMapper.MapBoundingBox(prescription.BoundingBox, _properties.AffineTransformation);                  // MinX, MinY, MaxX, MaxY
                feature = new Feature(polygon, properties);
            }
            else
            {
                // @ToDo dissolve multipolygon or use Envelope?
                // NetTopologySuite.Operation.Union.CascadedPolygonUnion
                // NetTopologySuite.Algorithm.MinimumDiameter.GetMinimumRectangle
                var polygons = new List <GeoJSON.Net.Geometry.Polygon>();
                foreach (var shaperate in prescription.RxShapeLookups)
                {
                    if (shaperate.Shape != null && shaperate.Shape.Polygons.Count > 0)
                    {
                        foreach (var adaptPolygon in shaperate.Shape.Polygons)
                        {
                            GeoJSON.Net.Geometry.Polygon polygon = PolygonMapper.MapPolygon(adaptPolygon, _properties.AffineTransformation);
                            if (polygon != null)
                            {
                                polygons.Add(polygon);
                            }
                        }
                    }
                }
                feature = new Feature(new GeoJSON.Net.Geometry.MultiPolygon(polygons), properties);
            }

            return(feature);
        }
        private List <Feature> MapMultiple(RasterGridPrescription prescription)
        {
            List <Feature> features = new List <Feature>();

            // Based on Open.Topology.TestRunner.Functions/CreateShapeFunctions.Grid
            var    grid = new List <BoundingBox>();
            int    nCellsOnSideX = (int)prescription.ColumnCount;
            int    nCellsOnSideY = (int)prescription.RowCount;
            double cellSizeX = prescription.CellWidth.Value.Value;
            double cellSizeY = prescription.CellHeight.Value.Value;
            double dMinX, dMinY;

            if (prescription.BoundingBox != null)
            {
                dMinX = prescription.BoundingBox.MinX.Value.Value;
                dMinY = prescription.BoundingBox.MinY.Value.Value;
            }
            else
            {
                dMinX = prescription.Origin.X;
                dMinY = prescription.Origin.Y;
            }

            for (int j = 0; j < nCellsOnSideY; j++)
            {
                for (int i = 0; i < nCellsOnSideX; i++)
                {
                    double x1 = dMinX + i * cellSizeX;
                    double y1 = dMinY + j * cellSizeY;
                    double x2 = dMinX + (i + 1) * cellSizeX;
                    double y2 = dMinY + (j + 1) * cellSizeY;

                    var bbox = new BoundingBox();
                    bbox.MinY = new NumericRepresentationValue(RepresentationInstanceList.vrLatitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), y1));
                    bbox.MinX = new NumericRepresentationValue(RepresentationInstanceList.vrLongitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), x1));
                    bbox.MaxY = new NumericRepresentationValue(RepresentationInstanceList.vrLatitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), y2));
                    bbox.MaxX = new NumericRepresentationValue(RepresentationInstanceList.vrLongitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), x2));
                    grid.Add(bbox);
                }
            }

            int    index          = 0;
            double outOfFieldRate = -1.0;               // something save to compare with

            if (prescription.OutOfFieldRate != null)
            {
                outOfFieldRate = prescription.OutOfFieldRate.Value.Value;
            }

            Console.WriteLine($"PrescriptionMapper outOfFieldRate: {outOfFieldRate}, grids {grid.Count}");

            // @ToDo merge adjacent grid boxes with same property values?
            foreach (var bbox in grid)
            {
                // skip outOfField grids
                if (prescription.Rates[index].RxRates[0].Rate != outOfFieldRate)
                {
                    GeoJSON.Net.Geometry.IGeometryObject geometry   = PolygonMapper.MapBoundingBox(bbox, _properties.AffineTransformation);
                    Dictionary <string, object>          properties = new Dictionary <string, object>();
                    RxProductLookup product = prescription.RxProductLookups.Where(r => r.Id.ReferenceId == prescription.Rates[index].RxRates[0].RxProductLookupId).FirstOrDefault();
                    if (product != null)
                    {
                        properties.Add("productId", product.ProductId);
                        Product adaptProduct = _dataModel.Catalog.Products.Where(p => p.Id.ReferenceId == product.ProductId).FirstOrDefault();
                        if (adaptProduct != null)
                        {
                            properties.Add("productDescription", adaptProduct.Description);
                            properties.Add("productType", adaptProduct.ProductType.ToString());                                 // or via GetName?
                        }
                        properties.Add("productCode", product.Representation.Code);
                        properties.Add("productUom", product.UnitOfMeasure.Code);
                    }
                    else
                    {
                        properties.Add("productId", prescription.Rates[index].RxRates[0].RxProductLookupId);
                    }
                    properties.Add("rate", prescription.Rates[index].RxRates[0].Rate);

                    features.Add(new Feature(geometry, properties));
                }
                index++;
            }

            return(features);
        }
Ejemplo n.º 11
0
        private ISOTreatmentZone ExportTreatmentZonesForType2(ISOTask task, RasterGridPrescription prescription)
        {
            if (prescription.ProductIds == null)
            {
                TaskDataMapper.AddError($"No Products are present for Grid Type 2 Prescription export: {prescription.Description}", prescription.Id.ReferenceId.ToString());
                return(null);
            }

            var lossOfSignalTreatmentZone = new ISOTreatmentZone {
                TreatmentZoneDesignator = "Loss of GPS", ProcessDataVariables = new List <ISOProcessDataVariable>()
            };
            var outOfFieldTreatmentZone = new ISOTreatmentZone {
                TreatmentZoneDesignator = "Out of Field", ProcessDataVariables = new List <ISOProcessDataVariable>()
            };
            var defaultTreatmentZone = new ISOTreatmentZone {
                TreatmentZoneDesignator = "Default", ProcessDataVariables = new List <ISOProcessDataVariable>()
            };

            foreach (var productId in prescription.ProductIds)
            {
                var isoUnit = DetermineIsoUnit(prescription.RxProductLookups.First(p => p.ProductId == productId).UnitOfMeasure);

                string          isoProductId  = TaskDataMapper.InstanceIDMap.GetISOID(productId) ?? string.Empty;
                RxProductLookup productLookup = prescription.RxProductLookups.FirstOrDefault(p => p.ProductId == productId);

                ISOProcessDataVariable lossPDV = ExportProcessDataVariable(productLookup?.LossOfGpsRate ?? prescription.LossOfGpsRate, isoProductId, isoUnit);
                if (lossPDV != null)
                {
                    lossOfSignalTreatmentZone.ProcessDataVariables.Add(lossPDV);
                }

                ISOProcessDataVariable oofPDV = ExportProcessDataVariable(productLookup?.OutOfFieldRate ?? prescription.OutOfFieldRate, isoProductId, isoUnit);
                if (oofPDV != null)
                {
                    outOfFieldTreatmentZone.ProcessDataVariables.Add(oofPDV);
                }

                NumericRepresentation defaultRepresentation = productLookup?.LossOfGpsRate.Representation; //We can reuse the loss of gps representation here if it exists
                if (defaultRepresentation == null)
                {
                    //Determine the representation based on the unit of the product to be applied
                    var unitDimension = isoUnit.ToAdaptUnit().Dimension;
                    if (UnitFactory.DimensionToDdi.ContainsKey(unitDimension))
                    {
                        int ddi = UnitFactory.DimensionToDdi[unitDimension];
                        RepresentationMapper representationMapper = new RepresentationMapper();
                        var representation = representationMapper.Map(ddi) as NumericRepresentation;
                        if (representation == null)
                        {
                            representation = new NumericRepresentation
                            {
                                Code       = ddi.ToString(),
                                CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI
                            };
                        }
                    }
                    else
                    {
                        TaskDataMapper.AddError($"Unable to identify a default representation: {prescription.Description}", prescription.Id.ReferenceId.ToString());
                        return(null);
                    }
                }
                //Add 0 as the default rate in the PDV; actual values are in the binary
                var defaultRate = new NumericRepresentationValue(defaultRepresentation, new NumericValue(prescription.RxProductLookups.First(p => p.ProductId == productId).UnitOfMeasure, 0d));
                ISOProcessDataVariable defaultPDV = ExportProcessDataVariable(defaultRate, isoProductId, isoUnit);
                defaultTreatmentZone.ProcessDataVariables.Add(defaultPDV);
            }

            if (lossOfSignalTreatmentZone.ProcessDataVariables.Count > 0)
            {
                lossOfSignalTreatmentZone.TreatmentZoneCode = 253;
                task.TreatmentZones.Add(lossOfSignalTreatmentZone);
                task.PositionLostTreatmentZoneCode = lossOfSignalTreatmentZone.TreatmentZoneCode;
            }

            if (outOfFieldTreatmentZone.ProcessDataVariables.Count > 0)
            {
                outOfFieldTreatmentZone.TreatmentZoneCode = 254;
                task.TreatmentZones.Add(outOfFieldTreatmentZone);
                task.OutOfFieldTreatmentZoneCode = outOfFieldTreatmentZone.TreatmentZoneCode;
            }

            defaultTreatmentZone.TreatmentZoneCode = 1;
            task.TreatmentZones.Add(defaultTreatmentZone);
            task.DefaultTreatmentZoneCode = defaultTreatmentZone.TreatmentZoneCode;

            return(defaultTreatmentZone);
        }
        public static void Export(string path)
        {
            ApplicationDataModel adm = new ApplicationDataModel();

            adm.Catalog   = new Catalog();
            adm.Documents = new Documents();

            //--------------------------
            //Setup information
            //--------------------------
            //Add a crop
            Crop corn = new Crop()
            {
                Name = "Corn"
            };

            adm.Catalog.Crops.Add(corn);

            //Add some seed varieties
            CropVarietyProduct seedVariety1 = new CropVarietyProduct()
            {
                CropId = corn.Id.ReferenceId, Description = "Variety 1"
            };
            CropVarietyProduct seedVariety2 = new CropVarietyProduct()
            {
                CropId = corn.Id.ReferenceId, Description = "Variety 2"
            };

            adm.Catalog.Products.Add(seedVariety1);
            adm.Catalog.Products.Add(seedVariety2);

            //Add a liquid product
            CropNutritionProduct fertilizer = new CropNutritionProduct()
            {
                Description = "Starter", Form = ProductFormEnum.Liquid
            };

            fertilizer.ProductType = ProductTypeEnum.Fertilizer;
            adm.Catalog.Products.Add(fertilizer);

            //Add a granular product
            CropProtectionProduct insecticide = new CropProtectionProduct()
            {
                Description = "Insecticide", Form = ProductFormEnum.Solid
            };

            insecticide.ProductType = ProductTypeEnum.Chemical;
            adm.Catalog.Products.Add(insecticide);

            //GFF
            Grower grower = new Grower()
            {
                Name = "Example Grower"
            };

            adm.Catalog.Growers.Add(grower);

            Farm farm = new Farm()
            {
                Description = "Example Farm", GrowerId = grower.Id.ReferenceId
            };

            adm.Catalog.Farms.Add(farm);

            Field field = new Field()
            {
                Description = "Example Field", FarmId = farm.Id.ReferenceId, GrowerId = grower.Id.ReferenceId
            };

            field.Area = GetNumericRepresentationValue(23d, "ha", "vrReportedFieldArea");
            adm.Catalog.Fields.Add(field);

            //Crop zone
            TimeScope season = new TimeScope()
            {
                DateContext = DateContextEnum.CropSeason, TimeStamp1 = new DateTime(2021, 1, 1)
            };
            CropZone cropZone = new CropZone()
            {
                CropId = corn.Id.ReferenceId, FieldId = field.Id.ReferenceId, TimeScopes = new List <TimeScope>()
                {
                    season
                }
            };

            adm.Catalog.CropZones.Add(cropZone);

            //Field boundary
            FieldBoundary boundary = new FieldBoundary()
            {
                SpatialData = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.475010
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.475010
                                    }
                                }
                            },
                            InteriorRings = new List <LinearRing>()
                            {
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        }
                                    }
                                },
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                FieldId = field.Id.ReferenceId
            };

            adm.Catalog.FieldBoundaries.Add(boundary);
            field.ActiveBoundaryId = boundary.Id.ReferenceId;

            //--------------------------
            //Prescription
            //--------------------------

            //Prescription setup data
            //Setup the representation and units for seed rate & seed depth prescriptions
            NumericRepresentation seedRate = GetNumericRepresentation("vrSeedRateSeedsTarget");
            UnitOfMeasure         seedUOM  = UnitInstance.UnitSystemManager.GetUnitOfMeasure("seeds1ac-1");
            RxProductLookup       seedVariety1RateLookup = new RxProductLookup()
            {
                ProductId = seedVariety1.Id.ReferenceId, Representation = seedRate, UnitOfMeasure = seedUOM
            };
            RxProductLookup seedVariety2RateLookup = new RxProductLookup()
            {
                ProductId = seedVariety2.Id.ReferenceId, Representation = seedRate, UnitOfMeasure = seedUOM
            };

            NumericRepresentation seedDepth = GetNumericRepresentation("vrSeedDepthTarget");
            UnitOfMeasure         depthUOM  = UnitInstance.UnitSystemManager.GetUnitOfMeasure("cm");
            RxProductLookup       seedVariety1DepthLookup = new RxProductLookup()
            {
                ProductId = seedVariety1.Id.ReferenceId, Representation = seedDepth, UnitOfMeasure = depthUOM
            };
            RxProductLookup seedVariety2DepthLookup = new RxProductLookup()
            {
                ProductId = seedVariety2.Id.ReferenceId, Representation = seedDepth, UnitOfMeasure = depthUOM
            };

            //Setup liquid rx representation/units
            NumericRepresentation fertilizerRate       = GetNumericRepresentation("vrAppRateVolumeTarget");
            UnitOfMeasure         fertilizerUOM        = UnitInstance.UnitSystemManager.GetUnitOfMeasure("gal1ac-1");
            RxProductLookup       fertilizerRateLookup = new RxProductLookup()
            {
                ProductId = fertilizer.Id.ReferenceId, Representation = fertilizerRate, UnitOfMeasure = fertilizerUOM
            };

            //Setup granular rx representation/units
            NumericRepresentation insecticideRate       = GetNumericRepresentation("vrAppRateMassTarget");
            UnitOfMeasure         insecticideUOM        = UnitInstance.UnitSystemManager.GetUnitOfMeasure("lb1ac-1");
            RxProductLookup       insecticideRateLookup = new RxProductLookup()
            {
                ProductId = insecticide.Id.ReferenceId, Representation = insecticideRate, UnitOfMeasure = insecticideUOM
            };


            //Prescription zones
            //Zone 1 - Variety 1 at 32000 seeds/acre, 4 cm depth target; Starter at 7 gal/ac; Insecticide at 5 lb/ac
            RxShapeLookup zone1 = new RxShapeLookup()
            {
                Rates = new List <RxRate>()
                {
                    new RxRate()
                    {
                        Rate = 32000d,
                        RxProductLookupId = seedVariety1RateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 4d,
                        RxProductLookupId = seedVariety1DepthLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 7d,
                        RxProductLookupId = fertilizerRateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 5d,
                        RxProductLookupId = insecticideRateLookup.Id.ReferenceId
                    }
                },
                Shape = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.477404
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.477756
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.478304
                                    }
                                }
                            },
                            InteriorRings = new List <LinearRing>()
                            {
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        }
                                    }
                                },
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            //Zone 2 - Variety 1 at 34000 seeds/acre, depth target 5cm; Starter at 4 gal/ac; Insecticide at 2.5 lb/ac
            RxShapeLookup zone2 = new RxShapeLookup()
            {
                Rates = new List <RxRate>()
                {
                    new RxRate()
                    {
                        Rate = 34000d,
                        RxProductLookupId = seedVariety1RateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 5d,
                        RxProductLookupId = seedVariety1DepthLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 4d,
                        RxProductLookupId = fertilizerRateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 2.5,
                        RxProductLookupId = insecticideRateLookup.Id.ReferenceId
                    }
                },
                Shape = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.477756
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.477404
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.477756
                                    }
                                }
                            }
                        }
                    }
                }
            };

            //Zone 3 - Variety 2 at 29000 seeds/acre, depth target 6 cm; Starter at 6 gal/ac ; Insecticide at 2.75 lb/ac
            RxShapeLookup zone3 = new RxShapeLookup()
            {
                Rates = new List <RxRate>()
                {
                    new RxRate()
                    {
                        Rate = 29000d,
                        RxProductLookupId = seedVariety2RateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 6d,
                        RxProductLookupId = seedVariety2DepthLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 6d,
                        RxProductLookupId = fertilizerRateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 2.75,
                        RxProductLookupId = insecticideRateLookup.Id.ReferenceId
                    }
                },
                Shape = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.475010
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.475010
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.476688
                                    }
                                }
                            }
                        }
                    }
                }
            };

            //Assembled Rx
            VectorPrescription vectorPrescription = new VectorPrescription()
            {
                Description      = "Test Prescription",
                RxProductLookups = new List <RxProductLookup>()
                {
                    seedVariety1RateLookup,
                    seedVariety2RateLookup,
                    fertilizerRateLookup,
                    seedVariety1DepthLookup,
                    seedVariety2DepthLookup,
                    insecticideRateLookup
                },
                RxShapeLookups = new List <RxShapeLookup>()
                {
                    zone1, zone2, zone3
                },
                CropZoneId = cropZone.Id.ReferenceId,
                FieldId    = field.Id.ReferenceId
            };

            (adm.Catalog.Prescriptions as List <Prescription>).Add(vectorPrescription);

            //--------------------------
            //Export data to file via the Plugin
            //--------------------------
            PrecisionPlanting.ADAPT._2020.Plugin plugin = new Plugin();
            plugin.Export(adm, path);
        }