Package gov.nasa.worldwind.terrain
Class LocalElevationModel
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.terrain.AbstractElevationModel
-
- gov.nasa.worldwind.terrain.LocalElevationModel
-
- All Implemented Interfaces:
AVList
,Disposable
,MessageListener
,ElevationModel
,Restorable
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
public class LocalElevationModel extends AbstractElevationModel
Implements an elevation model for a local file or collection of files containing elevation data.Note: Unless the amount of data associated with the local elevation models is small, it's best to construct and add elevations to a local elevation model on a thread other than the event dispatch thread in order to avoid freezing the user interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
LocalElevationModel.LocalTile
An internal class that represents one elevation raster in the elevation model.
-
Field Summary
Fields Modifier and Type Field Description protected double[]
extremeElevations
The min and max elevations.protected java.util.concurrent.CopyOnWriteArrayList<LocalElevationModel.LocalTile>
tiles
The list of elevation rasters, one per file specified.-
Fields inherited from class gov.nasa.worldwind.terrain.AbstractElevationModel
dataFileStore, enabled, expiryTime, missingDataFlag, missingDataValue, networkRetrievalEnabled
-
-
Constructor Summary
Constructors Constructor Description LocalElevationModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addElevations(java.io.File file)
Adds the specified elevation data to this elevation model.void
addElevations(java.lang.String filename)
Adds the specified elevation data to this elevation model.void
addElevations(java.nio.ByteBuffer byteBuffer, Sector sector, int width, int height, AVList parameters)
Adds new elevations to this elevation model.protected void
addRaster(DataRaster raster, java.lang.String filename)
Adds a new raster to this elevation model.protected void
adjustMinMax(LocalElevationModel.LocalTile tile)
Updates the min and max elevations for this elevation model to account for a specified tile.boolean
contains(Angle latitude, Angle longitude)
Indicates whether a specified location is within the elevation model's domain.protected double
doGetElevations(Sector sector, java.util.List<? extends LatLon> latlons, double targetResolution, double[] buffer, boolean mapMissingData)
Performs the lookup and assembly of elevations for a list of specified locations.protected LocalElevationModel.LocalTile
findTile(double latRadians, double lonRadians)
Finds the tile in this elevation model that contains a specified location.double
getBestResolution(Sector sector)
Indicates the best resolution attainable for a specified sector.double
getElevations(Sector sector, java.util.List<? extends LatLon> latlons, double targetResolution, double[] buffer)
Returns the elevations of a collection of locations.double[]
getExtremeElevations(Angle latitude, Angle longitude)
Returns the minimum and maximum elevations at a specified location.double[]
getExtremeElevations(Sector sector)
Returns the minimum and maximum elevations within a specified sector of the elevation model.double
getMaxElevation()
Returns the maximum elevation contained in the elevation model.double
getMinElevation()
Returns the minimum elevation contained in the elevation model.Sector
getSector()
Returns the sector spanned by this elevation model.double
getUnmappedElevation(Angle latitude, Angle longitude)
Returns the elevation at a specified location, but without replacing missing data with the elevation model's missing data replacement value.double
getUnmappedElevations(Sector sector, java.util.List<? extends LatLon> latlons, double targetResolution, double[] buffer)
Returns the elevations of a collection of locations.int
intersects(Sector sector)
Indicates whether the elevation model covers a specified sector either partially or fully.boolean
isExtremesCachingEnabled()
Indicates whether extreme value caching is enabled.protected java.lang.Double
lookupElevation(double latRadians, double lonRadians)
Looks up an elevation for a specified location.void
setExtremesCachingEnabled(boolean enabled)
Indicates whether extreme values of sectors should be cached as they're computed.-
Methods inherited from class gov.nasa.worldwind.terrain.AbstractElevationModel
composeElevations, createElevationModelConfigElements, dispose, getBestResolutions, getDataFileStore, getDetailHint, getElevation, getElevationModelConfigParams, getElevations, getExpiryTime, getLocalDataAvailability, getMissingDataReplacement, getMissingDataSignal, getName, getRestorableState, getUnmappedElevations, getUnmappedLocalSourceElevation, isElevationModelConfigDocument, isEnabled, isNetworkRetrievalEnabled, isTransparentValue, restoreState, setDataFileStore, setEnabled, setExpiryTime, setMissingDataReplacement, setMissingDataSignal, setName, setNetworkRetrievalEnabled, toString
-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
-
-
-
-
Field Detail
-
extremeElevations
protected double[] extremeElevations
The min and max elevations.
-
tiles
protected java.util.concurrent.CopyOnWriteArrayList<LocalElevationModel.LocalTile> tiles
The list of elevation rasters, one per file specified.
-
-
Method Detail
-
getMinElevation
public double getMinElevation()
Description copied from interface:ElevationModel
Returns the minimum elevation contained in the elevation model. When associated with a globe, this value is the elevation of the lowest point on the globe. It may be negative, indicating a value below mean surface level. (Sea level in the case of Earth.)- Returns:
- The minimum elevation of the model.
-
getMaxElevation
public double getMaxElevation()
Description copied from interface:ElevationModel
Returns the maximum elevation contained in the elevation model. When the elevation model is associated with a globe, this value is the elevation of the highest point on the globe.- Returns:
- The maximum elevation of the elevation model.
-
getSector
public Sector getSector()
Returns the sector spanned by this elevation model.- Returns:
- the sector spanned by this elevation model.
-
getExtremeElevations
public double[] getExtremeElevations(Angle latitude, Angle longitude)
Description copied from interface:ElevationModel
Returns the minimum and maximum elevations at a specified location.- Parameters:
latitude
- the latitude of the location in question.longitude
- the longitude of the location in question.- Returns:
- A two-element
double
array indicating, respectively, the minimum and maximum elevations at the specified location. These values are the global minimum and maximum if the local minimum and maximum values are currently unknown.
-
getExtremeElevations
public double[] getExtremeElevations(Sector sector)
Description copied from interface:ElevationModel
Returns the minimum and maximum elevations within a specified sector of the elevation model.- Parameters:
sector
- the sector in question.- Returns:
- A two-element
double
array indicating, respectively, the sector's minimum and maximum elevations. These elements are the global minimum and maximum if the local minimum and maximum values are currently unknown.
-
getBestResolution
public double getBestResolution(Sector sector)
Description copied from interface:ElevationModel
Indicates the best resolution attainable for a specified sector.- Parameters:
sector
- the sector in question. If null, the elevation model's best overall resolution is returned. This is the best attainable at some locations but not necessarily at all locations.- Returns:
- the best resolution attainable for the specified sector, in radians, or
Double.MAX_VALUE
if the sector does not intersect the elevation model.
-
setExtremesCachingEnabled
public void setExtremesCachingEnabled(boolean enabled)
Description copied from interface:ElevationModel
Indicates whether extreme values of sectors should be cached as they're computed. Caching should be disabled if especially many sectors are to be used when querying extreme elevations of this elevation model, such as during terrain intersection calculations. The default is for caching to be enabled. During normal operation caching enhances performance, but during terrain intersection computation it can hamper performance.- Parameters:
enabled
- true if extreme value caching should be performed.
-
isExtremesCachingEnabled
public boolean isExtremesCachingEnabled()
Description copied from interface:ElevationModel
Indicates whether extreme value caching is enabled.- Returns:
- true if extreme values caching is enabled, otherwise false.
- See Also:
ElevationModel.setExtremesCachingEnabled(boolean)
-
getUnmappedElevation
public double getUnmappedElevation(Angle latitude, Angle longitude)
Description copied from interface:ElevationModel
Returns the elevation at a specified location, but without replacing missing data with the elevation model's missing data replacement value. When a missing data signal is found, the signal value is returned, not the replacement value.- Parameters:
latitude
- the latitude of the location for which to return the elevation.longitude
- the longitude of the location for which to return the elevation.- Returns:
- the elevation at the specified location, or the elevation model's missing data signal. If no data is currently in memory for the location, and the location is within the elevation model's coverage area, the elevation model's minimum elevation at that location is returned.
-
getElevations
public double getElevations(Sector sector, java.util.List<? extends LatLon> latlons, double targetResolution, double[] buffer)
Description copied from interface:ElevationModel
Returns the elevations of a collection of locations. Replaces any elevation values corresponding to the missing data signal with the elevation model's missing data replacement value. If a location within the elevation model's coverage area cannot currently be determined, the elevation model's minimum extreme elevation for that location is returned in the output buffer. If a location is outside the elevation model's coverage area, the output buffer for that location is not modified; it retains the buffer's original value.- Parameters:
sector
- the sector in question.latlons
- the locations to return elevations for. If a location is null, the output buffer for that location is not modified.targetResolution
- the desired horizontal resolution, in radians, of the raster or other elevation sample from which elevations are drawn. (To compute radians from a distance, divide the distance by the radius of the globe, ensuring that both the distance and the radius are in the same units.)buffer
- an array in which to place the returned elevations. The array must be pre-allocated and contain at least as many elements as the list of locations.- Returns:
- the resolution achieved, in radians, or
Double.MAX_VALUE
if individual elevations cannot be determined for all of the locations. - See Also:
ElevationModel.setMissingDataSignal(double)
-
getUnmappedElevations
public double getUnmappedElevations(Sector sector, java.util.List<? extends LatLon> latlons, double targetResolution, double[] buffer)
Description copied from interface:ElevationModel
Returns the elevations of a collection of locations. Does not replace any elevation values corresponding to the missing data signal with the elevation model's missing data replacement value. If a location within the elevation model's coverage area cannot currently be determined, the elevation model's minimum extreme elevation for that location is returned in the output buffer. If a location is outside the elevation model's coverage area, the output buffer for that location is not modified; it retains the buffer's original value.- Parameters:
sector
- the sector in question.latlons
- the locations to return elevations for. If a location is null, the output buffer for that location is not modified.targetResolution
- the desired horizontal resolution, in radians, of the raster or other elevation sample from which elevations are drawn. (To compute radians from a distance, divide the distance by the radius of the globe, ensuring that both the distance and the radius are in the same units.)buffer
- an array in which to place the returned elevations. The array must be pre-allocated and contain at least as many elements as the list of locations.- Returns:
- the resolution achieved, in radians, or
Double.MAX_VALUE
if individual elevations cannot be determined for all of the locations. - See Also:
ElevationModel.setMissingDataSignal(double)
-
doGetElevations
protected double doGetElevations(Sector sector, java.util.List<? extends LatLon> latlons, double targetResolution, double[] buffer, boolean mapMissingData)
Performs the lookup and assembly of elevations for a list of specified locations. This method is provided to enable subclasses to override this operation.- Parameters:
sector
- the sector containing the specified locations.latlons
- the list of locations at which to lookup elevations.targetResolution
- the desired maximum horizontal resolution of the elevation data to draw from.buffer
- a buffer in which to return the elevations. Must be at least as large as the list of locations.mapMissingData
- indicates whether to replace any elevations that match this elevation model's missing data signal to this model's missing data replacement value.- Returns:
- the resolution achieved, in radians, or
Double.MAX_VALUE
if individual elevations cannot be determined for all of the locations. - Throws:
java.lang.IllegalArgumentException
- if either the sector, list of locations or buffer is null, or the buffer size is not at least as large as the location list.- See Also:
AbstractElevationModel.setMissingDataSignal(double)
,AbstractElevationModel.setMissingDataReplacement(double)
-
addElevations
public void addElevations(java.lang.String filename) throws java.io.IOException
Adds the specified elevation data to this elevation model.- Parameters:
filename
- the file containing the elevation data.- Throws:
java.lang.IllegalArgumentException
- if the filename is null or the file does not exist, or if the file does not contain elevations in a recognizable format.java.io.IOException
- if an exception occurs while opening or reading the specified file.WWRuntimeException
- if an error occurs attempting to read and interpret the elevation data, or if necessary information is missing from the data file or its auxiliary files.
-
addElevations
public void addElevations(java.io.File file) throws java.io.IOException
Adds the specified elevation data to this elevation model.- Parameters:
file
- the file containing the elevation data.- Throws:
java.lang.IllegalArgumentException
- if the file is null or does not exist, if the file does not contain elevations in a recognizable format, or if the specified file does not contain required information such as the data's location and data type.java.io.IOException
- if an exception occurs while opening or reading the specified file.WWRuntimeException
- if an error occurs attempting to read and interpret the elevation data, or if an error occurs attempting to read and interpret the file's contents.
-
addRaster
protected void addRaster(DataRaster raster, java.lang.String filename) throws java.io.IOException
Adds a new raster to this elevation model.- Parameters:
raster
- the raster to add.filename
- the filename associated with the raster. Used only for error reporting.- Throws:
java.lang.IllegalArgumentException
- if necessary information is missing from the raster.java.io.IOException
- if an exception occurs while opening or reading the specified file.WWRuntimeException
- if an error occurs attempting to read and interpret the elevation data.
-
addElevations
public void addElevations(java.nio.ByteBuffer byteBuffer, Sector sector, int width, int height, AVList parameters)
Adds new elevations to this elevation model. The elevations are specified as a rectangular array arranged in row-major order in a linear buffer.- Parameters:
byteBuffer
- the elevations to add.sector
- the sector containing the elevations.width
- the number of elevation values in a row of the array. Each consecutive group ofwidth
elevation values is considered one row of the array, with the first element of the buffer starting the row of elevations at the sector's maximum latitude.height
- the number of rows in the array.parameters
- a list of key-value pairs indicating information about the raster. A value forAVKey.DATA_TYPE
is required. Values recognized but not required areAVKey.MISSING_DATA_SIGNAL
,AVKey.BYTE_ORDER
,AVKey.ELEVATION_MIN
andAVKey.ELEVATION_MAX
.- Throws:
java.lang.IllegalArgumentException
- if either the buffer, sector or parameters list is null, or if a key-value pair forAVKey.DATA_TYPE
is not specified in the parameters.
-
intersects
public int intersects(Sector sector)
Description copied from interface:ElevationModel
Indicates whether the elevation model covers a specified sector either partially or fully.- Parameters:
sector
- the sector in question.- Returns:
- 0 if the elevation model fully contains the sector, 1 if the elevation model intersects the sector but does not fully contain it, or -1 if the sector does not intersect the elevation model.
-
contains
public boolean contains(Angle latitude, Angle longitude)
Description copied from interface:ElevationModel
Indicates whether a specified location is within the elevation model's domain.- Parameters:
latitude
- the latitude of the location in question.longitude
- the longitude of the location in question.- Returns:
- true if the location is within the elevation model's domain, otherwise false.
-
adjustMinMax
protected void adjustMinMax(LocalElevationModel.LocalTile tile)
Updates the min and max elevations for this elevation model to account for a specified tile.- Parameters:
tile
- the tile to account for.
-
lookupElevation
protected java.lang.Double lookupElevation(double latRadians, double lonRadians)
Looks up an elevation for a specified location.- Parameters:
latRadians
- the latitude of the location, in radians.lonRadians
- the longitude of the location, in radians.- Returns:
- the elevation if the specified location is contained in this elevation model, null if it's not, or this elevation model's missing data flag if that's the value at the specified location.
-
findTile
protected LocalElevationModel.LocalTile findTile(double latRadians, double lonRadians)
Finds the tile in this elevation model that contains a specified location.- Parameters:
latRadians
- the location's latitude, in radians.lonRadians
- the location's longitude, in radians.- Returns:
- the tile that contains the location, or null if no tile contains it.
-
-