localelevationmodel.java

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

JAVA
476
字号
/*Copyright (C) 2001, 2008 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.terrain;import gov.nasa.worldwind.avlist.*;import gov.nasa.worldwind.exception.WWRuntimeException;import gov.nasa.worldwind.formats.worldfile.WorldFile;import gov.nasa.worldwind.geom.Angle;import gov.nasa.worldwind.geom.LatLon;import gov.nasa.worldwind.geom.Sector;import gov.nasa.worldwind.util.BufferWrapper;import gov.nasa.worldwind.util.Logging;import gov.nasa.worldwind.util.WWIO;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.nio.ByteBuffer;import java.util.List;import java.util.concurrent.CopyOnWriteArrayList;/** * @author tag * @version $Id: LocalElevationModel.java 9709 2009-03-27 01:33:50Z tgaskins $ */public class LocalElevationModel extends AbstractElevationModel{    protected double[] extremeElevations = null;    protected CopyOnWriteArrayList<LocalTile> tiles = new CopyOnWriteArrayList<LocalTile>();    public double getMinElevation()    {        return this.extremeElevations[0];    }    public double getMaxElevation()    {        return this.extremeElevations[1];    }    public double[] getExtremeElevations(Angle latitude, Angle longitude)    {        if (latitude == null || longitude == null)        {            String msg = Logging.getMessage("nullValue.AngleIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }                if (this.tiles.size() == 0)            return new double[] {this.missingDataValue, this.missingDataValue};        double min = Double.MAX_VALUE;        double max = -min;        for (LocalTile tile : this.tiles)        {            if (tile.sector.contains(latitude, longitude))            {                if (tile.minElevation < min)                    min = tile.minElevation;                if (tile.maxElevation > max)                    max = tile.maxElevation;            }        }                return new double[] {            min != Double.MAX_VALUE ? min : this.missingDataValue,            max != -Double.MAX_VALUE ? max : this.missingDataValue};    }    public double[] getExtremeElevations(Sector sector)    {        if (sector == null)        {            String msg = Logging.getMessage("nullValue.SectorIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (this.tiles.size() == 0)            return new double[] {this.missingDataValue, this.missingDataValue};        double min = Double.MAX_VALUE;        double max = -min;        for (LocalTile tile : this.tiles)        {            if (tile.sector.intersects(sector))            {                if (tile.minElevation < min)                    min = tile.minElevation;                if (tile.maxElevation > max)                    max = tile.maxElevation;            }        }        return new double[] {            min != Double.MAX_VALUE ? min : this.missingDataValue,            max != -Double.MAX_VALUE ? max : this.missingDataValue};    }    public double getBestResolution(Sector sector)    {        double res = Double.MAX_VALUE;        for (LocalTile tile : tiles)        {            if (!sector.intersects(tile.sector))                continue;            double r = tile.sector.getDeltaLatRadians() / tile.tileHeight;            if (r < res)                res = r;        }        return res;    }    public double getUnmappedElevation(Angle latitude, Angle longitude)    {        if (latitude == null || longitude == null)        {            String msg = Logging.getMessage("nullValue.AngleIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        return this.lookupElevation(latitude.radians, longitude.radians);    }    public double getElevations(Sector sector, List<? extends LatLon> latlons, double targetResolution, double[] buffer)    {        if (sector == null)        {            String msg = Logging.getMessage("nullValue.SectorIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (latlons == null)        {            String msg = Logging.getMessage("nullValue.LatLonListIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (buffer == null)        {            String msg = Logging.getMessage("nullValue.ElevationsBufferIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (buffer.length < latlons.size())        {            String msg = Logging.getMessage("ElevationModel.ElevationsBufferTooSmall", latlons.size());            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        for (int i = 0; i < latlons.size(); i++)        {            LatLon ll = latlons.get(i);            if (ll == null)                continue;            double e = this.lookupElevation(ll.getLatitude().radians, ll.getLongitude().radians);            if (e != this.missingDataFlag)                buffer[i] = e;        }        return this.getBestResolution(sector);    }    public void addElevations(String filePath, Sector sector, int width, int height) 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);        }        if (sector == null)        {            String message = Logging.getMessage("nullValue.SectorIsNull");            Logging.logger().severe(message);            throw new IllegalStateException(message);        }        try        {            File[] worldFiles = WorldFile.getWorldFiles(file);            AVList worldFileParams = WorldFile.decodeWorldFiles(worldFiles, null);            // Setup parameters to instruct BufferWrapper on how to interpret the ByteBuffer.            Object pixelType = worldFileParams.getValue(AVKey.PIXEL_TYPE);            if (pixelType == null)                pixelType = AVKey.INT16;            Object byteOrder = worldFileParams.getValue(AVKey.BYTE_ORDER);            if (byteOrder == null)                byteOrder = AVKey.LITTLE_ENDIAN;            // Get the missing data value from the world file parameters. If that is null, then attempt to get the            // missing data value from the ElevationModel.            // This code expects the string "gov.nasa.worldwind.avkey.MissingDataValue", which now corresponds to the             // key MISSING_DATA_REPLACEMENT.            Double tileMissingDataFlag = AVListImpl.getDoubleValue(worldFileParams, AVKey.MISSING_DATA_REPLACEMENT);            if (tileMissingDataFlag == null)                tileMissingDataFlag = this.getMissingDataSignal();            // TODO: determine and react to other formats            // Assume .bil format            AVList bufferParams = new AVListImpl();            bufferParams.setValue(AVKey.DATA_TYPE, pixelType);            bufferParams.setValue(AVKey.BYTE_ORDER, byteOrder);            ByteBuffer byteBuffer = WWIO.readFileToBuffer(file);            BufferWrapper buffer = BufferWrapper.wrap(byteBuffer, bufferParams);            LocalTile tile = new LocalTile(sector, tileMissingDataFlag, width, height, buffer);            this.tiles.add(tile);            this.adjustMinMax(tile);        }        catch (IOException e)

⌨️ 快捷键说明

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