Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //determine output and call build function
            if (m_imgSource != null && m_destination != null)
            {
                // get selected max zoom
                m_selectedLevel = m_zoomLevels.level[cboZoomSelect.SelectedIndex];

                if (generateZXYTiles(m_selectedLevel.zyxLevel))
                {
                    DialogResult dlgR = MessageBox.Show("Tiles created at " + m_destination, "Complete", MessageBoxButtons.OK);
                }
            }
        }
Пример #2
0
        public zoomLevels(Form1.projection projection)
        {
            level = new List <zoomLevel>();

            for (int i = 0; i < 24; i++)
            {
                zoomLevel currentLevel = new zoomLevel();
                currentLevel.zyxLevel = i;
                if (i - 1 >= 0)
                {
                    currentLevel.bingLevel = i - 1;
                }
                ;
                switch (projection)
                {
                case Form1.projection.Mercator:
                    currentLevel.pixelsX = Form1.c_TileSize * (int)Math.Pow(2, i);
                    currentLevel.tilesX  = currentLevel.pixelsX / Form1.c_TileSize;
                    break;

                case Form1.projection.Equirectangular:
                    currentLevel.pixelsX = (Form1.c_TileSize * (int)Math.Pow(2, i)) * 2;
                    currentLevel.tilesX  = (currentLevel.pixelsX / Form1.c_TileSize);
                    break;

                default:
                    break;
                }
                currentLevel.pixelsY = Form1.c_TileSize * (int)Math.Pow(2, i);
                currentLevel.tilesY  = currentLevel.pixelsY / Form1.c_TileSize;
                currentLevel.ResolutionPerPixelMi = 24901.0 / currentLevel.pixelsX;
                currentLevel.ResolutionPerPixelFt = 131477280.0 / currentLevel.pixelsX;
                currentLevel.ResolutionPerPixelKM = 40075.0 / currentLevel.pixelsX;
                currentLevel.ResolutionPerPixelM  = 40075000.0 / currentLevel.pixelsX;
                //if (Math.Max(currentLevel.pixelsX,currentLevel.pixelsY) <= Math.Pow(2,15)
                //{
                level.Add(currentLevel);
                //}
            }
            ;
        }
Пример #3
0
        private bool createTiles(ref Image imgCurrent, int intCurrXGroup, int intCurrYGroup, int intCurrentZ, zoomLevel currLevel)
        {
            int     intCurrentX         = 0;
            int     intCurrentY         = 0;
            int     intMaxLevelRow      = 0;
            int     intMaxLevelColumn   = 0;
            int     intCurrentTileCount = 0;
            string  zFolder             = "";
            string  xFolder             = "";
            string  yFile = "";
            string  saveFilePath;
            Boolean blnReturn = true;

            // update labels
            tbxProcessing.Text         = string.Format(m_strProcessingTemplate, intCurrentZ, m_selectedLevel.zyxLevel, m_strStepResize);
            progressProcessing.Visible = true;
            progressProcessing.Value   = 0;
            progressProcessing.Minimum = 0;
            progressProcessing.Maximum = currLevel.tilesX * currLevel.tilesY;

            // create zoom (z) folder
            zFolder      = intCurrentZ.ToString();
            saveFilePath = m_destination + "\\" + zFolder + "\\";
            createFolder(saveFilePath);

            intMaxLevelColumn = currLevel.tilesX;
            intMaxLevelRow    = currLevel.tilesY;

            for (intCurrentX = 0; intCurrentX < intMaxLevelColumn; intCurrentX++)
            {
                // create column (x) folder
                xFolder      = ((intCurrXGroup * currLevel.tilesX) + intCurrentX).ToString();
                saveFilePath = m_destination + "\\" + zFolder + "\\" + xFolder + "\\";
                createFolder(saveFilePath);

                for (intCurrentY = 0; intCurrentY < intMaxLevelRow; intCurrentY++)
                {
                    tbxProcessing.Text = string.Format(m_strProcessingTemplate, intCurrentZ, m_selectedLevel.zyxLevel, m_strStepTiles);

                    yFile = ((intCurrYGroup * currLevel.tilesY) + intCurrentY).ToString();
                    using (Image imgTile = cropImage(imgCurrent, intCurrentX, intCurrentY, c_TileSize, c_TileSize))
                    {
                        // save file
                        saveFilePath = m_destination + "\\" + zFolder + "\\" + xFolder + "\\" + yFile + m_saveExtenstion;
                        imgTile.Save(saveFilePath, m_saveFormat);
                    }

                    intCurrentTileCount++;
                    progressProcessing.Value = intCurrentTileCount;
                }
            }
            return(blnReturn);
        }
