Beispiel #1
0
        public virtual string GetLocalPath(QuadTile qt)
        {
            if (qt.Level >= m_levelCount)
            {
                throw new ArgumentException(string.Format("Level {0} not available.",
                                                          qt.Level));
            }

            string relativePath = String.Format(@"{0}\{1:D4}\{1:D4}_{2:D4}.{3}",
                                                qt.Level, qt.Row, qt.Col, m_imageFileExtension);

            if (m_dataDirectory != null)
            {
                // Search data directory first
                string rawFullPath = Path.Combine(m_dataDirectory, relativePath);
                if (File.Exists(rawFullPath))
                {
                    return(rawFullPath);
                }
            }

            // If cache doesn't exist, fall back to duplicate texture path.
            if (m_cacheDirectory == null)
            {
                return(m_duplicateTexturePath);
            }

            // Try cache with default file extension
            string cacheFullPath = Path.Combine(m_cacheDirectory, relativePath);

            if (File.Exists(cacheFullPath))
            {
                return(cacheFullPath);
            }

            // Try cache but accept any valid image file extension
            const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

            string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);

            if (Directory.Exists(cacheSearchPath))
            {
                foreach (string imageFile in Directory.GetFiles(
                             cacheSearchPath,
                             Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                {
                    string extension = Path.GetExtension(imageFile).ToLower();
                    if (ValidExtensions.IndexOf(extension) < 0)
                    {
                        continue;
                    }

                    return(imageFile);
                }
            }

            return(cacheFullPath);
        }
Beispiel #2
0
        static private Stream CacheCallback(DataRequestDescriptor drd)
        {
            lock (m_cacheLock)
            {
                // search for any files that could be used to fulfill the request.
                if (drd.CacheLocation == null)
                {
                    return(null);
                }

                // Try cache with default file extension
                string cacheFullPath = drd.CacheLocation;
                if (File.Exists(cacheFullPath))
                {
                    return(new FileStream(cacheFullPath, FileMode.Open));
                }

                // Try cache but accept any valid image file extension
                const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

                // if (allowCache)
                {
                    string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);
                    if (Directory.Exists(cacheSearchPath))
                    {
                        foreach (string imageFile in Directory.GetFiles(
                                     cacheSearchPath,
                                     Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                        {
                            string extension = Path.GetExtension(imageFile).ToLower();
                            if (ValidExtensions.IndexOf(extension) > 0)
                            {
                                return(new FileStream(imageFile, FileMode.Open));
                            }
                        }
                    }
                }

                // no stream found for this data request.
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns a path to be used for local storage of the tile
        /// Checks through various places before just assinging to cache, in this order.
        /// If it finds a tile in any of these places, it immediately returns the path.
        /// 1. The "Data" directory (if existent), under its folder structure
        /// 2. If the QTS doesn't have a cache directory, it just returns the m_duplicateTexturePath
        /// 3. If it has a cache directory, first with the default file extension, then checks for others
        /// 4. If not found in any of these, it simply constructs the path
        ///    from cache directory and default extension, and returns that path
        ///
        /// This method also checks for tiles in the old, pre-1.4.1 cache structure if it can't find it
        /// in the new WWJ format.  If it can't find it in the old structure, it returns a WWJ-style
        /// path to store a new tile in.
        /// </summary>
        public virtual string GetLocalPath(QuadTile qt)
        {
            if (qt.Level >= this.m_levelCount)
            {
                throw new ArgumentException(string.Format("Level {0} not available.",
                                                          qt.Level));
            }

            //List of cache structures to try, in order of preference
            string[] patternArray =
            {
                @"{0}\{1:D1}\{1:D1}_{2:D1}.{3}",
                @"{0}\{1:D4}\{1:D4}_{2:D4}.{3}"
            };

            foreach (string relativePattern in patternArray)
            {
                //Try each pattern through
                string relativePath = String.Format(relativePattern,
                                                    qt.Level, qt.Row, qt.Col, this.m_imageFileExtension);

                if (this.m_dataDirectory != null)
                {
                    // Search data directory first
                    string rawFullPath = Path.Combine(this.m_dataDirectory, relativePath);
                    if (File.Exists(rawFullPath))
                    {
                        return(rawFullPath);
                    }
                }

                // If cache doesn't exist, fall back to duplicate texture path.
                if (this.m_cacheDirectory == null)
                {
                    return(this.m_duplicateTexturePath);
                }

                // Try cache with default file extension
                string cacheFullPath = Path.Combine(this.m_cacheDirectory, relativePath);
                if (File.Exists(cacheFullPath))
                {
                    return(cacheFullPath);
                }

                // Try cache but accept any valid image file extension
                const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

                string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);
                if (Directory.Exists(cacheSearchPath))
                {
                    foreach (string imageFile in Directory.GetFiles(
                                 cacheSearchPath,
                                 Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                    {
                        string extension = Path.GetExtension(imageFile).ToLower();
                        if (ValidExtensions.IndexOf(extension) < 0)
                        {
                            continue;
                        }

                        return(imageFile);
                    }
                }
            }

            //If it's not anywhere in cache, use the first (preferred) pattern, in the cache directory
            string defaultPath = String.Format(patternArray[0],
                                               qt.Level, qt.Row, qt.Col, this.m_imageFileExtension);
            string defaultFullPath = Path.Combine(this.m_cacheDirectory, defaultPath);

            return(defaultFullPath);
        }
Beispiel #4
0
        public ImageTileInfo GetImageTileInfo(int level, int row, int col, bool allowCache)
        {
            if (level >= m_numberLevels)
            {
                throw new ArgumentException("Level " + level.ToString() + " not available.");
            }

            string relativePath = String.Format(@"{0}\{1:D4}\{1:D4}_{2:D4}.{3}", level, row, col, m_imageFileExtension);

            if (m_dataDirectory != null)
            {
                // Search data directory first
                string rawFullPath = Path.Combine(m_dataDirectory, relativePath);
                if (File.Exists(rawFullPath))
                {
                    return(new ImageTileInfo(rawFullPath));
                }
            }

            // Try cache with default file extension
            string cacheFullPath = Path.Combine(m_cacheDirectory, relativePath);

            if (File.Exists(cacheFullPath))
            {
                return(new ImageTileInfo(cacheFullPath));
            }

            // Try cache but accept any valid image file extension
            const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

            if (allowCache)
            {
                string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);
                if (Directory.Exists(cacheSearchPath))
                {
                    foreach (string imageFile in Directory.GetFiles(
                                 cacheSearchPath,
                                 Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                    {
                        string extension = Path.GetExtension(imageFile).ToLower();
                        if (ValidExtensions.IndexOf(extension) < 0)
                        {
                            continue;
                        }

                        if (m_imageTileService != null)
                        {
                            return(new ImageTileInfo(
                                       imageFile,
                                       m_imageTileService.GetImageTileServiceUri(level, row, col)));
                        }

                        if (m_wmsLayerAccessor != null)
                        {
                            double tileRange = m_levelZeroTileSizeDegrees * Math.Pow(0.5, level);
                            double west      = -180.0 + col * tileRange;
                            double south     = -90.0 + row * tileRange;

                            string fileUri = m_wmsLayerAccessor.GetWMSRequestUrl(
                                west, south, west + tileRange, south + tileRange,
                                m_textureSizePixels, m_textureSizePixels);

                            return(new ImageTileInfo(imageFile, fileUri));
                        }

                        return(new ImageTileInfo(imageFile));
                    }
                }
            }

            if (m_imageTileService != null)
            {
                return(new ImageTileInfo(
                           cacheFullPath,
                           m_imageTileService.GetImageTileServiceUri(level, row, col)));
            }

            if (m_wmsLayerAccessor != null)
            {
                double tileRange = m_levelZeroTileSizeDegrees * Math.Pow(0.5, level);
                double west      = -180.0 + col * tileRange;
                double south     = -90.0 + row * tileRange;

                string fileUri = m_wmsLayerAccessor.GetWMSRequestUrl(
                    west, south, west + tileRange, south + tileRange,
                    m_textureSizePixels, m_textureSizePixels);

                return(new ImageTileInfo(Path.Combine(m_cacheDirectory, relativePath), fileUri));
            }

            // No success, return our "duplicate" tile if any
            if (m_duplicateTexturePath != null && File.Exists(m_duplicateTexturePath))
            {
                return(new ImageTileInfo(m_duplicateTexturePath,
                                         Path.Combine(m_cacheDirectory, m_duplicateTexturePath)));
            }

            return(null);
            //throw new ApplicationException("No image access method available.");
        }
Beispiel #5
0
        /// <summary>
        /// 获取切片的本地存放路径或缓存存放路径
        /// </summary>
        /// <param name="qt"></param>
        /// <returns></returns>
        public virtual string GetLocalPath(int Level, int Row, int Col)
        {
            //判断请求的层数,是否超出了范围
            if (Level >= m_levelCount)
            {
                throw new ArgumentException(string.Format("层 {0} 不可用.",
                                                          Level));
            }

            //获得请求的相对路径
            //string relativePath = String.Format(@"{0}\{1:D4}\{1:D4}_{2:D4}.{3}",
            //    qt.Level, qt.Row, qt.Col, m_imageFileExtension);
            string relativePath = String.Format(@"{0}\{1}\{1}_{2}",
                                                Level, Row, Col);

            //判断m_dataDirectory路径是否存在
            if (m_dataDirectory != null)
            {
                // Search data directory first
                string rawFullPath = Path.Combine(m_dataDirectory, relativePath);
                if (File.Exists(rawFullPath + ".dds"))
                {
                    return(rawFullPath + ".dds");
                }
                else if (File.Exists(rawFullPath + ".jpg"))
                {
                    return(rawFullPath + ".jpg");
                }
                else if (File.Exists(rawFullPath + ".png"))
                {
                    return(rawFullPath + ".png");
                }
                else if (File.Exists(rawFullPath + ".bil"))
                {
                    return(rawFullPath + ".bil");
                }
                else if (File.Exists(rawFullPath + ".tif"))
                {
                    return(rawFullPath + ".tif");
                }
                else if (File.Exists(rawFullPath + ".bmp"))
                {
                    return(rawFullPath + ".bmp");
                }
                else if (File.Exists(rawFullPath + ".dib"))
                {
                    return(rawFullPath + ".dib");
                }
                else if (File.Exists(rawFullPath + ".hdr"))
                {
                    return(rawFullPath + ".hdr");
                }
                else if (File.Exists(rawFullPath + ".jpeg"))
                {
                    return(rawFullPath + ".jpeg");
                }
                else if (File.Exists(rawFullPath + ".pfm"))
                {
                    return(rawFullPath + ".pfm");
                }
                else if (File.Exists(rawFullPath + ".ppm"))
                {
                    return(rawFullPath + ".ppm");
                }
                else if (File.Exists(rawFullPath + ".gif"))
                {
                    return(rawFullPath + ".gif");
                }
                else if (File.Exists(rawFullPath + ".tga"))
                {
                    return(rawFullPath + ".tga");
                }
            }

            //若缓存路径不存在,则返回默认纹理的路径
            // If cache doesn't exist, fall back to duplicate texture path.
            if (m_cacheDirectory == null)
            {
                return(m_duplicateTexturePath);
            }

            //获得Cache的存放全部路径
            // Try cache with default file extension
            string cacheFullPath = Path.Combine(m_cacheDirectory, relativePath);

            if (File.Exists(cacheFullPath + ".jpg"))
            {
                return(cacheFullPath + ".jpg");
            }
            else if (File.Exists(cacheFullPath + ".png"))
            {
                return(cacheFullPath + ".png");
            }
            else if (File.Exists(cacheFullPath + ".dds"))
            {
                return(cacheFullPath + ".dds");
            }
            else if (File.Exists(cacheFullPath + ".bil"))
            {
                return(cacheFullPath + ".bil");
            }
            else if (File.Exists(cacheFullPath + ".tif"))
            {
                return(cacheFullPath + ".tif");
            }
            else if (File.Exists(cacheFullPath + ".bmp"))
            {
                return(cacheFullPath + ".bmp");
            }
            else if (File.Exists(cacheFullPath + ".dib"))
            {
                return(cacheFullPath + ".dib");
            }
            else if (File.Exists(cacheFullPath + ".hdr"))
            {
                return(cacheFullPath + ".hdr");
            }
            else if (File.Exists(cacheFullPath + ".jpeg"))
            {
                return(cacheFullPath + ".jpeg");
            }
            else if (File.Exists(cacheFullPath + ".pfm"))
            {
                return(cacheFullPath + ".pfm");
            }
            else if (File.Exists(cacheFullPath + ".ppm"))
            {
                return(cacheFullPath + ".ppm");
            }
            else if (File.Exists(cacheFullPath + ".gif"))
            {
                return(cacheFullPath + ".gif");
            }
            else if (File.Exists(cacheFullPath + ".tga"))
            {
                return(cacheFullPath + ".tga");
            }

            // Try cache but accept any valid image file extension
            const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

            string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);

            if (Directory.Exists(cacheSearchPath))
            {
                foreach (string imageFile in Directory.GetFiles(
                             cacheSearchPath,
                             Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                {
                    string extension = Path.GetExtension(imageFile).ToLower();
                    if (ValidExtensions.IndexOf(extension) < 0)
                    {
                        continue;
                    }

                    return(imageFile);
                }
            }

            return("");
        }