Exemple #1
0
            protected URLBuilder(String version, AVList parameters)
            {
                Double d = (Double)parameters.getValue(AVKey.MISSING_DATA_SIGNAL);

                this.layerNames  = parameters.getStringValue(AVKey.LAYER_NAMES);
                this.styleNames  = parameters.getStringValue(AVKey.STYLE_NAMES);
                this.imageFormat = parameters.getStringValue(AVKey.IMAGE_FORMAT);

                String coordSystemKey;
                String defaultCS;

                if (version == null || WWUtil.compareVersion(version, "1.3.0") >= 0) // version 1.3.0 or greater
                {
                    this.wmsVersion = MAX_VERSION;
                    coordSystemKey  = "&crs=";
                    defaultCS       = "CRS:84"; // would like to do EPSG:4326 but that's incompatible with our old WMS server, see WWJ-474
                }
                else
                {
                    this.wmsVersion = version;
                    coordSystemKey  = "&srs=";
                    defaultCS       = "EPSG:4326";
                }

                String coordinateSystem = parameters.getStringValue(AVKey.COORDINATE_SYSTEM);

                this.crs = coordSystemKey + (coordinateSystem != null ? coordinateSystem : defaultCS);
            }
Exemple #2
0
        public static bool?getBooleanValue(AVList avList, string key)
        {
            object o = avList.getValue(key);

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

            if (o is bool)
            {
                return((bool)o);
            }

            if (!(o is string))
            {
                return(null);
            }

            string text = (string)o;
            bool   result;

            if (bool.TryParse(text, out result))
            {
                return(result);
            }
            Logging.logger().log(Level.SEVERE, "Configuration.ConversionError", new Exception().Message);
            return(null);
        }