Пример #4
0
        private bool generateZXYTiles(int intMaxZoom)
        {
            Image     imgCurrent;
            zoomLevel currLevel, maxLevel = null;
            bool      blnReturn = true;
            int       intCurrentZ = 0;
            int       intMaxLevelRow = 0;
            int       intMaxLevelColumn = 0;
            int       intMaxGoodZoomLevel = 0;
            int       intGroupCountX = 0;
            int       intCurrXGroup = 0;
            int       intCurrYGroup = 0;
            int       tileXoffset, tileYoffset, tileXpixels, tileYpixels;
            bool      successfulResize = false;
            bool      foundMaxResize   = false;

            tbxError.Text = "";

            try
            {
                // find the maximum successful reize level possible
                if (!foundMaxResize)
                {
                    // find the maximum size that the image can be successfully resized to.
                    while (!successfulResize)
                    {
                        successfulResize = false;
                        for (int i = intMaxZoom; i > 0; i--)
                        {
                            try
                            {
                                // get zoom settings for test size
                                maxLevel = m_zoomLevels.level.Find(x => x.zyxLevel.Equals(i));

                                // resize
                                imgCurrent = resize(m_imgSource, maxLevel.pixelsX, maxLevel.pixelsY);

                                // successful resize, set result value
                                imgCurrent.Dispose();
                                intMaxGoodZoomLevel = i;
                                successfulResize    = true;
                                break;
                            }
                            catch
                            {
                                // resize failed, try next size smaller
                                successfulResize = false;
                            }
                        }
                        // quit if no zoom level works;
                        if (intMaxGoodZoomLevel == 0)
                        {
                            break;
                        }
                    }
                }

                for (intCurrentZ = 0; intCurrentZ <= intMaxZoom; intCurrentZ++)
                {
                    // resize image to zoom level
                    currLevel         = m_zoomLevels.level.Find(x => x.zyxLevel.Equals(intCurrentZ));
                    intMaxLevelColumn = currLevel.tilesX;
                    intMaxLevelRow    = currLevel.tilesY;

                    if (maxLevel.zyxLevel >= currLevel.zyxLevel)
                    {
                        intCurrXGroup  = 0;
                        intCurrYGroup  = 0;
                        imgCurrent     = resize(m_imgSource, currLevel.pixelsX, currLevel.pixelsY);
                        intGroupCountX = 0;
                        createTiles(ref imgCurrent, intCurrXGroup, intCurrYGroup, intCurrentZ, currLevel);
                        imgCurrent.Dispose();
                    }
                    else
                    {
                        // current level larger than max capable level, process in sections
                        intGroupCountX = (currLevel.tilesX / maxLevel.tilesX);
                        for (intCurrXGroup = 0; intCurrXGroup < intGroupCountX; intCurrXGroup++)
                        {
                            for (intCurrYGroup = 0; intCurrYGroup < intGroupCountX; intCurrYGroup++)
                            {
                                tileXoffset = intCurrXGroup;
                                tileYoffset = intCurrYGroup;
                                tileXpixels = (m_imgSource.Width / intGroupCountX);
                                tileYpixels = (m_imgSource.Height / intGroupCountX);

                                imgCurrent = cropImage(m_imgSource, tileXoffset, tileYoffset, tileXpixels, tileYpixels);
                                imgCurrent = resize(imgCurrent, maxLevel.pixelsX, maxLevel.pixelsY);
                                createTiles(ref imgCurrent, intCurrXGroup, intCurrYGroup, intCurrentZ, maxLevel);
                                imgCurrent.Dispose();
                            }
                        }
                    }
                }

                tbxProcessing.Text = "";
                //progressProcessing.Visible = false;
                //progressProcessing.Value = 0;
            }
            catch (Exception ex)
            {
                tbxError.Text = "Tile creation error" + Environment.NewLine + "message:" + Environment.NewLine + ex.Message + Environment.NewLine + "stackTrace:" + Environment.NewLine + ex.StackTrace;
                blnReturn     = false;
            }

            return(blnReturn);
        }