summaryrefslogtreecommitdiffstats
path: root/DataStructure/GenerateMap.java
blob: ff43b8983cafea5970356efcb5ab5f8d9b552561 (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package gui;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import DataStructure.Interpolator;
import Parse.NMEAParse;
import Parse.sqlreader;

public class GenerateMap {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			for (String s : args) {
				if (s.contains("?") || s.contains("help")) {
					printHelp();
					System.exit(1);
				}

			}
			double resolution = Double.parseDouble(args[0]);
			if (resolution == 0) {
				printHelp();
				System.exit(-1);
			}
			long imsi = Long.parseLong(args[1]);
			if (imsi == 0) {
				printHelp();
				System.exit(-1);
			}

			// everything okay until now... do GSMmap
			NMEAParse nmea = new NMEAParse(args[2]);
			sqlreader sql = null;
			sql = new sqlreader(nmea, imsi, 1000);

			for (int i = 3; i < args.length; i++) {
				nmea = new NMEAParse(args[i]);
				sql.merge(new sqlreader(nmea, imsi, 1000));

			}

			Interpolator map = new Interpolator(sql, resolution);
			try {
				map.toGoogleKml("measured.kml");
			} catch (IOException e) {
			}
			System.out
					.println("GSMmap read successfully... Interpolating. This will take some time");
			map.interpolateVR();
			try {
				map.toGoogleKml("interpolated.kml");
			} catch (IOException e) {
			}
			backupOfOldMap();
			map.save("parallel-strictdB-BER.obj");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			System.out.println("Java SQL class not found");
			printHelp();
			System.exit(-2);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			printHelp();
			System.out.println("SQL error. Maybe no Internet?");
			System.exit(-2);
		}
	}

	private static void printHelp() {
		System.out.println();
		System.out.println();
		System.out
				.println("Usage: GenerateMap [resolution] [IMSI] [NMEA files]");
		System.out.println();
		System.out
				.println("Resolution is in degree Longitude and Latitude. For example a resolution of 0.00008 will generate tiles with a size of 9 x 6 meter");
		System.out.println("more than one NMEA (GPS) logfile can be given");
		System.out.println();
		System.out
				.println("Map will automatically be interpolated and stored as parallel-strictdB-BER.obj");
		System.out
				.println("previous map will be renamed to parallel-strictdB-BER.old");

	}

	private static void backupOfOldMap() {
		try {
			File test = new File("parallel-strictdB-BER.obj");
			if (test.isFile()) {
				new File("parallel-strictdB-BER.old").delete();
				test.renameTo(new File("parallel-strictdB-BER.old"));
			}
		} catch (SecurityException e) {

		}
	}
}