/// <summary>
        /// Creates the tile specified by level.
        /// </summary>
        /// <param name="level">
        /// Zoom level.
        /// </param>
        /// <param name="tileX">
        /// X tile coordinate.
        /// </param>
        /// <param name="tileY">
        /// Y tile coordinate.
        /// </param>
        public void Create(int level, int tileX, int tileY)
        {
            // Pre-compute tables to map from pixel position to global (longitude, latitude).
            // Map size at this level.
            double tileSize = (double)(((long)Constants.TileSize) << level);

            // Compute longitudes across the tile (px = 0 at left edge);
            double[] longitudes = new double[Constants.TileSize];
            long     pixelX     = checked (tileX * Constants.TileSize);

            for (int px = 0; px < Constants.TileSize; px++)
            {
                double x = ((pixelX + px) + 0.5) / tileSize;
                longitudes[px] = 360.0 * x - 180.0;
            }

            // Compute latitudes across the tile (py = 0 at top edge).
            double[] latitudes = new double[Constants.TileSize];
            long     pixelY    = checked (tileY * Constants.TileSize);

            for (int py = 0; py < Constants.TileSize; py++)
            {
                double y = 0.5 - (((pixelY + py) + 0.5) / tileSize);
                latitudes[py] = 90.0 - (360.0 * Math.Atan(Math.Exp(-y * 2.0 * Math.PI)) / Math.PI);
            }

            int[] colors   = new int[Constants.TileSize * Constants.TileSize];
            bool  hasData  = false;
            int   position = -1;

            for (int py = 0; py < Constants.TileSize; py++)
            {
                for (int px = 0; px < Constants.TileSize; px++)
                {
                    // Map geo location to an ARGB value.
                    Color color = this.ColorMap.GetColor(longitudes[px], latitudes[py]);

                    // Store and update bit indicating whether actual data is present or not.
                    position++;
                    colors[position] = color.ToArgb();
                    if (hasData == false)
                    {
                        hasData = (color != Color.Transparent);
                    }
                }
            }

            if (hasData)
            {
                TileHelper.ToBitmap(level, tileX, tileY, colors, this.TileSerializer);
            }

            colors     = null;
            longitudes = null;
            latitudes  = null;
        }
Beispiel #2
0
        /// <summary>
        /// Creates base tiles and the pyramid.
        /// </summary>
        /// <param name="level">
        /// Zoom level.
        /// </param>
        /// <param name="tileX">
        /// X tile coordinate.
        /// </param>
        /// <param name="tileY">
        /// Y tile coordinate.
        /// </param>
        public void Create(int level, int tileX, int tileY)
        {
            // Size of the image to extract before scaling it down to (side x side)
            int    tileSize = Constants.TileSize * (int)Math.Pow(2, MaximumLevelsOfDetail - level);
            Bitmap tile     = this.ExtractTile((tileX * tileSize), (tileY * tileSize), tileSize);

            if (tile != null)
            {
                if (tileSize > Constants.TileSize)
                {
                    tile = TileHelper.ResizeBitmap(tile, Constants.TileSize, Constants.TileSize);
                }

                this.TileSerializer.Serialize(tile, level, tileX, tileY);
            }
        }
        /// <summary>
        /// Creates a DEM tile creator instance for the specified projection type.
        /// </summary>
        /// <param name="map">
        /// Color map used.
        /// </param>
        /// <param name="projectionType">
        /// Projection type desired.
        /// </param>
        /// <param name="path">
        /// Location where the tiles should be serialized.
        /// </param>
        /// <returns>
        /// ITileCreator instance.
        /// </returns>
        public static ITileCreator CreateImageTileCreator(IColorMap map, ProjectionTypes projectionType, string path)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            IImageTileSerializer serializer = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(path), ImageFormat.Png);

            return(CreateImageTileCreator(map, projectionType, serializer));
        }
Beispiel #4
0
        private void Initialize(Bitmap bitmap)
        {
            this.imageWidth  = bitmap.Width;
            this.imageHeight = bitmap.Height;

            // Compute the maximum level of detail that this image supports.
            // This is a function of size of the image.
            this.MaximumLevelsOfDetail = TileHelper.CalculateMaximumLevel(this.imageHeight, this.imageWidth, this.inputBoundary);

            // Get starting pixel values for x and y
            Helper.LatLongToPixelXY(this.inputBoundary.Bottom, this.inputBoundary.Left, this.MaximumLevelsOfDetail, out startX, out startY);

            // Get ending pixel values for x and y
            Helper.LatLongToPixelXY(this.inputBoundary.Top, this.inputBoundary.Right, this.MaximumLevelsOfDetail, out endX, out endY);

            // Get image data
            this.imageData = TileHelper.BitmapToBytes(bitmap);
        }
