File: GenerateTileLookup.java

package info (click to toggle)
gpsprune 19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,516 kB
  • sloc: java: 42,704; sh: 25; makefile: 24; python: 15
file content (79 lines) | stat: -rw-r--r-- 2,109 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package tim.prune.function.srtm.gen;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;

/**
 * Class used to generate a lookup file to find the URLs of SRTM tiles.
 * The tiles are split into directories for each continent, so we need some way
 * of going from coordinates to directories.
 * This class reads the directory listings from the files tiles1.txt, tiles2.txt etc
 * and combines the result into a binary array
 */
public class GenerateTileLookup
{

	/**
	 * Main method for generating the array
	 * @param args ignored
	 */
	public static void main(String[] args)
	{
		System.out.println("Generate tile lookup");
		byte[] lookup = new byte[360 * 120]; // +/- 180 degrees longitude, +/- 60 degrees latitude
		for (int f=1; f<= 6; f++)
		{
			BufferedReader r = null;
			try
			{
				r = new BufferedReader(new FileReader(new File("tim/prune/function/srtm/gen/tiles" + f + ".txt")));
				String line = r.readLine();
				System.out.println("Read continent: '" + line + "'");
				while ((line = r.readLine()) != null) {
					if (line.length() == 7)
					{
						boolean north = (line.charAt(0) == 'N');
						int lat = Integer.parseInt(line.substring(1, 3));
						if (!north) {lat = -lat;}
						boolean east = (line.charAt(3) == 'E');
						int lon = Integer.parseInt(line.substring(4));
						if (!east) {lon = -lon;}
						// Store in lookup
						int arrindex = (lat+59)*360 + (lon+180);
						lookup[arrindex] = (byte) f;
					}
				}
			}
			catch (Exception e) {
				e.printStackTrace();
			}
			finally {
				if (r != null)
				{
					try {
						r.close();
					} catch (Exception e) {}
				}
			}
		}
		// Now f should be populated
		StringBuilder b = new StringBuilder();
		for (int l=-180; l<180; l++) {
			int i = 59 * 360 + (l+180);
			b.append("" + lookup[i]);
		}
		System.out.println("equator: " + b.toString());

		// Write bytes to file
		try {
			FileOutputStream out = new FileOutputStream(new File("srtmtiles.dat"));
			out.write(lookup);
			out.close();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}