X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fsrtm%2FTileFinder.java;h=e2b01fa166dbd9b607f9e13890f0a12a7f5b7302;hp=5ada68ca1b65e5428c3d6f961db1086e6b8086db;hb=38a0c12649e9104d0d40ce93a932b9086011f8c8;hpb=8b20e3e027058cdf6ff52993ee5576193d08667a diff --git a/src/tim/prune/function/srtm/TileFinder.java b/src/tim/prune/function/srtm/TileFinder.java index 5ada68c..e2b01fa 100644 --- a/src/tim/prune/function/srtm/TileFinder.java +++ b/src/tim/prune/function/srtm/TileFinder.java @@ -3,15 +3,17 @@ package tim.prune.function.srtm; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; /** * Class to get the URLs of the SRTM tiles * using the srtmtiles.dat file */ -public abstract class TileFinder +public class TileFinder { + /** tile data loaded from file */ + private byte[] _tileData = null; + /** URL prefix for all tiles */ private static final String URL_PREFIX = "https://dds.cr.usgs.gov/srtm/version2_1/SRTM3/"; /** Directory names for each continent */ @@ -24,33 +26,33 @@ public abstract class TileFinder * @param inTiles list of Tiles to get * @return array of URLs */ - public static URL[] getUrls(ArrayList inTiles) + public URL getUrl(SrtmTile inTile) { - if (inTiles == null || inTiles.size() < 1) {return null;} - URL[] urls = new URL[inTiles.size()]; - // Read dat file into array - byte[] lookup = readDatFile(); - if (lookup == null) - { - System.err.println("Build error: resource srtmtiles.dat missing!"); - return null; - } - for (int t=0; t 0) { - try { - urls[t] = new URL(URL_PREFIX + CONTINENTS[dir] + "/" + tile.getTileName()); - } catch (MalformedURLException e) {} // ignore error, url stays null - } - } catch (ArrayIndexOutOfBoundsException e) {} // ignore error, url stays null + System.err.println("Build error: resource srtmtiles.dat missing!"); + return null; + } } - return urls; + + URL url = null; + // Get byte from lookup array + int idx = (inTile.getLatitude() + 59)*360 + (inTile.getLongitude() + 180); + try + { + int dir = _tileData[idx]; + if (dir > 0) { + try { + url = new URL(URL_PREFIX + CONTINENTS[dir] + "/" + inTile.getTileName()); + } catch (MalformedURLException e) {} // ignore error, url stays null + } + } catch (ArrayIndexOutOfBoundsException e) {} // ignore error, url stays null + + return url; } /**