/**
         * Returns true if the specified file store path can be opened as an XML document, and calling {@link
         * #accept(org.w3c.dom.Document)} returns true.
         *
         * @param fileStore the file store containing the named file path.
         * @param fileName  the named file path in question.
         *
         * @return true if the file name should be accepted; false otherwise.
         *
         * @throws ArgumentException if either the file store or the file name are null.
         */
        public bool accept(FileStore fileStore, String fileName)
        {
            if (fileStore == null)
            {
                String msg = Logging.getMessage("nullValue.FileStoreIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

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

            // Attempt to locate the named path in the FileStore, optionally checking the class path. If a file with that
            // name cannot be located, then return false.
            java.net.URL url = fileStore.findFile(fileName, true);
            if (url == null)
            {
                return(false);
            }

            // Attempt to convert the URL to a local file path. If that succeeds, then continue treating the URL as if
            // it were a File.
            java.io.File file = WWIO.convertURLToFile(url);
            if (file != null)
            {
                return(this.accept(file));
            }

            return(this.accept(url));
        }
Exemplo n.º 2
0
        protected void loadOffsetFile()
        {
            InputStream inputStream = WWIO.openFileOrResourceStream(this.offsetsFilePath, typeof(EGM96));

            if (inputStream == null)
            {
                String msg = Logging.getMessage("generic.CannotOpenFile", this.offsetsFilePath);
                Logging.logger().severe(msg);
                throw new WWRuntimeException(msg);
            }

            try
            {
                AVList bufferParams = new AVListImpl();
                bufferParams.setValue(AVKey.DATA_TYPE, AVKey.INT16);
                bufferParams.setValue(AVKey.BYTE_ORDER, AVKey.BIG_ENDIAN);
                this.deltas = BufferWrapper.wrap(WWIO.readStreamToBuffer(is, true), bufferParams);
            }
            catch (IOException e)
            {
                String msg = Logging.getMessage("generic.ExceptionAttemptingToReadFile", this.offsetsFilePath);
                Logging.logger().log(java.util.logging.Level.SEVERE, msg, e);
                throw e;
            }
            finally
            {
                WWIO.closeStream(is, this.offsetsFilePath);
            }
        }
        protected bool doCanRead(Object source, AVList parameters)
        {
            String path = WWIO.getSourcePath(source);

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

            GeotiffReader reader = null;

            try
            {
                reader = new GeotiffReader(path);
                bool isGeoTiff = reader.isGeotiff(0);
                if (!isGeoTiff)
                {
                    isGeoTiff = WorldFile.hasWorldFiles(source);
                }
                return(isGeoTiff);
            }
            catch (Exception e)
            {
                // Intentionally ignoring exceptions.
                return(false);
            }
            finally
            {
                if (reader != null)
                {
                    reader.close();
                }
            }
        }
            public ComposeImageTile(Sector sector, String mimeType, Level level, int width, int height)
            {
                super(sector, level, -1, -1); // row and column aren't used and need to signal that

                this.width  = width;
                this.height = height;

                this.file = File.createTempFile(WWIO.DELETE_ON_EXIT_PREFIX, WWIO.makeSuffixForMimeType(mimeType));
            }
Exemplo n.º 5
0
        public VPFFeatureClassSchema[] getFeatureClasses(FileFilter featureTableFilter)
        {
            if (featureTableFilter == null)
            {
                String message = Logging.getMessage("nullValue.FilterIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // List the file names in the coverage directory matching the specified feature table file filter.
            String[] names = WWIO.listChildFilenames(new File(this.getFilePath()), featureTableFilter);
            if (names == null)
            {
                return(null);
            }

            int numFeatures = names.length;

            VPFFeatureClassSchema[] desc = new VPFFeatureClassSchema[numFeatures];

            for (int i = 0; i < numFeatures; i++)
            {
                String featureTableName = names[i];
                String className        = WWIO.replaceSuffix(featureTableName, "");
                String type             = null;

                // If the Feature Class Attriute Table is available, then use it to determine the feature type for the
                // specified class.
                if (this.featureClassAttributeTable != null)
                {
                    VPFRecord record = this.featureClassAttributeTable.getRecord("fclass", className);
                    if (record != null)
                    {
                        type = (String)record.getValue("type");
                    }
                }

                // Otherwise, determine the feature type is based on the feature table extension.
                if (type == null)
                {
                    type = VPFUtils.getFeatureTypeName(featureTableName);
                }

                desc[i] = new VPFFeatureClassSchema(className, VPFFeatureType.fromTypeName(type), featureTableName);
            }

            return(desc);
        }
Exemplo n.º 6
0
        protected bool doCanRead(Object source, AVList parameters)
        {
            if (WWUtil.isEmpty(source))
            {
                return(false);
            }

            if (null == parameters)
            {
                File file = WWIO.getFileForLocalAddress(source);
                if (null == file)
                {
                    return(false);
                }

                return(GDALUtils.canOpen(file));
            }

            bool           canOpen = false;
            GDALDataRaster raster  = null;

            try
            {
                raster = new GDALDataRaster(source, true); // read data raster quietly
                parameters.setValues(raster.getMetadata());
                canOpen = true;
            }
            catch (Throwable t)
            {
                // we purposely ignore any exception here, this should be a very quiet mode
                canOpen = false;
            }
            finally
            {
                if (null != raster)
                {
                    raster.dispose();
                    raster = null;
                }
            }

            return(canOpen);
        }
Exemplo n.º 7
0
        public static String getFeatureTypeName(String tableName)
        {
            if (tableName == null)
            {
                String message = Logging.getMessage("nullValue.StringIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            String suffix = WWIO.getSuffix(tableName);

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

            suffix = "." + suffix;

            if (suffix.equalsIgnoreCase(VPFConstants.POINT_FEATURE_TABLE))
            {
                return(VPFConstants.POINT_FEATURE_TYPE);
            }
            else if (suffix.equalsIgnoreCase(VPFConstants.LINE_FEATURE_TABLE))
            {
                return(VPFConstants.LINE_FEATURE_TYPE);
            }
            else if (suffix.equalsIgnoreCase(VPFConstants.AREA_FEATURE_TABLE))
            {
                return(VPFConstants.AREA_FEATURE_TYPE);
            }
            else if (suffix.equalsIgnoreCase(VPFConstants.TEXT_FEATURE_TABLE))
            {
                return(VPFConstants.TEXT_FEATURE_TYPE);
            }
            else if (suffix.equalsIgnoreCase(VPFConstants.COMPLEX_FEATURE_TABLE))
            {
                return(VPFConstants.COMPLEX_FEATURE_TYPE);
            }

            return(null);
        }
Exemplo n.º 8
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);
        }
        /**
         * Determine if a host is reachable by attempting to resolve the host name, and then attempting to open a
         * connection.
         *
         * @param hostName Name of the host to connect to.
         *
         * @return {@code true} if a the host is reachable, {@code false} if the host name cannot be resolved, or if opening
         *         a connection to the host fails.
         */
        protected static bool isHostReachable(String hostName)
        {
            try
            {
                // Assume host is unreachable if we can't get its dns entry without getting an exception
                //noinspection ResultOfMethodCallIgnored
                InetAddress.getByName(hostName);
            }
            catch (UnknownHostException e)
            {
                String message = Logging.getMessage("NetworkStatus.UnreachableTestHost", hostName);
                Logging.logger().fine(message);
                return(false);
            }
            catch (Exception e)
            {
                String message = Logging.getMessage("NetworkStatus.ExceptionTestingHost", hostName);
                Logging.logger().info(message);
                return(false);
            }

            // Was able to get internet address, but host still might not be reachable because the address might have been
            // cached earlier when it was available. So need to try something else.

            URLConnection connection = null;

            try
            {
                URL   url   = new URL("http://" + hostName);
                Proxy proxy = WWIO.configureProxy();
                if (proxy != null)
                {
                    connection = url.openConnection(proxy);
                }
                else
                {
                    connection = url.openConnection();
                }

                connection.setConnectTimeout(2000);
                connection.setReadTimeout(2000);
                String ct = connection.getContentType();
                if (ct != null)
                {
                    return(true);
                }
            }
            catch (IOException e)
            {
                String message = Logging.getMessage("NetworkStatus.ExceptionTestingHost", hostName);
                Logging.logger().info(message);
            }
            finally
            {
                if (connection != null && connection is HttpURLConnection)
                {
                    ((HttpURLConnection)connection).disconnect();
                }
            }

            return(false);
        }
Exemplo n.º 10
0
        protected Texture initializeTexture(DrawContext dc, Object imageSource)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new IllegalStateException(message);
            }

            if (this.textureInitializationFailed)
            {
                return(null);
            }

            Texture t;
            bool    haveMipMapData;
            GL      gl = dc.getGL();

            if (imageSource is String)
            {
                String path = (String)imageSource;

                Object streamOrException = WWIO.getFileOrResourceAsStream(path, this.GetType());
                if (streamOrException == null || streamOrException is Exception)
                {
                    Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionAttemptingToReadImageFile",
                                         streamOrException != null ? streamOrException : path);
                    this.textureInitializationFailed = true;
                    return(null);
                }

                try
                {
                    TextureData td = OGLUtil.newTextureData(gl.getGLProfile(), (InputStream)streamOrException,
                                                            this.useMipMaps);
                    t = TextureIO.newTexture(td);
                    haveMipMapData = td.getMipmapData() != null;
                }
                catch (Exception e)
                {
                    String msg = Logging.getMessage("layers.TextureLayer.ExceptionAttemptingToReadTextureFile",
                                                    imageSource);
                    Logging.logger().log(java.util.logging.Level.SEVERE, msg, e);
                    this.textureInitializationFailed = true;
                    return(null);
                }
            }
            else if (imageSource is BufferedImage)
            {
                try
                {
                    TextureData td = AWTTextureIO.newTextureData(gl.getGLProfile(), (BufferedImage)imageSource,
                                                                 this.useMipMaps);
                    t = TextureIO.newTexture(td);
                    haveMipMapData = td.getMipmapData() != null;
                }
                catch (Exception e)
                {
                    String msg = Logging.getMessage("generic.IOExceptionDuringTextureInitialization");
                    Logging.logger().log(java.util.logging.Level.SEVERE, msg, e);
                    this.textureInitializationFailed = true;
                    return(null);
                }
            }
            else if (imageSource is URL)
            {
                try
                {
                    InputStream stream = ((URL)imageSource).openStream();
                    if (stream == null)
                    {
                        Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionAttemptingToReadImageFile",
                                             imageSource);
                        this.textureInitializationFailed = true;
                        return(null);
                    }

                    TextureData td = OGLUtil.newTextureData(gl.getGLProfile(), stream, this.useMipMaps);
                    t = TextureIO.newTexture(td);
                    haveMipMapData = td.getMipmapData() != null;
                }
                catch (Exception e)
                {
                    String msg = Logging.getMessage("layers.TextureLayer.ExceptionAttemptingToReadTextureFile",
                                                    imageSource);
                    Logging.logger().log(java.util.logging.Level.SEVERE, msg, e);
                    this.textureInitializationFailed = true;
                    return(null);
                }
            }
            else
            {
                Logging.logger().log(java.util.logging.Level.SEVERE, "generic.UnrecognizedImageSourceType",
                                     imageSource.GetType().Name);
                this.textureInitializationFailed = true;
                return(null);
            }

            if (t == null) // In case JOGL TextureIO returned null
            {
                Logging.logger().log(java.util.logging.Level.SEVERE, "generic.TextureUnreadable",
                                     imageSource is String ? imageSource : imageSource.GetType().Name);
                this.textureInitializationFailed = true;
                return(null);
            }

            // Textures with the same path are assumed to be identical textures, so key the texture id off the
            // image source.
            dc.getTextureCache().put(imageSource, t);
            t.bind(gl);

            // Enable the appropriate mip-mapping texture filters if the caller has specified that mip-mapping should be
            // enabled, and the texture itself supports mip-mapping.
            bool useMipMapFilter = this.useMipMaps && (haveMipMapData || t.isUsingAutoMipmapGeneration());

            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                               useMipMapFilter ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);

            if (this.isUseAnisotropy() && useMipMapFilter)
            {
                double maxAnisotropy = dc.getGLRuntimeCapabilities().getMaxTextureAnisotropy();
                if (dc.getGLRuntimeCapabilities().isUseAnisotropicTextureFilter() && maxAnisotropy >= 2.0)
                {
                    gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)maxAnisotropy);
                }
            }

            this.width     = t.getWidth();
            this.height    = t.getHeight();
            this.texCoords = t.getImageTexCoords();

            return(t);
        }