... | ... | @@ -32,75 +32,122 @@ Although it was not technically required by the assignment instructions, we want |
|
|
Specifically, we wanted to allow user input for these decisions:
|
|
|
|
|
|
|
|
|
**1.** Inform the user that the programme will download the CSV and KML files and **ask them for permission to store the files locally**.
|
|
|
**1.** Allow the user to **accept the default directory or set a new one.**
|
|
|
|
|
|
<details><summary> See the Code</summary>
|
|
|
|
|
|
```java
|
|
|
Scanner askUser = new Scanner(System.in); // warning coming from non-closed scanner. Note: if we close it, subsequent scanners fail to work.
|
|
|
String answer;
|
|
|
|
|
|
// welcome and information for user
|
|
|
System.out.println("Hello! Welcome to this Google Earth Tweet and WMS Mapper!\n\n"
|
|
|
+ "This programme will:\n"
|
|
|
+ "1: download an image of Boston from a WMS\n"
|
|
|
+ "2: convert it into a KML structure\n"
|
|
|
+ "3: download a tweets.csv file from the web\n"
|
|
|
+ "4: convert it into a KML structure\n"
|
|
|
+ "5: launch both kml files in Google Earth\n\n"
|
|
|
+ "The downloaded files will be stored at C:\\Users\\Public\\Documents\n"
|
|
|
+ "If this is fine, please enter Y below and hit enter to continue! If not, we will stop the programme and you can manually change the directory at the very top of this class's code.");
|
|
|
+ "5: create a KML file for a tour in Google Earth\n"
|
|
|
+ "6: launch all kml files in Google Earth\n\n"
|
|
|
+ "By default, the downloaded files will be stored at: C:\\Users\\Public\\Documents"
|
|
|
+ "\nIf this is fine, please enter Y below and hit enter to continue! If not, enter anything else to set a new directory.");
|
|
|
|
|
|
answer = askUser.next();
|
|
|
// askUser.close();
|
|
|
String newDirectory = null;
|
|
|
|
|
|
// if yes, set directory to the default and return directory
|
|
|
if(answer.contains("Y") || answer.contains("y") || answer.contains("yes") || answer.contains("Yes")) {
|
|
|
System.out.println("Great! Lets get started!\n");
|
|
|
directory = "C:\\Users\\Public\\Documents";
|
|
|
return directory;
|
|
|
|
|
|
// else, allow user to enter directory and check if it exists. Otherwise keep asking for a valid directory.
|
|
|
} else {
|
|
|
System.out.println("We've stopped the programme. Please adjust the code and start again!");
|
|
|
System.exit(0);
|
|
|
System.out.println("Please enter a new directory below and hit enter: ");
|
|
|
Scanner askNewDirectory = new Scanner(System.in);
|
|
|
boolean exists = false; // by default, exists is set to "false"
|
|
|
while (exists != true) { // while-loop keeps asking for user input until exists is set to "true"
|
|
|
newDirectory = askNewDirectory.nextLine(); // use .nextLine() to make sure path-files with a space are read
|
|
|
File tempDir = new File(newDirectory);
|
|
|
boolean exists2 = tempDir.exists(); // check if entered directory exists
|
|
|
if (exists2 == true) { // if directory exists, set exists2 to "true"
|
|
|
exists = true; // if exists2 is "true", exists becomes "true" to exit the while loop
|
|
|
directory = newDirectory;
|
|
|
System.out.println("\nNew directory set to: " + directory + "\n");
|
|
|
} else {
|
|
|
System.out.println("\nWrong file path. Please try again.");
|
|
|
}
|
|
|
```
|
|
|
}
|
|
|
return directory;
|
|
|
}
|
|
|
} // askUser1()
|
|
|
|
|
|
```
|
|
|
</details>
|
|
|
|
|
|
|
|
|
**2.** Ask the user if they would like to **see additional information** on the WMS while the programme is running.
|
|
|
|
|
|
|
|
|
<details><summary>See the Code</summary>
|
|
|
```java
|
|
|
Scanner askServiceInfo = new Scanner(System.in); //warning coming from non-closed scanner. Note: if scanner is closed subsequent scanners fail to work.
|
|
|
String answer;
|
|
|
// user interaction: offer additional information
|
|
|
Scanner askServiceInfo = new Scanner(System.in); // warning coming from non-closed scanner. Note: if scanner is closed subsequent scanners fail to work
|
|
|
String answer1;
|
|
|
String answer2;
|
|
|
System.out.println("\nWould you like additional information on the WMS service while the programme runs? Type Y for yes or anything else for no and hit enter.");
|
|
|
answer = askServiceInfo.next();
|
|
|
answer1 = askServiceInfo.next();
|
|
|
// askServiceInfo.close();
|
|
|
|
|
|
if(answer.contains("Y") || answer.contains("y") || answer.contains("yes") || answer.contains("Yes")) {
|
|
|
System.out.println("\tThe WMS capabilities are being retreived from a server called: " + serverName +"\n\tAnd the server's title is: " + serverTitle +"\n\t" +
|
|
|
"The requested image will be stored as a .png with dimensions of 1000 x 1000 pixels.\n\t" +
|
|
|
"The coordinate reference system is set to ESPG:4326.");
|
|
|
System.out.println("\tRequested GetMap URL: " + request.getFinalURL());
|
|
|
if(answer1.contains("Y") || answer1.contains("y") || answer1.contains("yes") || answer1.contains("Yes")) {
|
|
|
// Access WMS Capabilities directly from the WMS
|
|
|
WMSCapabilities capabilities = wms.getCapabilities();
|
|
|
System.out.println("\tThe WMS capabilities are being retreived from a server called: " + capabilities.getService().getName() + "\n\t" // method to access service infos
|
|
|
+ "The server's title is: " + capabilities.getService().getTitle() +"\n\t"
|
|
|
+ "The requested image will be stored as a .png with dimensions of 1000 x 1000 pixels.\n\t"
|
|
|
+ "The coordinate reference system is set to ESPG:4326.\n\t"
|
|
|
+ "The requested GetMap URL is: " + request.getFinalURL());
|
|
|
|
|
|
System.out.println("\nPlease let us know when you are done with this step. Type any keyword and press enter:");
|
|
|
Scanner askNextStep = new Scanner(System.in);
|
|
|
answer2 = askNextStep.next();
|
|
|
// if(answer2.length() != 0){
|
|
|
// }else {
|
|
|
// }
|
|
|
|
|
|
} else {
|
|
|
System.out.println("Alright.");
|
|
|
System.out.println("Alright."); // lowkey annoyed answer hehe ;)
|
|
|
}
|
|
|
```
|
|
|
</details>
|
|
|
|
|
|
|
|
|
**3.** Ask the user if they would like to **proceed to launch** Google Earth.
|
|
|
|
|
|
**3.** Ask the user if they would like to **proceed to launch** Google Earth. This step also made sure that the programme would halt again (giving the user some time to actually read the console output before Google Earth launches). If the users does not answer with some form of "yes", the programme will end with a friendly good-bye message.
|
|
|
|
|
|
|
|
|
<details><summary> See the Code </summary>
|
|
|
```java
|
|
|
static void askUser2() {
|
|
|
|
|
|
// ask user to proceed with google earth launch
|
|
|
Scanner askContinue = new Scanner(System.in);
|
|
|
String answer1;
|
|
|
System.out.println("Would you like to proceed to launch Google Earth now? Type Y for yes or anything else for no and hit enter.");
|
|
|
|
|
|
System.out.println("We have created a small tour to show you the WMS and Tweets in Google Earth. It will automatically begin when Google Earth is launched.\n"
|
|
|
+ "Would you like to proceed to launch Google Earth now? Type Y for yes or anything else for no and hit enter.");
|
|
|
|
|
|
answer1 = askContinue.next();
|
|
|
askContinue.close();
|
|
|
|
|
|
// if yes, proceed with programme execution. Else, exit programme.
|
|
|
if(answer1.contains("Y") || answer1.contains("y") || answer1.contains("yes") || answer1.contains("Yes")) {
|
|
|
System.out.println("Proceeding... ");
|
|
|
} else {
|
|
|
System.out.println("We've ended the programme for you. If you'd like to try again, run the programme again. :)");
|
|
|
System.out.println("We've ended the programme for you. If you'd like to try again, run the programme again. :)"); // Inform
|
|
|
System.exit(0);
|
|
|
}
|
|
|
|
|
|
} // askUer2()
|
|
|
```
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
... | ... | |