1 package tim.prune.function.srtm.gen;
3 import java.io.BufferedReader;
5 import java.io.FileOutputStream;
6 import java.io.FileReader;
9 * Class used to generate a lookup file to find the URLs of SRTM tiles.
10 * The tiles are split into directories for each continent, so we need some way
11 * of going from coordinates to directories.
12 * This class reads the directory listings from the files tiles1.txt, tiles2.txt etc
13 * and combines the result into a binary array
15 public class GenerateTileLookup
19 * Main method for generating the array
22 public static void main(String[] args)
24 System.out.println("Generate tile lookup");
25 byte[] lookup = new byte[360 * 120]; // +/- 180 degrees longitude, +/- 60 degrees latitude
26 for (int f=1; f<= 6; f++)
30 BufferedReader r = new BufferedReader(new FileReader(new File("tim/prune/function/srtm/gen/tiles" + f + ".txt")));
31 String line = r.readLine();
32 System.out.println("Read continent: '" + line + "'");
33 while ((line = r.readLine()) != null) {
34 if (line.length() == 7)
36 boolean north = (line.charAt(0) == 'N');
37 int lat = Integer.parseInt(line.substring(1, 3));
38 if (!north) {lat = -lat;}
39 boolean east = (line.charAt(3) == 'E');
40 int lon = Integer.parseInt(line.substring(4));
41 if (!east) {lon = -lon;}
43 int arrindex = (lat+59)*360 + (lon+180);
44 lookup[arrindex] = (byte) f;
52 // Now f should be populated
53 StringBuilder b = new StringBuilder();
54 for (int l=-180; l<180; l++) {
55 int i = 59 * 360 + (l+180);
56 b.append("" + lookup[i]);
58 System.out.println("equator: " + b.toString());
60 // Write bytes to file
62 FileOutputStream out = new FileOutputStream(new File("srtmtiles.dat"));