Beispiel #5
0
        /// <summary>
        /// Creates the tile specified by level.
        /// </summary>
        /// <param name="level">
        /// Zoom level.
        /// </param>
        /// <param name="tileX">
        /// X tile coordinate.
        /// </param>
        /// <param name="tileY">
        /// Y tile coordinate.
        /// </param>
        public void Create(int level, int tileX, int tileY)
        {
            // Map to convert from pixel position to global (longitude, latitude).
            OctTileMap tileMap = new OctTileMap(level, tileX, tileY);

            int[] colors   = new int[Constants.TileSize * Constants.TileSize];
            bool  hasData  = false;
            int   position = -1;

            for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++)
            {
                for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++)
                {
                    // Map pixel (u, v) position to (longitude, latitude).
                    double   u         = (0.5 + pixelX) / ((double)Constants.TileSize);
                    double   v         = (0.5 + pixelY) / ((double)Constants.TileSize);
                    Vector2d location  = tileMap.PointToRaDec(new Vector2d(u, v));
                    double   latitude  = location.Y;
                    double   longitude = location.X;

                    // For Toast projection, Longitude spans from 0 to +360 and latitude from +90 to -90.
                    // So we need to convert from -180 to +180 => 0 to +360.
                    longitude -= 180.0;

                    // Map geo location to an ARGB value.
                    Color color = this.ColorMap.GetColor(longitude, latitude);

                    // Store and update bit indicating whether actual data is present or not.
                    position++;
                    colors[position] = color.ToArgb();
                    if (hasData == false)
                    {
                        hasData = (color != Color.Transparent);
                    }
                }
            }

            if (hasData)
            {
                TileHelper.ToBitmap(level, tileX, tileY, colors, this.TileSerializer);
            }

            colors = null;
        }
Beispiel #6
0
        public static void ToBitmap(int level, int tileX, int tileY, int[] values, IImageTileSerializer serializer, IImageTileSerializer referenceImageSerializer)
        {
            byte[] referenceImage = null;
            using (Bitmap image = new Bitmap(Constants.TileSize, Constants.TileSize, PixelFormat.Format32bppArgb))
            {
                // Set the data row by row
                Rectangle  dimension = new Rectangle(0, 0, Constants.TileSize, Constants.TileSize);
                BitmapData imageData = image.LockBits(dimension, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                byte[]     rgb       = new byte[imageData.Stride];
                int        position  = -1;

                if (referenceImageSerializer != null)
                {
                    referenceImage = TileHelper.BitmapToBytes(referenceImageSerializer.Deserialize(level, tileX, tileY));
                }

                for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++)
                {
                    Array.Clear(rgb, 0, rgb.Length);
                    int   pos            = 0;
                    Color referenceColor = Color.White;
                    for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++)
                    {
                        Color color = Color.Transparent;
                        position++;
                        if (referenceImage != null)
                        {
                            if (referenceImage != null &&
                                referenceImage[(position * 4)] == referenceColor.B &&
                                referenceImage[(position * 4) + 1] == referenceColor.G &&
                                referenceImage[(position * 4) + 2] == referenceColor.R)
                            {
                                if (values != null)
                                {
                                    color = Color.FromArgb(values[position]);
                                }
                            }
                        }
                        else
                        {
                            if (values != null)
                            {
                                color = Color.FromArgb(values[position]);
                            }
                        }

                        rgb[pos++] = color.B;
                        rgb[pos++] = color.G;
                        rgb[pos++] = color.R;
                        rgb[pos++] = color.A;
                    }

                    IntPtr p = new IntPtr(imageData.Scan0.ToInt64() + (pixelY * imageData.Stride));
                    System.Runtime.InteropServices.Marshal.Copy(rgb, 0, p, rgb.Length);
                }

                image.UnlockBits(imageData);
                if (serializer != null)
                {
                    serializer.Serialize(image, level, tileX, tileY);
                }

                imageData = null;
                rgb       = null;
            }
        }
Beispiel #7
0
 public static void ToBitmap(int level, int tileX, int tileY, int[] values, IImageTileSerializer serializer)
 {
     TileHelper.ToBitmap(level, tileX, tileY, values, serializer, null);
 }
Beispiel #8
0
 /// <summary>
 /// Aggregates lower level image tiles to construct upper level tiles.
 /// </summary>
 /// <param name="level">
 /// Zoom level.
 /// </param>
 /// <param name="tileX">
 /// X coordinate.
 /// </param>
 /// <param name="tileY">
 /// Y coordinate.
 /// </param>
 public void CreateParent(int level, int tileX, int tileY)
 {
     TileHelper.CreateParent(level, tileX, tileY, this.TileSerializer);
 }