Ejemplo n.º 1
0
        static public IGeometry ToGeometry(this GeoJSON.Net.Geometry.IGeometryObject geoJsonGeometry)
        {
            IGeometry geometry = null;

            switch (geoJsonGeometry.Type)
            {
            case GeoJSON.Net.GeoJSONObjectType.Point:
                geometry = (geoJsonGeometry as GeoJSON.Net.Geometry.Point).ToPoint();
                break;

            case GeoJSON.Net.GeoJSONObjectType.MultiPoint:
                geometry = (geoJsonGeometry as GeoJSON.Net.Geometry.MultiPoint).ToMultiPoint();
                break;

            case GeoJSON.Net.GeoJSONObjectType.LineString:
                geometry = (geoJsonGeometry as GeoJSON.Net.Geometry.LineString).ToPolyline();
                break;

            case GeoJSON.Net.GeoJSONObjectType.MultiLineString:
                geometry = (geoJsonGeometry as GeoJSON.Net.Geometry.MultiLineString).ToPolyline();
                break;

            case GeoJSON.Net.GeoJSONObjectType.Polygon:
                geometry = (geoJsonGeometry as GeoJSON.Net.Geometry.Polygon).ToPolygon();
                break;

            case GeoJSON.Net.GeoJSONObjectType.MultiPolygon:
                geometry = (geoJsonGeometry as GeoJSON.Net.Geometry.MultiPolygon).ToPolygon();
                break;
            }

            return(geometry);
        }
        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);
        }
        private Feature Map(RasterGridPrescription prescription)
        {
            GeoJSON.Net.Geometry.IGeometryObject geometry   = null;
            Dictionary <string, object>          properties = new Dictionary <string, object>();

            if (prescription.BoundingBox != null)
            {
                geometry = PolygonMapper.MapBoundingBox(prescription.BoundingBox, _properties.AffineTransformation);
            }
            else
            {
                geometry = PointMapper.MapPoint2Point(prescription.Origin, _properties.AffineTransformation);
            }

            properties.Add("RowCount", prescription.RowCount);
            properties.Add("ColumnCount", prescription.ColumnCount);
            properties.Add("CellWidth", prescription.CellWidth.Value.Value);
            properties.Add("CellHeight", prescription.CellHeight.Value.Value);
            //properties.Add("RxProductLookups", prescription.RxProductLookups);  // Id, ProductId, Representation, UnitOfMeasure

            // 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.0;

            foreach (var rate in prescription.Rates)
            {
                if (rate.RxRates[0].Rate != outOfFieldRate)
                {
                    minRate = Math.Min(minRate, rate.RxRates[0].Rate);
                    maxRate = Math.Max(maxRate, rate.RxRates[0].Rate);
                }
            }
            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);
                }
            }
            //Array Values = products.Select(x => (Object)x).ToArray(); ;
            properties.Add("Products", products.ToArray());

            return(new Feature(geometry, properties));
        }
Ejemplo n.º 4
0
 static public byte[] GeometryToWkb(GeoJSON.Net.Geometry.IGeometryObject p_Geometry)
 {
     return(WkbEncode.Encode(p_Geometry));
 }
Ejemplo n.º 5
0
 static public DbGeography GeometryToDbGeography(GeoJSON.Net.Geometry.IGeometryObject p_Geometry)
 {
     return(DbGeography.FromBinary(WkbEncode.Encode(p_Geometry)));
 }