public static SpeciesObservationGridResult CreateGridCellTestDataUsingGoogleMercator(int nrRows, int nrColumns, int gridSize)
        {
            var result = new SpeciesObservationGridResult();

            //double[] upperLeftStartCoordinate = {15.569241, 58.3898709}; // Linköping
            //double[] leftUpperStartCoordinate = { 15.416564941405483, 60.479793034510955 }; // Borlänge

            double[] centerStartCoordinate         = { 15.416564941405483, 60.479793034510955 }; // Borlänge
            double[] mercatorCenterStartCoordinate = Wgs84Util.WGS84ToGoogleMercator(centerStartCoordinate);

            //double[] currentSouthWestCoordinate;
            //double[] currentNorthEastCoordinate;

            result.GridCellCoordinateSystem   = "GoogleMercator";
            result.GridCellCoordinateSystemId = 3;
            result.GridCellSize = gridSize;
            result.Cells        = new List <SpeciesObservationGridCellResult>();

            for (int i = 0; i < nrRows; i++)
            {
                for (int j = 0; j < nrColumns; j++)
                {
                    double[] mercatorCenterCoordinate = new double[] { mercatorCenterStartCoordinate[0] + (j * gridSize), mercatorCenterStartCoordinate[1] - (i * gridSize) };
                    double   halfGridSize             = gridSize / 2.0;

                    //double[] currentWestNorthCoordinate = Wgs84Util.TranslateCoordinate(leftUpperStartCoordinate, j * gridSize, -i * gridSize);
                    //double[] currentEastSouthCoordinate = Wgs84Util.TranslateCoordinate(currentWestNorthCoordinate, gridSize, -gridSize);
                    //double[] currentCentreCoordinate = Wgs84Util.TranslateCoordinate(currentWestNorthCoordinate, gridSize / 2.0, -gridSize / 2.0);

                    //double[] mercatorCurrentWestNorthCoordinate = Wgs84Util.WGS84ToGoogleMercator(currentWestNorthCoordinate);
                    //double[] mercatorCurrentEastSouthCoordinate = Wgs84Util.WGS84ToGoogleMercator(currentEastSouthCoordinate);
                    //double[] mercatorCurrentCentreCoordinate = Wgs84Util.WGS84ToGoogleMercator(currentCentreCoordinate);

                    var gridCell = new SpeciesObservationGridCellResult();
                    gridCell.CentreCoordinateX = mercatorCenterCoordinate[0];
                    gridCell.CentreCoordinateY = mercatorCenterCoordinate[1];
                    gridCell.CentreCoordinate  = mercatorCenterCoordinate;

                    gridCell.BoundingBox[0] = new[] { mercatorCenterCoordinate[0] - halfGridSize, mercatorCenterCoordinate[1] - halfGridSize };
                    gridCell.BoundingBox[2] = new[] { mercatorCenterCoordinate[0] + halfGridSize, mercatorCenterCoordinate[1] + halfGridSize };

                    gridCell.ObservationCount = _random.Next(0, 200);
                    result.Cells.Add(gridCell);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new grid cell result.
        /// </summary>
        /// <param name="gridCell">The grid cell object returned from web service.</param>
        public static SpeciesObservationGridCellResult Create(IGridCellSpeciesObservationCount gridCell)
        {
            var model = new SpeciesObservationGridCellResult();

            //model.WestSouthCoordinate = new double[] { gridCell.GridCellCentreCoordinate.X - gridCell.GridCellSize, gridCell.GridCellCentreCoordinate.Y - gridCell.GridCellSize };
            //model.EastNorthCoordinate = new double[] { gridCell.GridCellCentreCoordinate.X + gridCell.GridCellSize, gridCell.GridCellCentreCoordinate.Y + gridCell.GridCellSize };

            //model.WestSouthCoordinate = new double[] { gridCell.GridCellBoundingBox.LinearRings[0].Points[0].X, gridCell.GridCellBoundingBox.LinearRings[0].Points[0].Y };
            //model.EastNorthCoordinate = new double[] { gridCell.GridCellBoundingBox.LinearRings[0].Points[2].X, gridCell.GridCellBoundingBox.LinearRings[0].Points[2].Y };

            model.BoundingBox = new double[4][];
            if (gridCell.GridCellBoundingBox != null && gridCell.GridCellBoundingBox.LinearRings != null && gridCell.GridCellBoundingBox.LinearRings.Count > 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    IPoint point = gridCell.GridCellBoundingBox.LinearRings[0].Points[i];
                    model.BoundingBox[i] = new[] { point.X, point.Y };
                }
            }

            if (gridCell.OrginalGridCellBoundingBox != null && gridCell.OrginalGridCellBoundingBox.Min != null && gridCell.OrginalGridCellBoundingBox.Max != null)
            {
                model.OriginalBoundingBox = new double[, ]
                {
                    { gridCell.OrginalGridCellBoundingBox.Min.X, gridCell.OrginalGridCellBoundingBox.Min.Y },
                    { gridCell.OrginalGridCellBoundingBox.Max.X, gridCell.OrginalGridCellBoundingBox.Max.Y }
                };
            }

            if (gridCell.GridCellCentreCoordinate != null)
            {
                model.CentreCoordinate  = new[] { gridCell.GridCellCentreCoordinate.X, gridCell.GridCellCentreCoordinate.Y };
                model.CentreCoordinateX = gridCell.GridCellCentreCoordinate.X;
                model.CentreCoordinateY = gridCell.GridCellCentreCoordinate.Y;
            }

            model.OriginalCentreCoordinateX = gridCell.OrginalGridCellCentreCoordinate.X;
            model.OriginalCentreCoordinateY = gridCell.OrginalGridCellCentreCoordinate.Y;
            model.ObservationCount          = gridCell.ObservationCount;
            model.GridCellSize = gridCell.GridCellSize;
            model.Srid         = gridCell.GridCoordinateSystem.Srid();
            return(model);
        }
        /// <summary>
        /// Creates a Grid statistics result object.
        /// </summary>
        /// <param name="cells">Grid statistics cell list returned from web service.</param>
        /// <returns></returns>
        public static SpeciesObservationGridResult Create(IList <IGridCellSpeciesObservationCount> cells)
        {
            var model = new SpeciesObservationGridResult();

            model.Cells = new List <SpeciesObservationGridCellResult>();
            model.GridCellCoordinateSystem = "";

            if (cells == null || cells.Count == 0)
            {
                return(model);
            }

            model.GridCellSize = cells[0].GridCellSize;
            model.GridCellCoordinateSystemId = (int)cells[0].GridCoordinateSystem;
            model.GridCellCoordinateSystem   = cells[0].GridCoordinateSystem.ToString();
            foreach (GridCellSpeciesObservationCount gridCell in cells)
            {
                model.Cells.Add(SpeciesObservationGridCellResult.Create(gridCell));
            }
            return(model);
        }