Exemple #3
0
        public static double?getDoubleValue(AVList avList, string key)
        {
            object o = avList.getValue(key);

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

            if (o is double)
            {
                return((double)o);
            }

            string v = getStringValue(avList, key);

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

            try
            {
                return(double.Parse(v));
            }
            catch (Exception e)
            {
                Logging.logger().log(Level.SEVERE, "Configuration.ConversionError", v);
                return(null);
            }
        }
        public static DataRaster wrap(BufferedImage image, AVList parameters)
        {
            if (null == image)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (null == parameters)
            {
                String msg = Logging.getMessage("nullValue.AVListIsNull");
                Logging.logger().finest(msg);
                throw new ArgumentException(msg);
            }

            if (params.hasKey(AVKey.WIDTH))
            {
                int width = (Integer)parameters.getValue(AVKey.WIDTH);
                if (width != image.getWidth())
                {
                    String msg = Logging.getMessage("generic.InvalidWidth", "" + width + "!=" + image.getWidth());
                    Logging.logger().finest(msg);
                    throw new ArgumentException(msg);
                }
            }
        protected static AVList wcsGetParamsFromCapsDoc(WCS100Capabilities caps, AVList parameters)
        {
            if (caps == null)
            {
                String message = Logging.getMessage("nullValue.WCSCapabilities");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (parameters == null)
            {
                String message = Logging.getMessage("nullValue.ElevationModelConfigParams");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            WCS100DescribeCoverage coverage = (WCS100DescribeCoverage)parameters.getValue(AVKey.DOCUMENT);

            if (coverage == null)
            {
                String message = Logging.getMessage("nullValue.WCSDescribeCoverage");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            getWCSElevationModelConfigParams(caps, coverage, parameters);

            wcsSetFallbacks(parameters);
            determineNumLevels(coverage, parameters);

            parameters.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder(caps.getVersion(), parameters));

            if (parameters.getValue(AVKey.ELEVATION_EXTREMES_FILE) == null)
            {
                // Use the default extremes file if there are at least as many levels in this new elevation model as the
                // level of the extremes file, which is level 5.
                int numLevels = (int)parameters.getValue(AVKey.NUM_LEVELS);
                if (numLevels >= 6)
                {
                    parameters.setValue(AVKey.ELEVATION_EXTREMES_FILE, "config/SRTM30Plus_ExtremeElevations_5.bil");
                }
            }

            return(parameters);
        }
        protected static void wcsSetFallbacks(AVList parameters)
        {
            if (parameters.getValue(AVKey.LEVEL_ZERO_TILE_DELTA) == null)
            {
                Angle delta = Angle.fromDegrees(20);
                parameters.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(delta, delta));
            }

            if (parameters.getValue(AVKey.TILE_WIDTH) == null)
            {
                parameters.setValue(AVKey.TILE_WIDTH, 150);
            }

            if (parameters.getValue(AVKey.TILE_HEIGHT) == null)
            {
                parameters.setValue(AVKey.TILE_HEIGHT, 150);
            }

            if (parameters.getValue(AVKey.FORMAT_SUFFIX) == null)
            {
                parameters.setValue(AVKey.FORMAT_SUFFIX, ".tif");
            }

            if (parameters.getValue(AVKey.MISSING_DATA_SIGNAL) == null)
            {
                parameters.setValue(AVKey.MISSING_DATA_SIGNAL, -9999d);
            }

            if (parameters.getValue(AVKey.NUM_LEVELS) == null)
            {
                parameters.setValue(AVKey.NUM_LEVELS, 18); // approximately 20 cm per pixel
            }
            if (parameters.getValue(AVKey.NUM_EMPTY_LEVELS) == null)
            {
                parameters.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
            }

            if (parameters.getValue(AVKey.ELEVATION_MIN) == null)
            {
                parameters.setValue(AVKey.ELEVATION_MIN, -11000.0);
            }

            if (parameters.getValue(AVKey.ELEVATION_MAX) == null)
            {
                parameters.setValue(AVKey.ELEVATION_MAX, 8850.0);
            }
        }
        protected static void determineNumLevels(WCS100DescribeCoverage coverage, AVList parameters)
        {
            List <GMLRectifiedGrid> grids =
                coverage.getCoverageOfferings().get(0).getDomainSet().getSpatialDomain().getRectifiedGrids();

            if (grids.Count < 1 || grids[0].getOffsetVectors().Count < 2)
            {
                parameters.setValue(AVKey.NUM_LEVELS, 18);
                return;
            }

            double xRes           = Math.Abs(grids[0].getOffsetVectors().get(0).x);
            double yRes           = Math.Abs(grids[0].getOffsetVectors().get(1).y);
            double dataResolution = Math.Min(xRes, yRes);

            int    tileSize    = (int)parameters.getValue(AVKey.TILE_WIDTH);
            LatLon level0Delta = (LatLon)parameters.getValue(AVKey.LEVEL_ZERO_TILE_DELTA);

            double n = Math.Log(level0Delta.getLatitude().degrees / (dataResolution * tileSize)) / Math.Log(2);

            parameters.setValue(AVKey.NUM_LEVELS, (int)(Math.Ceiling(n) + 1));
        }
        public static AVList getWCSElevationModelConfigParams(WCS100Capabilities caps, WCS100DescribeCoverage coverage,
                                                              AVList parameters)
        {
            DataConfigurationUtils.getWCSConfigParameters(caps, coverage, parameters); // checks for null args

            // Ensure that we found all the necessary information.
            if (parameters.getStringValue(AVKey.DATASET_NAME) == null)
            {
                Logging.logger().warning(Logging.getMessage("WCS.NoCoverageName"));
                throw new WWRuntimeException(Logging.getMessage("WCS.NoCoverageName"));
            }

            if (parameters.getStringValue(AVKey.SERVICE) == null)
            {
                Logging.logger().warning(Logging.getMessage("WCS.NoGetCoverageURL"));
                throw new WWRuntimeException(Logging.getMessage("WCS.NoGetCoverageURL"));
            }

            if (parameters.getStringValue(AVKey.DATA_CACHE_NAME) == null)
            {
                Logging.logger().warning(Logging.getMessage("nullValue.DataCacheIsNull"));
                throw new WWRuntimeException(Logging.getMessage("nullValue.DataCacheIsNull"));
            }

            if (parameters.getStringValue(AVKey.IMAGE_FORMAT) == null)
            {
                Logging.logger().severe("WCS.NoImageFormats");
                throw new WWRuntimeException(Logging.getMessage("WCS.NoImageFormats"));
            }

            if (parameters.getValue(AVKey.SECTOR) == null)
            {
                Logging.logger().severe("WCS.NoLonLatEnvelope");
                throw new WWRuntimeException(Logging.getMessage("WCS.NoLonLatEnvelope"));
            }

            if (parameters.getStringValue(AVKey.COORDINATE_SYSTEM) == null)
            {
                String msg = Logging.getMessage("WCS.RequiredCRSNotSupported", "EPSG:4326");
                Logging.logger().severe(msg);
                throw new WWRuntimeException(msg);
            }

            return(parameters);
        }
Exemple #9
0
        protected bool doCanRead(Object source, AVList parameters)
        {
            File file = this.getFile(source);

            if (null == file)
            {
                return(false);
            }

            // Assume that a proper suffix reliably identifies a DTED file. Otherwise the file will have to be loaded
            // to determine that, and there are often tens of thousands of DTED files, which causes raster server start-up
            // times to be excessive.
            if (this.canReadSuffix(source))
            {
                parameters.setValue(AVKey.PIXEL_FORMAT, AVKey.ELEVATION); // we know that DTED is elevation data
                return(true);
            }

            bool canRead = false;

            try
            {
                AVList metadata = DTED.readMetadata(file);
                if (null != metadata)
                {
                    if (null != parameters)
                    {
                        parameters.setValues(metadata);
                    }

                    canRead = AVKey.ELEVATION.Equals(metadata.getValue(AVKey.PIXEL_FORMAT));
                }
            }
            catch (Throwable t)
            {
                Logging.logger().finest(t.getMessage());
                canRead = false;
            }

            return(canRead);
        }
Exemple #10
0
        //**************************************************************//
        //********************  Configuration  *************************//
        //**************************************************************//

        /**
         * Parses WMSBasicElevationModel configuration parameters from a specified WMS Capabilities source. This writes
         * output as key-value pairs to parameters. Supported key and parameter names are: <table>
         * <th><td>Parameter</td><td>Value</td><td>Type</td></th> <tr><td>{@link AVKey#ELEVATION_MAX}</td><td>WMS layer's
         * maximum extreme elevation</td><td>Double</td></tr> <tr><td>{@link AVKey#ELEVATION_MIN}</td><td>WMS layer's
         * minimum extreme elevation</td><td>Double</td></tr> <tr><td>{@link AVKey#DATA_TYPE}</td><td>Translate WMS layer's
         * image format to a matching data type</td><td>String</td></tr> </table> This also parses common WMS layer
         * parameters by invoking {@link DataConfigurationUtils#getWMSLayerConfigParams(gov.nasa.worldwind.ogc.wms.WMSCapabilities,
         * String[], SharpEarth.avlist.AVList)}.
         *
         * @param caps                  the WMS Capabilities source to parse for WMSBasicElevationModel configuration
         *                              parameters.
         * @param formatOrderPreference an ordered array of preferred image formats, or null to use the default format.
         * @param parameters                the output key-value pairs which recieve the WMSBasicElevationModel configuration
         *                              parameters.
         *
         * @return a reference to parameters.
         *
         * @throws ArgumentException if either the document or parameters are null, or if parameters does not contain the
         *                                  required key-value pairs.
         * @throws SharpEarth.exception.WWRuntimeException
         *                                  if the Capabilities document does not contain any of the required information.
         */
        public static AVList getWMSElevationModelConfigParams(WMSCapabilities caps, String[] formatOrderPreference,
                                                              AVList parameters)
        {
            if (caps == null)
            {
                String message = Logging.getMessage("nullValue.WMSCapabilities");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (parameters == null)
            {
                String message = Logging.getMessage("nullValue.ElevationModelConfigParams");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // Get common WMS layer parameters.
            DataConfigurationUtils.getWMSLayerConfigParams(caps, formatOrderPreference, parameters);

            // Attempt to extract the WMS layer names from the specified parameters.
            String layerNames = parameters.getStringValue(AVKey.LAYER_NAMES);

            if (layerNames == null || layerNames.Length == 0)
            {
                String message = Logging.getMessage("nullValue.WMSLayerNames");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            String[] names = layerNames.Split(',');
            if (names == null || names.Length == 0)
            {
                String message = Logging.getMessage("nullValue.WMSLayerNames");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // Get the layer's extreme elevations.
            Double[] extremes = caps.getLayerExtremeElevations(names);

            Double d = (Double)parameters.getValue(AVKey.ELEVATION_MIN);

            if (d == null && extremes != null && extremes[0] != null)
            {
                parameters.setValue(AVKey.ELEVATION_MIN, extremes[0]);
            }

            d = (Double)parameters.getValue(AVKey.ELEVATION_MAX);
            if (d == null && extremes != null && extremes[1] != null)
            {
                parameters.setValue(AVKey.ELEVATION_MAX, extremes[1]);
            }

            // Compute the internal pixel type from the image format.
            if (parameters.getValue(AVKey.DATA_TYPE) == null && parameters.getValue(AVKey.IMAGE_FORMAT) != null)
            {
                String s = WWIO.makeDataTypeForMimeType(parameters.getValue(AVKey.IMAGE_FORMAT).ToString());
                if (s != null)
                {
                    parameters.setValue(AVKey.DATA_TYPE, s);
                }
            }

            // Use the default data type.
            if (parameters.getValue(AVKey.DATA_TYPE) == null)
            {
                parameters.setValue(AVKey.DATA_TYPE, AVKey.INT16);
            }

            // Use the default byte order.
            if (parameters.getValue(AVKey.BYTE_ORDER) == null)
            {
                parameters.setValue(AVKey.BYTE_ORDER, AVKey.LITTLE_ENDIAN);
            }

            return(parameters);
        }
Exemple #11
0
        public LevelSet(AVList parameters)
        {
            StringBuffer sb = new StringBuffer();

            Object o = parameters.getValue(AVKey.LEVEL_ZERO_TILE_DELTA);

            if (o == null || !(o is LatLon))
            {
                sb.append(Logging.getMessage("term.tileDelta")).append(" ");
            }

            o = parameters.getValue(AVKey.SECTOR);
            if (o == null || !(o is Sector))
            {
                sb.append(Logging.getMessage("term.sector")).append(" ");
            }

            int numLevels = 0;

            o = parameters.getValue(AVKey.NUM_LEVELS);
            if (o == null || !(o is Integer) || (numLevels = (Integer)o) < 1)
            {
                sb.append(Logging.getMessage("term.numLevels")).append(" ");
            }

            int numEmptyLevels = 0;

            o = parameters.getValue(AVKey.NUM_EMPTY_LEVELS);
            if (o != null && o is Integer && (Integer)o > 0)
            {
                numEmptyLevels = (Integer)o;
            }

            String[] inactiveLevels = null;
            o = parameters.getValue(AVKey.INACTIVE_LEVELS);
            if (o != null && !(o is String))
            {
                sb.append(Logging.getMessage("term.inactiveLevels")).append(" ");
            }
            else if (o != null)
            {
                inactiveLevels = ((String)o).split(",");
            }

            SectorResolution[] sectorLimits = null;
            o = parameters.getValue(AVKey.SECTOR_RESOLUTION_LIMITS);
            if (o != null && !(o is SectorResolution[]))
            {
                sb.append(Logging.getMessage("term.sectorResolutionLimits")).append(" ");
            }
            else if (o != null)
            {
                sectorLimits = (SectorResolution[])o;
                foreach (SectorResolution sr in sectorLimits)
                {
                    if (sr.levelNumber > numLevels - 1)
                    {
                        String message =
                            Logging.getMessage("LevelSet.sectorResolutionLimitsTooHigh", sr.levelNumber, numLevels - 1);
                        Logging.logger().warning(message);
                        break;
                    }
                }
            }
            this.sectorLevelLimits = sectorLimits;

            if (sb.length() > 0)
            {
                String message = Logging.getMessage("layers.LevelSet.InvalidLevelDescriptorFields", sb.ToString());
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            this.sector             = (Sector)parameters.getValue(AVKey.SECTOR);
            this.levelZeroTileDelta = (LatLon)parameters.getValue(AVKey.LEVEL_ZERO_TILE_DELTA);

            o = parameters.getValue(AVKey.TILE_ORIGIN);
            if (o != null && o is LatLon)
            {
                this.tileOrigin = (LatLon)o;
            }
            else
            {
                this.tileOrigin = new LatLon(Angle.NEG90, Angle.NEG180);
            }

            parameters = parameters.copy(); // copy so as not to modify the user's parameters

            TileUrlBuilder tub = (TileUrlBuilder)parameters.getValue(AVKey.TILE_URL_BUILDER);

            if (tub == null)
            {
                parameters.setValue(AVKey.TILE_URL_BUILDER, new TileUrlBuilder()
                {