Пример #1
0
        protected DataRasterReader findDataRasterReader(Object source, AVList parameters)
        {
            if (source == null)
            {
                String message = Logging.getMessage("nullValue.SourceIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            parameters = (null == parameters) ? new AVListImpl() : parameters;

            DataRasterReader reader = this.readerFactory.findReaderFor(source, parameters);

            if (reader == null)
            {
                return(null);
            }

            if (!params.hasKey(AVKey.PIXEL_FORMAT))
            {
                try
                {
                    reader.readMetadata(source, parameters);
                }
                catch (Exception e)
                {
                    // Reading the input source's metadata caused an exception. This exception does not prevent us from
                    // determining if the source represents elevation data, but we want to make a note of it. Therefore we
                    // log the exception with level FINE.
                    String message = Logging.getMessage("generic.ExceptionWhileReading", source);
                    Logging.logger().finest(message);
                }
            }

            return(reader);
        }
Пример #2
0
        /**
         * Reads XML document and extracts raster sources
         *
         * @param config Parsed configuration document.
         *
         * @return TRUE, if all raster sources are available, FALSE otherwise
         *
         */
        protected bool readRasterSources(RasterServerConfiguration config)
        {
            long startTime = System.currentTimeMillis();

            bool hasUnavailableRasterSources = false;

            int    numSources = 0;
            Sector extent     = null;

            try
            {
                List <RasterServerConfiguration.Source> sources = config.getSources();

                if (sources == null || sources.size() == 0)
                {
                    return(false);
                }

                numSources = sources.size();
                foreach (RasterServerConfiguration.Source source in sources)
                {
                    Thread.yield();
                    try
                    {
                        String rasterSourcePath = source.getPath();
                        if (WWUtil.isEmpty(rasterSourcePath))
                        {
                            continue;
                        }

                        AVList rasterMetadata   = new AVListImpl();
                        File   rasterSourceFile = new File(rasterSourcePath);
                        // normalize
                        rasterSourcePath = rasterSourceFile.getAbsolutePath();

                        if (!rasterSourceFile.exists())
                        {
                            hasUnavailableRasterSources = true;
                            String reason = Logging.getMessage("generic.FileDoesNotExists", rasterSourcePath);
                            Logging.logger().warning(reason);
                            continue;
                        }

                        if (!rasterSourceFile.canRead())
                        {
                            hasUnavailableRasterSources = true;
                            String reason = Logging.getMessage("generic.FileNoReadPermission", rasterSourcePath);
                            Logging.logger().warning(reason);
                            continue;
                        }

                        DataRasterReader rasterReader = this.findDataRasterReader(rasterSourceFile, rasterMetadata);
                        if (null == rasterReader)
                        {
                            hasUnavailableRasterSources = true;
                            String reason = Logging.getMessage("generic.UnknownFileFormatOrMatchingReaderNotFound",
                                                               rasterSourcePath);
                            Logging.logger().warning(reason);
                            continue;
                        }

                        Sector sector = source.getSector();
                        if (null == sector)
                        {
                            rasterReader.readMetadata(rasterSourceFile, rasterMetadata);

                            Object o = rasterMetadata.getValue(AVKey.SECTOR);
                            sector = (o is Sector) ? (Sector)o : null;
                        }
                        else
                        {
                            rasterMetadata.setValue(AVKey.SECTOR, sector);
                        }

                        Object rasterPixelFormat  = rasterMetadata.getValue(AVKey.PIXEL_FORMAT);
                        String datasetPixelFormat = this.getDataSetPixelFormat();

                        if (!WWUtil.isEmpty(datasetPixelFormat))
                        {
                            // verify all data rasters are the same type - we do not allow to mix elevations and imagery
                            if (!datasetPixelFormat.Equals(rasterPixelFormat))
                            {
                                hasUnavailableRasterSources = true;
                                String reason = Logging.getMessage("generic.UnexpectedRasterType", rasterSourcePath);
                                Logging.logger().warning(reason);
                                continue;
                            }
                        }
                        else
                        {
                            if (AVKey.IMAGE.Equals(rasterPixelFormat) || AVKey.ELEVATION.Equals(rasterPixelFormat))
                            {
                                this.setDataSetPixelFormat((String)rasterPixelFormat);
                            }
                            else
                            {
                                hasUnavailableRasterSources = true;
                                String reason = Logging.getMessage("generic.UnknownFileFormat", rasterSourcePath);
                                Logging.logger().warning(reason);
                                continue;
                            }
                        }

                        if (null != sector)
                        {
                            extent = Sector.union(extent, sector);
                            this.dataRasterList.add(
                                new CachedDataRaster(rasterSourceFile, rasterMetadata, rasterReader, this.getCache())
                                );
                        }
                        else
                        {
                            hasUnavailableRasterSources = true;
                            String reason = Logging.getMessage("generic.NoSectorSpecified", rasterSourcePath);
                            Logging.logger().warning(reason);
                        }
                    }
                    catch (Throwable t)
                    {
                        String message = t.getMessage();
                        message = (WWUtil.isEmpty(message)) ? t.getCause().getMessage() : message;
                        Logging.logger().log(java.util.logging.Level.WARNING, message, t);
                    }
                }

                if (null != extent && extent.getDeltaLatDegrees() > 0d && extent.getDeltaLonDegrees() > 0d)
                {
                    this.setValue(AVKey.SECTOR, extent);
                }
            }
            catch (Throwable t)
            {
                String message = t.getMessage();
                message = (WWUtil.isEmpty(message)) ? t.getCause().getMessage() : message;
                Logging.logger().log(java.util.logging.Level.SEVERE, message, t);
            }
            finally
            {
                Logging.logger().finest(this.getStringValue(AVKey.DISPLAY_NAME) + ": " + numSources
                                        + " files in " + (System.currentTimeMillis() - startTime) + " milli-seconds");
            }

            return(!hasUnavailableRasterSources);
        }
Пример #3
0
 /**
  * Create a cached data raster.
  *
  * @param source the location of the local file, expressed as either a String path, a File, or a file URL.
  * @param parameters metadata as AVList, it is expected to next parameters: AVKey.WIDTH, AVKey.HEIGHT, AVKey.SECTOR,
  *               AVKey.PIXEL_FORMAT.
  *               <p/>
  *               If any of these keys is missing, there will be an attempt made to retrieve missign metadata from
  *               the source using the reader.
  * @param reader A reference to a DataRasterReader instance
  * @param cache  A reference to a MemoryCache instance
  *
  * @throws java.io.IOException      thrown if there is an error to read metadata from the source
  * @throws ArgumentException thrown when a source or a reader are null
  */
 public CachedDataRaster(Object source, AVList parameters, DataRasterReader reader, MemoryCache cache)