Пример #1
0
        internal static void ConvertHGTZIPsToHGTZIP(ISector sector, string rootFolder, bool overwrite)
        {
            string outputPath = Path.Combine(rootFolder, sector.GetAllParents().Where(x => x.Zoom == 4).Single().ToString(), sector.ToString() + ".HGT.ZIP");

            if (!overwrite && File.Exists(outputPath))
            {
                return;
            }
            int[,] shorts = ConvertHGTZIPsToShorts(sector);
            byte[] outputBytes = new byte[REZ * REZ * 2];
            for (int x = 0; x < REZ; x++)
            {
                for (int y = 0; y < REZ; y++)
                {
                    outputBytes[(REZ * y + x) * 2]     = (byte)(shorts[x, y] / 256);
                    outputBytes[(REZ * y + x) * 2 + 1] = (byte)(shorts[x, y] % 256);
                }
            }
            string directoryName = Path.GetDirectoryName(outputPath);

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            Compression.ZipToFile(outputPath, outputBytes);
        }
Пример #2
0
 private void RebuildImage(GraphicsDevice graphicsDevice, ISector sector)
 {
     // combination images
     using (Texture2D rendered = new RenderTarget2D(graphicsDevice, 512, 512, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24))
     {
         int highestZoom = ZCoords.GetSectorManager().GetHighestCacheZoom();
         foreach (var parent in sector.GetAllParents().OrderBy(x => - x.Zoom).Where(x => x.Zoom <= highestZoom))
         {
             List <ISector> roadSectors = parent.GetChildrenAtLevel(parent.Zoom == highestZoom - 1 ? ZCoords.GetSectorManager().GetHighestOSMZoom() : parent.Zoom + 1);
             Texture2D[]    textures    = new Texture2D[roadSectors.Count];
             for (int i = 0; i < roadSectors.Count; i++)
             {
                 IGraphicsBuffer buffer = null;
                 if (File.Exists(OSMPaths.GetSectorImagePath(roadSectors[i])))
                 {
                     using (var reader = File.OpenRead(OSMPaths.GetSectorImagePath(roadSectors[i])))
                     {
                         buffer = new ImageTileBuffer(graphicsDevice, Texture2D.FromStream(graphicsDevice, reader), roadSectors[i]);
                     }
                 }
                 else
                 {
                     throw new NotImplementedException();
                 }
                 textures[i] = buffer.GetImage(graphicsDevice);
             }
             if (textures.Any(x => x != null))
             {
                 graphicsDevice.SetRenderTarget((RenderTarget2D)rendered);
                 for (int i = 0; i < roadSectors.Count; i++)
                 {
                     int size, x, y;
                     size = 512 >> (roadSectors[i].Zoom - parent.Zoom);
                     x    = parent.GetRelativeXOf(roadSectors[i]) * size;
                     y    = parent.GetRelativeYOf(roadSectors[i]) * size;
                     if (textures[i] != null)
                     {
                         GraphicsBasic.DrawSpriteRect(graphicsDevice, x, y, size, size, textures[i], BlendState.AlphaBlend, Microsoft.Xna.Framework.Color.White);
                     }
                 }
             }
             for (int i = 0; i < textures.Length; i++)
             {
                 if (textures[i] != null && textures[i] != GlobalContent.Error)
                 {
                     textures[i].Dispose();
                 }
             }
             SuperSave(rendered, OSMPaths.GetSectorImagePath(parent));
         }
     }
 }