localelevationmodel.java

来自「world wind java sdk 源码」· Java 代码 · 共 476 行 · 第 1/2 页

JAVA
476
字号
        {            String message = Logging.getMessage("ElevationModel.ExceptionReadingElevationFile", filePath);            Logging.logger().severe(message);            throw e;        }    }    public void addElevations(String filePath) throws IOException    {        if (filePath == null)        {            String message = Logging.getMessage("nullValue.FilePathIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        File file = new File(filePath);        if (!file.exists())        {            String message = Logging.getMessage("generic.FileNotFound", file.getPath());            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        String suffix = WWIO.getSuffix(filePath);        if (suffix == null)        {            return; // TODO: throw exception and log message        }        this.addElevationsFromWorldFiles(filePath);        // TODO: determine and react to other formats    }    protected void addElevationsFromWorldFiles(String filePath) throws IOException    {        int size[];        Sector sector;        try        {            File[] worldFiles = WorldFile.getWorldFiles(new File(filePath));            if (worldFiles == null || worldFiles.length == 0)            {                String message = Logging.getMessage("WorldFile.WorldFileNotFound", filePath);                Logging.logger().severe(message);                throw new FileNotFoundException(message);            }            AVList values = WorldFile.decodeWorldFiles(worldFiles, null);            size = (int[]) values.getValue(WorldFile.WORLD_FILE_IMAGE_SIZE);            if (size == null)            {                String message = Logging.getMessage("WorldFile.NoSizeSpecified", filePath);                throw new WWRuntimeException(message);            }            sector = (Sector) values.getValue(AVKey.SECTOR);            if (sector == null)            {                String message = Logging.getMessage("WorldFile.NoSectorSpecified", filePath);                throw new WWRuntimeException(message);            }        }        catch (IOException e)        {            String message = Logging.getMessage("ElevationModel.ExceptionReadingElevationFile", filePath);            Logging.logger().severe(message);            throw e;        }        this.addElevations(filePath, sector, size[0], size[1]);    }    public int intersects(Sector sector)    {        boolean intersects = false;        for (LocalTile tile : this.tiles)        {            if (tile.sector.contains(sector))                return 0;            if (tile.sector.intersects(sector))                intersects = true;        }        return intersects ? 1 : -1;    }    public boolean contains(Angle latitude, Angle longitude)    {        for (LocalTile tile : this.tiles)        {            if (tile.sector.contains(latitude, longitude))                return true;        }        return false;    }    protected void adjustMinMax(LocalTile tile)    {        if (this.extremeElevations == null && tile != null)        {            this.extremeElevations = new double[] {tile.minElevation, tile.maxElevation};        }        else if (tile != null) // adjust for just the input tile        {            if (tile.minElevation < this.extremeElevations[0])                this.extremeElevations[0] = tile.minElevation;            if (tile.maxElevation > this.extremeElevations[1])                this.extremeElevations[1] = tile.maxElevation;        }        else // Find the min and max among all the tiles        {            double min = Double.MAX_VALUE;            double max = -min;            for (LocalTile t : this.tiles)            {                if (t.minElevation < min)                    min = t.minElevation;                if (t.maxElevation > max)                    max = t.maxElevation;            }            this.extremeElevations =                new double[] {min != Double.MAX_VALUE ? min : 0, max != -Double.MAX_VALUE ? max : 0};        }    }    protected double lookupElevation(final double latRadians, final double lonRadians)    {        LocalTile tile = this.findTile(latRadians, lonRadians);        if (tile == null)            return this.missingDataFlag;        final double sectorDeltaLat = tile.sector.getDeltaLat().radians;        final double sectorDeltaLon = tile.sector.getDeltaLon().radians;        final double dLat = tile.sector.getMaxLatitude().radians - latRadians;        final double dLon = lonRadians - tile.sector.getMinLongitude().radians;        final double sLat = dLat / sectorDeltaLat;        final double sLon = dLon / sectorDeltaLon;        int j = (int) ((tile.tileHeight - 1) * sLat);        int i = (int) ((tile.tileWidth - 1) * sLon);        int k = j * tile.tileWidth + i;        double eLeft = tile.elevations.getDouble(k);        double eRight = i < (tile.tileWidth - 1) ? tile.elevations.getDouble(k + 1) : eLeft;        if (tile.missingDataFlag == eLeft || tile.missingDataFlag == eRight)            return this.missingDataFlag;        double dw = sectorDeltaLon / (tile.tileWidth - 1);        double dh = sectorDeltaLat / (tile.tileHeight - 1);        double ssLon = (dLon - i * dw) / dw;        double ssLat = (dLat - j * dh) / dh;        double eTop = eLeft + ssLon * (eRight - eLeft);        if (j < tile.tileHeight - 1 && i < tile.tileWidth - 1)        {            eLeft = tile.elevations.getDouble(k + tile.tileWidth);            eRight = tile.elevations.getDouble(k + tile.tileWidth + 1);            if (tile.missingDataFlag == eLeft || tile.missingDataFlag == eRight)                return this.missingDataFlag;        }        double eBot = eLeft + ssLon * (eRight - eLeft);        return eTop + ssLat * (eBot - eTop);    }    protected LocalTile findTile(final double latRadians, final double lonRadians)    {        for (LocalTile tile : this.tiles)        {            if (tile.sector.containsRadians(latRadians, lonRadians))                return tile;        }        return null;    }    protected static class LocalTile    {        protected final Sector sector;        protected final int tileWidth;        protected final int tileHeight;        protected final double minElevation;        protected final double maxElevation;        protected final double missingDataFlag;        protected final BufferWrapper elevations;        protected LocalTile(Sector sector, double missingDataFlag, int tileWidth, int tileHeight,            BufferWrapper elevations)        {            this.sector = sector;            this.tileWidth = tileWidth;            this.tileHeight = tileHeight;            this.missingDataFlag = missingDataFlag;            this.elevations = elevations;            int len = this.elevations.length();            if (len != 0)            {                double min = Double.MAX_VALUE;                double max = -min;                for (int i = 0; i < len; i++)                {                    double v = this.elevations.getDouble(i);                    if (v == this.missingDataFlag)                        continue;                    if (v < min)                        min = v;                    if (v > max)                        max = v;                }                this.minElevation = min;                this.maxElevation = max;            }            else            {                this.minElevation = 0;                this.maxElevation = 0;            }        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?