/// <summary>
        /// Returns the metafile reader located based on the naming pattern.
        /// </summary>
        /// <param name="path">The path including the naming pattern.</param>
        /// <returns>The metafile reader located at the specified path if available; otherwise, <c>null</c>.</returns>
        private static GeoTiffMetafileReader GetReaderFromSearchPattern(String path)
        {
            GeoTiffMetafileReader reader     = null;
            FileSystem            fileSystem = FileSystem.GetFileSystemForPath(path);
            String fileNamePattern           = fileSystem.GetFileName(path);
            String directory = fileSystem.GetDirectory(path);

            String[] filePaths = fileSystem.GetFiles(directory, fileNamePattern, false);

            // check for matching paths
            foreach (MetafileFormat format in _readers.Keys)
            {
                foreach (String filePath in filePaths)
                {
                    if (format.IsMatchingName(filePath) && (reader = GetReader(filePath, format)) != null)
                    {
                        return(reader);
                    }
                }
            }

            // check for all paths
            foreach (MetafileFormat format in _readers.Keys)
            {
                foreach (String filePath in filePaths)
                {
                    if ((reader = GetReader(filePath, format)) != null)
                    {
                        return(reader);
                    }
                }
            }

            return(reader);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoTiffGroupReader" /> class.
        /// </summary>
        /// <param name="basePath">The base path.</param>
        /// <param name="parameters">The parameters of the reader for the specific stream.</param>
        /// <exception cref="System.ArgumentNullException">The collection of file paths is null.</exception>
        public GeoTiffGroupReader(IEnumerable <String> filePaths, IDictionary <GeometryStreamParameter, Object> parameters)
            : base(SpectralGeometryStreamFormats.GeoTiff, parameters)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("basePath", "The collection of file paths is null.");
            }

            _filePaths = filePaths.Where(filePath => filePath.ToLower().EndsWith(".tif")).ToList();

            Boolean includeMetadata = ResolveParameter <Boolean>(SpectralGeometryStreamParameters.IncludeMetadata);

            if (includeMetadata)
            {
                foreach (String path in filePaths.Where(filePath => !filePath.ToLower().EndsWith(".tif")))
                {
                    _metafileReader = GeoTiffMetafileReaderFactory.CreateReader(path, GeoTiffMetafilePathOption.IsMetafilePath);

                    if (_metafileReader != null)
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Returns the metafile reader located based on the GeoTIFF path.
        /// </summary>
        /// <param name="path">The path of the GeoTIFF file.</param>
        /// <returns>The metafile reader located at the specified path if available; otherwise, <c>null</c>.</returns>
        private static GeoTiffMetafileReader GetReaderFromGeoTiffFileName(String path)
        {
            GeoTiffMetafileReader reader     = null;
            FileSystem            fileSystem = FileSystem.GetFileSystemForPath(path);
            String directory = fileSystem.GetDirectory(path);

            // search the extension
            foreach (MetafileFormat format in _readers.Keys)
            {
                String[] filePaths = new String[]
                {
                    fileSystem.Combine(directory, fileSystem.GetFileNameWithoutExtension(path) + "." + format.DefaultExtension.ToLower()),
                    fileSystem.Combine(directory, fileSystem.GetFileNameWithoutExtension(path) + "." + format.DefaultExtension.ToUpper())
                };

                foreach (String filePath in filePaths)
                {
                    if (fileSystem.Exists(filePath) && (reader = GetReader(filePath, format)) != null)
                    {
                        return(reader);
                    }
                }
            }

            // search the directory
            return(GetReaderInDirectory(directory));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoTiffReader" /> class.
        /// </summary>
        /// <param name="path">The file path to be read.</param>
        /// <param name="parameters">The parameters of the reader for the specific stream.</param>
        /// <exception cref="System.ArgumentException">
        /// The path is empty.
        /// or
        /// The path is invalid.
        /// or
        /// The type of a parameter value does not match the type specified by the format.
        /// or
        /// The parameter value does not satisfy the conditions of the parameter.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// Exception occurred during stream opening.
        /// or
        /// Exception occurred during stream reading.
        /// </exception>
        public GeoTiffReader(Uri path, IDictionary <GeometryStreamParameter, Object> parameters)
            : base(path, SpectralGeometryStreamFormats.GeoTiff, parameters)
        {
            Boolean includeMetadata = ResolveParameter <Boolean>(SpectralGeometryStreamParameters.IncludeMetadata);

            if (includeMetadata)
            {
                _metafileReader = GeoTiffMetafileReaderFactory.CreateReader(path, GeoTiffMetafilePathOption.IsGeoTiffFilePath);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoTiffReader" /> class.
        /// </summary>
        /// <param name="path">The file path to be read.</param>
        /// <exception cref="System.ArgumentException">
        /// The path is empty.
        /// or
        /// The path is invalid.
        /// or
        /// The type of a parameter value does not match the type specified by the format.
        /// or
        /// The parameter value does not satisfy the conditions of the parameter.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// Exception occurred during stream opening.
        /// or
        /// Exception occurred during stream reading.
        /// </exception>
        public GeoTiffReader(String path)
            : base(path, SpectralGeometryStreamFormats.GeoTiff, null)
        {
            Boolean includeMetadata = ResolveParameter <Boolean>(SpectralGeometryStreamParameters.IncludeMetadata);

            if (includeMetadata)
            {
                _metafileReader = GeoTiffMetafileReaderFactory.CreateReader(path, GeoTiffMetafilePathOption.IsGeoTiffFilePath);
            }
        }
        /// <summary>
        /// Returns the metafile reader located at the specified directory.
        /// </summary>
        /// <param name="path">The path of the directory.</param>
        /// <returns>The metafile reader located at the specified path if available; otherwise, <c>null</c>.</returns>
        private static GeoTiffMetafileReader GetReaderInDirectory(String path)
        {
            GeoTiffMetafileReader reader     = null;
            FileSystem            fileSystem = FileSystem.GetFileSystemForPath(path);

            // try the default file name
            foreach (MetafileFormat format in _readers.Keys)
            {
                if (format.HasDefaultFileName)
                {
                    String filePath = fileSystem.Combine(path, format.DefaultFileName);

                    if (fileSystem.Exists(filePath) && (reader = GetReader(filePath, format)) != null)
                    {
                        return(reader);
                    }
                }
            }

            // try the default naming pattern and extension
            foreach (MetafileFormat format in _readers.Keys)
            {
                if (format.HasDefaultNamingPattern)
                {
                    foreach (String filePath in fileSystem.GetFiles(path, format.DefaultNamingPattern, false))
                    {
                        if ((reader = GetReader(filePath, format)) != null)
                        {
                            return(reader);
                        }
                    }
                }
            }

            // try the default extension
            foreach (MetafileFormat format in _readers.Keys)
            {
                if (format.HasDefaultNamingPattern)
                {
                    foreach (String filePath in fileSystem.GetFiles(path, format.DefaultExtension.ToLower(), false).
                             Concat(fileSystem.GetFiles(path, format.DefaultExtension.ToUpper(), false)))
                    {
                        if ((reader = GetReader(filePath, format)) != null)
                        {
                            return(reader);
                        }
                    }
                }
            }

            return(reader);
        }
        /// <summary>
        /// Returns the metafile reader located at the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>The metafile reader located at the specified path if available; otherwise, <c>null</c>.</returns>
        private static GeoTiffMetafileReader GetReader(String path)
        {
            GeoTiffMetafileReader reader = null;

            foreach (MetafileFormat format in _readers.Keys)
            {
                if ((reader = GetReader(path, format)) != null)
                {
                    return(reader);
                }
            }

            return(reader);
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeoTiffGroupReader" /> class.
        /// </summary>
        /// <param name="basePath">The base path.</param>
        /// <param name="parameters">The parameters of the reader for the specific stream.</param>
        /// <exception cref="System.ArgumentNullException">The base path is null.</exception>
        public GeoTiffGroupReader(String basePath, IDictionary <GeometryStreamParameter, Object> parameters)
            : base(SpectralGeometryStreamFormats.GeoTiff, parameters)
        {
            if (basePath == null)
            {
                throw new ArgumentNullException("basePath", "The base path is null.");
            }

            Boolean includeMetadata = ResolveParameter <Boolean>(SpectralGeometryStreamParameters.IncludeMetadata);

            FileSystem fileSystem = FileSystem.GetFileSystemForPath(basePath);

            _filePaths = new List <String>();

            // the base path is a directory
            if (fileSystem.IsDirectory(basePath))
            {
                if (includeMetadata)
                {
                    _metafileReader = GeoTiffMetafileReaderFactory.CreateReader(basePath, GeoTiffMetafilePathOption.IsDirectoryPath);
                }

                if (_metafileReader != null)
                {
                    // load files from the path specified by the metafile
                    List <String> filePaths = _metafileReader.ReadFilePaths().Select(path => fileSystem.Combine(basePath, path)).ToList();

                    // check whether the specified files exist
                    foreach (String filePath in filePaths)
                    {
                        if (fileSystem.Exists(filePath))
                        {
                            _filePaths.Add(filePath);
                        }
                    }
                }

                if (_filePaths.Count == 0)
                {
                    _filePaths = fileSystem.GetFiles(basePath, "*.tif", false).Union(fileSystem.GetFiles(basePath, "*.TIF", false)).ToList();
                }
            }
            else
            {
                String directoryPath = fileSystem.GetDirectory(basePath);
                String fileNameBase  = fileSystem.GetFileNameWithoutExtension(basePath);
                String extension     = fileSystem.GetExtension(basePath);

                if (includeMetadata)
                {
                    _metafileReader = GeoTiffMetafileReaderFactory.CreateReader(fileSystem.Combine(directoryPath, fileNameBase + "*"), GeoTiffMetafilePathOption.IsSearchPattern);
                }

                if (_metafileReader != null)
                {
                    _filePaths = _metafileReader.ReadFilePaths().Select(path => fileSystem.Combine(directoryPath, path)).ToList();
                }
                else
                {
                    _filePaths = fileSystem.GetFiles(directoryPath, fileNameBase + "*" + extension, false).ToList();
                }
            }
        }