Ejemplo n.º 1
0
        private void _WriteTiles(int Level, int idOverview, KMLBuildOptions options)
        {
            int nTileX = 0, nTileY = 0, nPixelRemTileX, nPixelRemTileY;

            // nTile          -> number of tile with value
            // nPixelRemTileX -> Remainder pixel before nTile

            if (idOverview == -1) // Original
            {
                nTileX = Math.DivRem(_ds.RasterXSize, options.TileSize, out nPixelRemTileX);
                nTileY = Math.DivRem(_ds.RasterYSize, options.TileSize, out nPixelRemTileY);
            }
            else
            {
                nTileX = Math.DivRem(_ds.GetRasterBand(1).GetOverview(idOverview).XSize, options.TileSize, out nPixelRemTileX);
                nTileY = Math.DivRem(_ds.GetRasterBand(1).GetOverview(idOverview).YSize, options.TileSize, out nPixelRemTileY);
            }

            options.ShowStatus(string.Format("Level {0} TileX 0->{1} TileY 0->{2} ...", Level, nTileX, nTileY));
            options.Progressed(0, nTileX, 1, 0);

            // Pixels with full values in TileSize
            for (int idGridX = 0; idGridX < nTileX; idGridX++)
            {
                options.Progressed(0, 0, 0, idGridX);
                for (int idGridY = 0; idGridY < nTileY; idGridY++)
                {
                    WriteTileEach(Level, idOverview, idGridX, idGridY, options.TileSize, options.TileSize, options);
                }
            }

            // Pixels without full values in TileSize
            if (nPixelRemTileX > 0)
            {
                options.ShowStatus(string.Format("Level {0} Remainder TileX 0->{1} ...", Level, nTileY));
                options.Progressed(0, nTileY, 1, 0);
                for (int idGridY = 0; idGridY < nTileY; idGridY++)
                {
                    options.Progressed(0, 0, 0, idGridY);
                    WriteTileEach(Level, idOverview, nTileX, idGridY, nPixelRemTileX, options.TileSize, options);
                }
            }

            if (nPixelRemTileY > 0)
            {
                options.ShowStatus(string.Format("Level {0} Remainder TileY 0->{1} ...", Level, nTileX));
                options.Progressed(0, nTileX, 1, 0);
                for (int idGridX = 0; idGridX < nTileX; idGridX++)
                {
                    options.Progressed(0, 0, 0, idGridX);
                    WriteTileEach(Level, idOverview, idGridX, nTileY, options.TileSize, nPixelRemTileY, options);
                }
            }

            if (nPixelRemTileX > 0 && nPixelRemTileY > 0)
            {
                options.ShowStatus("Remainder TileX & TileY ...");
                WriteTileEach(Level, idOverview, nTileX, nTileY, nPixelRemTileX, nPixelRemTileY, options);
            }
        }
Ejemplo n.º 2
0
        public void Write(KMLBuildOptions options)
        {
            int nLevel = GlobalMercator.GetTotalLevel(options.TileSize, _ds.RasterXSize, _ds.RasterYSize);

            _SetOverviewSameLevel(nLevel);

            // Original: idOverview = -1 and Level is Max
            _WriteTiles(nLevel, -1, options);
            // int Level, int idOverview, int[] Order, int SizeTile, string sNameDirTile

            // Next Levels
            for (int i = 0; i < nLevel; i++)
            {
                _WriteTiles(nLevel - (i + 1), i, options);
            }
        }
Ejemplo n.º 3
0
        private void WriteTileEachDS(int idOverview, ref Dataset dsOut, int xoff, int yoff, int xsize, int ysize, KMLBuildOptions options)
        {
            byte[] pixelsTile = new byte[options.TileSize * options.TileSize];

            byte[] pixelsAlpha = new byte[0];
            if (options.HaveAlphaBand)
            {
                pixelsAlpha = null;
                pixelsAlpha = new byte[options.TileSize * options.TileSize];
            }

            int idOrder = 0;

            for (int id = 0; id < _ds.RasterCount; id++)
            {
                Band bdOut = dsOut.GetRasterBand(id + 1);

                idOrder = options.HaveBandsOrder ? options.BandsOrder[id] : id + 1;

                Band bdIn = (idOverview != -1) ? _ds.GetRasterBand(idOrder).GetOverview(idOverview) : _ds.GetRasterBand(idOrder);

                if (xsize == options.TileSize)
                {
                    bdIn.ReadRaster(xoff, yoff, xsize, ysize, pixelsTile, xsize, ysize, 0, 0);
                    if (options.HaveStretchStardDesv)
                    {
                        ImageProcessing.SetStretchStardDevi(bdIn, ref pixelsTile, options.StretchStardDesvNum);
                    }
                }
                else
                {
                    byte[] pixels = new byte[xsize * ysize];
                    bdIn.ReadRaster(xoff, yoff, xsize, ysize, pixels, xsize, ysize, 0, 0);
                    if (options.HaveStretchStardDesv)
                    {
                        ImageProcessing.SetStretchStardDevi(bdIn, ref pixels, options.StretchStardDesvNum);
                    }

                    for (int iy = 0; iy < ysize; iy++)
                    {
                        System.Buffer.BlockCopy(pixels, iy * xsize, pixelsTile, iy * options.TileSize, xsize);
                    }
                }
                bdOut.WriteRaster(0, 0, options.TileSize, options.TileSize, pixelsTile, options.TileSize, options.TileSize, 0, 0);

                if (options.HaveAlphaBand)
                {
                    ImageProcessing.PopulateAlphaPixels(ref pixelsTile, ref pixelsAlpha);
                }

                bdOut.FlushCache(); bdIn.FlushCache();
                bdIn.Dispose(); bdOut.Dispose();
            }

            if (options.HaveAlphaBand)
            {
                Band bdAlpha = dsOut.GetRasterBand(_ds.RasterCount + 1);
                bdAlpha.WriteRaster(0, 0, options.TileSize, options.TileSize, pixelsAlpha, options.TileSize, options.TileSize, 0, 0);
                bdAlpha.FlushCache();
                bdAlpha.Dispose();
            }
        }
Ejemplo n.º 4
0
        private void WriteTileEach(int Level, int idOverview, int idGridX, int idGridY, int nPixelX, int nPixelY, KMLBuildOptions options)
        {
            int xoff = idGridX * options.TileSize;
            int yoff = idGridY * options.TileSize;

            Dataset dsOut = CreatePngDataset(idOverview, xoff, yoff, options.TileSize, options.HaveAlphaBand);

            WriteTileEachDS(idOverview, ref dsOut, xoff, yoff, nPixelX, nPixelY, options);

            if (options.HaveNullData)
            {
                _SetNullDataImage(dsOut, options.NullDataValue);
            }

            // Tiles: sPath\$[level]_$[y]_$[x].png
            string sPathNameTile = string.Format("{0}\\{1}_{2}_{3}.png", options.OutPath, Level, idGridX, idGridY);

            _DatasetPng2File(dsOut, sPathNameTile);

            dsOut.FlushCache();
            dsOut.Dispose();
        }