1 package tim.prune.function.srtm;
3 import java.io.InputStream;
4 import java.net.MalformedURLException;
9 * Class to get the URLs of the SRTM tiles
10 * using the srtmtiles.dat file
12 public class TileFinder
14 /** tile data loaded from file */
15 private byte[] _tileData = null;
17 /** URL prefix for all tiles */
18 private static final String URL_PREFIX = "https://srtm.kurviger.de/SRTM3/";
19 /** Directory names for each continent */
20 private static final String[] CONTINENTS = {"", "Eurasia", "North_America", "Australia",
21 "Islands", "South_America", "Africa"};
25 * Get the Urls for the given list of tiles
26 * @param inTiles list of Tiles to get
27 * @return array of URLs
29 public URL getUrl(SrtmTile inTile)
31 if (inTile == null) {return null;}
32 if (_tileData == null)
34 _tileData = readDatFile();
35 if (_tileData == null)
37 System.err.println("Build error: resource srtmtiles.dat missing!");
43 // Get byte from lookup array
44 int idx = (inTile.getLatitude() + 59)*360 + (inTile.getLongitude() + 180);
47 int dir = _tileData[idx];
50 url = new URL(URL_PREFIX + CONTINENTS[dir] + "/" + inTile.getTileName());
51 } catch (MalformedURLException e) {} // ignore error, url stays null
53 } catch (ArrayIndexOutOfBoundsException e) {} // ignore error, url stays null
59 * Read the dat file and get the contents
60 * @return byte array containing file contents
62 private static byte[] readDatFile()
64 InputStream in = null;
67 // Need absolute path to dat file
68 in = TileFinder.class.getResourceAsStream("/tim/prune/function/srtm/srtmtiles.dat");
71 byte[] buffer = new byte[in.available()];
77 catch (java.io.IOException e) {
78 System.err.println("Exception trying to read srtmtiles.dat : " + e.getMessage());
85 catch (Exception e) {} // ignore