Beispiel #1
0
 private void CreateChildren()
 {
     children     = new QTNode[4];
     children[TL] = new QTNode(RectangleD.FromLTRB(_bounds.Left, _bounds.Top, 0.5 * (_bounds.Left + _bounds.Right), 0.5 * (_bounds.Top + _bounds.Bottom)), Level + 1);
     children[TR] = new QTNode(RectangleD.FromLTRB(0.5 * (_bounds.Left + _bounds.Right), _bounds.Top, _bounds.Right, 0.5 * (_bounds.Top + _bounds.Bottom)), Level + 1);
     children[BL] = new QTNode(RectangleD.FromLTRB(_bounds.Left, 0.5 * (_bounds.Top + _bounds.Bottom), 0.5 * (_bounds.Left + _bounds.Right), _bounds.Bottom), Level + 1);
     children[BR] = new QTNode(RectangleD.FromLTRB(0.5 * (_bounds.Left + _bounds.Right), 0.5 * (_bounds.Top + _bounds.Bottom), _bounds.Right, _bounds.Bottom), Level + 1);
 }
Beispiel #2
0
        public static RectangleD GetTileLatLonBounds(int tileX, int tileY, int zoomLevel, int tileSize = 256)
        {
            if (zoomLevel < 0)
            {
                throw new System.ArgumentException("zoomLevel must be >=0", "zoomLevel");
            }
            PointD topLeft     = PixelToLL((tileX * tileSize), (tileY * tileSize), zoomLevel, tileSize);
            PointD bottomRight = PixelToLL(((tileX + 1) * tileSize), ((tileY + 1) * tileSize), zoomLevel, tileSize);

            return(RectangleD.FromLTRB(topLeft.X, bottomRight.Y, bottomRight.X, topLeft.Y));
        }
Beispiel #3
0
 public static RectangleD Transform(this EGIS.Projections.ICoordinateTransformation @this, RectangleD rect, Projections.TransformDirection direction = Projections.TransformDirection.Forward)
 {
     double[] pts = new double[8];
     pts[0] = rect.Left; pts[1] = rect.Bottom;
     pts[2] = rect.Right; pts[3] = rect.Bottom;
     pts[4] = rect.Right; pts[5] = rect.Top;
     pts[6] = rect.Left; pts[7] = rect.Top;
     @this.Transform(pts, 4, direction);
     return(RectangleD.FromLTRB(Math.Min(pts[0], pts[6]),
                                Math.Min(pts[5], pts[7]), Math.Max(pts[2], pts[4]),
                                Math.Max(pts[1], pts[3])));
 }
Beispiel #4
0
 public static RectangleD Transform(this RectangleD @this, ICoordinateTransformation transformation)
 {
     double[] pts = new double[8];
     pts[0] = @this.Left; pts[1] = @this.Bottom;
     pts[2] = @this.Right; pts[3] = @this.Bottom;
     pts[4] = @this.Right; pts[5] = @this.Top;
     pts[6] = @this.Left; pts[7] = @this.Top;
     transformation.Transform(pts, 4);
     return(RectangleD.FromLTRB(Math.Min(pts[0], pts[6]),
                                Math.Min(pts[5], pts[7]), Math.Max(pts[2], pts[4]),
                                Math.Max(pts[1], pts[3])));
 }
        public static RectangleD Transform(this EGIS.Projections.ICoordinateTransformation @this, RectangleD rect, Projections.TransformDirection direction = Projections.TransformDirection.Forward)
        {
            //following code was derived from code in QGIS TransformBoundingBox function in QgsCoordinateTransform
            //improves calculated bounding box after transforming to a different CRS when
            //only using the corners of the rectangle will not give an accurate result when transforming to some CRS.
            //This method creates a grid of points over the input rectangle,
            //transforms these points and then calculates the target bounding box from these points.

            const int nPoints  = 1000;
            double    t        = Math.Pow(Math.Sqrt((double)nPoints) - 1, 2.0);
            double    d        = Math.Sqrt((rect.Width * rect.Height) / Math.Pow(Math.Sqrt((double)nPoints) - 1, 2.0));
            int       nXPoints = (int)Math.Min(Math.Ceiling(rect.Width / d) + 1, 1000);
            int       nYPoints = (int)Math.Min(Math.Ceiling(rect.Height / d) + 1, 1000);

            int totalPoints = (nXPoints * nYPoints);

            PointD[] pts = new PointD[totalPoints];

            double dx = rect.Width / (double)(nXPoints - 1);
            double dy = rect.Height / (double)(nYPoints - 1);

            double pointY = rect.Top;
            int    index  = 0;

            for (int i = nYPoints; i > 0; --i)
            {
                double pointX = rect.Left;
                for (int j = nXPoints; j > 0; --j)
                {
                    pts[index].X   = pointX;
                    pts[index++].Y = pointY;
                    pointX        += dx;
                }
                pointY += dy;
            }
            @this.Transform(pts, direction);
            double minX = double.PositiveInfinity, maxX = double.NegativeInfinity, minY = double.PositiveInfinity, maxY = double.NegativeInfinity;

            for (int n = totalPoints - 1; n >= 0; --n)
            {
                if (double.IsInfinity(pts[n].X) || double.IsInfinity(pts[n].Y))
                {
                    continue;
                }
                minX = Math.Min(pts[n].X, minX);
                minY = Math.Min(pts[n].Y, minY);
                maxX = Math.Max(pts[n].X, maxX);
                maxY = Math.Max(pts[n].Y, maxY);
            }
            return(RectangleD.FromLTRB(minX, minY, maxX, maxY));
        }
Beispiel #6
0
        public static RectangleD Transform(this RectangleD @this, ICRS source, ICRS target)
        {
            if (source == null || target == null || source.IsEquivalent(target))
            {
                return(@this);
            }
            using (ICoordinateTransformation transformation = CoordinateReferenceSystemFactory.Default.CreateCoordinateTrasformation(source, target))
            {
                double[] pts = new double[8];
                pts[0] = @this.Left; pts[1] = @this.Bottom;
                pts[2] = @this.Right; pts[3] = @this.Bottom;
                pts[4] = @this.Right; pts[5] = @this.Top;
                pts[6] = @this.Left; pts[7] = @this.Top;
                transformation.Transform(pts, 4);

                return(RectangleD.FromLTRB(Math.Min(pts[0], pts[6]),
                                           Math.Min(pts[5], pts[7]), Math.Max(pts[2], pts[4]),
                                           Math.Max(pts[1], pts[3])));
            }
        }