Package uk.co.mccombe.terrain

# Class DEMReader

java.lang.Object
java.beans.PropertyChangeSupport
uk.co.mccombe.terrain.DEMReader

All Implemented Interfaces:
  `Serializable`

Direct Known Subclasses:
  `SRTM2Reader`, `SRTM3Reader`

public abstract class DEMReader extends PropertyChangeSupport
DEMReader - an abstract base class for readers of various forms of Digital Elevation Model data sets

See Also:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected class`
`DEMReader.CacheEntry`
CacheEntry -- A class used to store a row of values

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final int`
`BUFFERLENGTH`
`protected HashMap<String,DEMReader.CacheEntry>`
`cache`
`protected boolean`
`cacheEnable`
`protected String[]`
`copyright`
`protected long`
`cycle`
`protected String`
`DIRECTORY`
`protected long`
`hits`
`protected static ZipInputStream`
`in`
`protected String`
`lastMessage`
`protected int`
`lastValue`
`protected static final Locale`
`LOCALE`
`protected static final int`
`MAX_CACHE_SIZE`
`protected long`
`missing`
`protected static final double`
`MISSING`
`protected long`
`resultcount`
`protected long`
`tries`
`protected boolean`
`useLegacy`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`DEMReader(JComponent item)`

## Method Summary

Modifier and Type
Method
Description
`abstract String[]`
`copyright()`
`abstract String`
`datasetName()`
`abstract boolean`
`downloadable()`
`protected void`
`downloadFile(String filename)`
Download a specific file and sand save it in scratch space on the local machine
`protected abstract String`
`eastWest(double lon)`
`abstract String`
`extn()`
`abstract String`
`formatstring()`
`double`
`frac(int tile)`
Calculate the proportion of a degree represented by a particular element in the buffer
`protected abstract String`
`getDownloadSiteName()`
`double`
`getHeight(LatLong place)`
Calculate terrain height at a specified location using biaxial cubic Lagrangian interpolation on surrounding points in the tile.
`protected String`
`getProperty(TerrainProperties propertyName)`
`PropertyChangeListener[]`
`getPropertyChangeListeners()`
`protected DEMReader.CacheEntry`
`getRow(String name, int ytile)`
`long`
`hits()`
`static double`
`lagrangian(double x, Point2D.Double... points)`
Fit an exact polynomial to a set of points and return its value at a specified point
`abstract boolean`
`littleendian()`
`protected String`
`makename(String ns, double lat, String ew, double lon)`
`abstract double`
`maxLat()`
`abstract double`
`minLat()`
`long`
`missing()`
`abstract int`
`missingValue()`
`protected abstract String`
`northSouth(double lat)`
`String`
`numEntryName(String name)`
`byte[]`
`readByteRecord()`
Read the next byte record from the current ZipInputStream
`int[]`
`readRecord()`
Read the next record from the current ZipInputStream
`abstract int`
`recordlength()`
`void`
`resetCounts()`
`long`
`resultcount()`
`protected abstract void`
`setDownloadSiteName(String s)`
`protected void`
`setMessage(String msg)`
`protected void`
`setProgress(int val)`
`double`
`tile(double x)`
Calculate the number of the element in the buffer that refers to a particular lat or lon value
`long`
`tries()`
`String`
`zipEntryName(String name)`

### Methods inherited from class java.beans.PropertyChangeSupport

`addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### in

protected static ZipInputStream in

### DIRECTORY

protected String DIRECTORY

### cycle

protected long cycle

### cache

protected HashMap<String,DEMReader.CacheEntry> cache

### cacheEnable

protected boolean cacheEnable

### MAX_CACHE_SIZE

protected static final int MAX_CACHE_SIZE

See Also:
  - Constant Field Values

### hits

protected long hits

### tries

protected long tries

### missing

protected long missing

### resultcount

protected long resultcount

### MISSING

protected static final double MISSING

See Also:
  - Constant Field Values

### BUFFERLENGTH

protected static final int BUFFERLENGTH

See Also:
  - Constant Field Values

### lastMessage

protected String lastMessage

### lastValue

protected int lastValue

### LOCALE

protected static final Locale LOCALE

### useLegacy

protected boolean useLegacy

### copyright

protected String[] copyright

## Constructor Details

### DEMReader

protected DEMReader(JComponent item) throws DataFileException

Throws:
  `DataFileException`

## Method Details

### makename

protected String makename(String ns, double lat, String ew, double lon)

### getHeight

public double getHeight(LatLong place) throws MissingDataFileException, DataFileException
Calculate terrain height at a specified location using biaxial cubic Lagrangian interpolation on surrounding points in the tile. This method provides an exact fit at the points defined in the tile and a slightly smoothed surface in between. To speed the calculation up, rows of values from the tile are cached.

Parameters:
  `place` - -- the LatLong of the place to calculate the height for.
Returns:
  -- the calculated height at place.
Throws:
  `MissingDataFileException`
  `DataFileException`

### getRow

protected DEMReader.CacheEntry getRow(String name, int ytile) throws MissingDataFileException, DataFileException

Throws:
  `MissingDataFileException`
  `DataFileException`

### readRecord

public int[] readRecord() throws IOException
Read the next record from the current ZipInputStream

Returns:
  int[] buffer of length recordlength() containing the decoded next record;
Throws:
  `IOException`

### readByteRecord

public byte[] readByteRecord() throws IOException
Read the next byte record from the current ZipInputStream

Returns:
  byte[] buffer of length recordlength() containing the decoded next record;
Throws:
  `IOException`

### tile

public double tile(double x)
Calculate the number of the element in the buffer that refers to a particular lat or lon value

Parameters:
  `x` - the double lat/lon value
Returns:
  A double value representing the buffer element index

### frac

public double frac(int tile)
Calculate the proportion of a degree represented by a particular element in the buffer

Parameters:
  `tile` - the integer number of the element
Returns:
  double number representing a fraction of a degree

### downloadFile

protected void downloadFile(String filename) throws KeyManagementException, NoSuchAlgorithmException, IOException, MissingDataFileException, URISyntaxException
Download a specific file and sand save it in scratch space on the local machine

Parameters:
  `filename` - the name of the file to download
Throws:
  `KeyManagementException`
  `NoSuchAlgorithmException`
  `IOException`
  `MissingDataFileException`
  `URISyntaxException`

### lagrangian

public static double lagrangian(double x, Point2D.Double... points)
Fit an exact polynomial to a set of points and return its value at a specified point

Parameters:
  `x` - double the value at which to evaluate the calculated polynomial
  `points` - a set of java.awt.geom.Point2D.Double values
Returns:
  double value of the polynomial

### hits

public long hits()

### resultcount

public long resultcount()

### tries

public long tries()

### missing

public long missing()

### resetCounts

public void resetCounts()

### setMessage

protected void setMessage(String msg)

### setProgress

protected void setProgress(int val)

### getProperty

protected String getProperty(TerrainProperties propertyName)

### getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()

Overrides:
  `getPropertyChangeListeners` in class `PropertyChangeSupport`

### datasetName

public abstract String datasetName()

### downloadable

public abstract boolean downloadable()

### recordlength

public abstract int recordlength()

### formatstring

public abstract String formatstring()

### extn

public abstract String extn()

### littleendian

public abstract boolean littleendian()

### missingValue

public abstract int missingValue()

### copyright

public abstract String[] copyright()

### setDownloadSiteName

protected abstract void setDownloadSiteName(String s)

### getDownloadSiteName

protected abstract String getDownloadSiteName()

### eastWest

protected abstract String eastWest(double lon)

### northSouth

protected abstract String northSouth(double lat)

### maxLat

public abstract double maxLat()

### minLat

public abstract double minLat()

### zipEntryName

public String zipEntryName(String name)

### numEntryName

public String numEntryName(String name)