Update End of Term Assignment authored by Zorenböhmer Christina's avatar Zorenböhmer Christina
......@@ -102,15 +102,15 @@ Scanner askServiceInfo = new Scanner(System.in); //warning coming from non-close
## Step 1: Conceptualisation and Creating a Main, Executable Class
## Conceptualisation and Creating a Main Executable Class
### 1.1: Concept
### Concept
At the outset we began gathering ideas and drawing up concepts for our approach. We have visualised our concept below:
![SWD1](uploads/d5adef0d9577217d56ef2b8d1614458c/SWD1.png)
### 1.2: Create Main, Executable Class
### The Main Executable Class
Although this class could not be completed until we had created all other classes, we will begin with this class since it provides a neat summary of how all components for our project come together.
......@@ -120,17 +120,16 @@ As stated above, we aimed to make the whole programme run smoothly without the u
```java
package Test2;
package eot_Sahinovic_Woehs_Zorenboehmer;
public class execute_programme {
public class GoogleEarthTweetMapper {
public static String directory = "C:\\Users\\Christina\\Documents\\EoT"; //ADAPT NAME
// public static String directory = setDirectories.directory;
public static String google_earth_filepath = "C:\\Program Files\\Google\\Google Earth Pro\\client\\googleearth.exe"; // ADAPT to where Google Earth is
public static String directory = "C:\\Users\\Public\\Documents";
public static String google_earth_filepath = "C:\\Program Files\\Google\\Google Earth Pro\\client\\googleearth.exe";
public static String wms_url ="http://maps.heigit.org/osm-wms/service?service=WMS&request=GetCapabilities&version=1.1.0";
public static String wms_png = directory + "\\boston.png";
public static String wms_kml = directory + "\\wms_kml_structure.kml";
public static String wms_kml = directory + "\\boston.kml";
public static String twitter_url = "http://www.berndresch.com/work/twitter.csv";
public static String twitter_csv = directory + "\\tweets.csv";
......@@ -140,30 +139,32 @@ public class execute_programme {
public static void main(String[] args) {
// setDirectories.askUser();
// Welcome, inform user of local directory and ask to proceed
userInput1.askUser();
// run method getMap from class bostonWMS_GetMap
// getMap and store locally
wms_GetMap.getMap();
System.out.println("Step 1 completed.\n");
System.out.println(" --- Step 1 completed. ---\n");
// turn wms into kml
// Turn WMS into KML
wms_ImageToKML.wmsTOkml();
System.out.println("Step 2 completed.\n");
System.out.println(" --- Step 2 completed. --- \n");
// dowload tweets CSV from web
// Download tweets CSV from web
tweets_download.downloadCSV();
System.out.println("Step 3 completed.\n");
System.out.println(" --- Step 3 completed. --- \n");
// access local CSV tweets file and turn into kml
// Access local CSV tweets file and turn into KML
tweets_CSVtoKML.CSVtoKML();
System.out.println("Step 4 completed.\n");
System.out.println(" --- Step 4 completed. --- \n");
// ask if user wants to continue
userInput2.userInput2();
// Ask to proceed with launch
userInput2.askUser2();
System.out.println("Continued.\n");
// Launch
googleEarth_launch.launchGoogleEarth();
System.out.println("Step 5 completed.\n");
System.out.println(" --- Step 5 completed. --- \n");
}
}
......@@ -171,6 +172,66 @@ public class execute_programme {
</details>
## Step 1: Inform User, Ask for Permission to Store Files Locally
In this first step we ask the user to give us the "thumbs up" for downloading the required files onto their PC. We specify the location, which is set to "C:/Users/Public/Documents", which is a default file path that can apply to any PC.
<details><summary> See the Code for the "userInput1.java class here</summary>
```java
package eot_Sahinovic_Woehs_Zorenboehmer;
import java.util.Scanner;
public class userInput1 {
String directory = GoogleEarthTweetMapper.directory;
static void askUser() {
Scanner askUser = new Scanner(System.in); // warning coming from non-closed scanner. Note: if we close it, subsequent scanners fail to work.
String answer;
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.");
answer = askUser.next();
// askUser.close();
if(answer.contains("Y") || answer.contains("y") || answer.contains("yes") || answer.contains("Yes")) {
System.out.println("Great! Lets get started!\n");
} else {
System.out.println("We've stopped the programme. Please adjust the code and start again!");
System.exit(0);
}
} // askUser()
} // class
```
<details><summary> See the console output </summary>
```java
Hello! Welcome to this Google Earth Tweet and WMS Mapper!
This programme will:
1: download an image of Boston from a WMS
2: convert it into a KML structure
3: download a tweets.csv file from the web
4: convert it into a KML structure
5: launch both kml files in Google Earth
The downloaded files will be stored at C:\Users\Public\Documents
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.
y
Great! Lets get started!
```
</details>
## Step 2: Web Map Service
......@@ -187,8 +248,7 @@ First, we created a [non-executable class "wms_GetMap"](https://git.sbg.ac.at/s1
<details><summary> See the Code for the "wms_GetMap.java" class here</summary>
```java
package Test2;
package eot_Sahinovic_Woehs_Zorenboehmer;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -209,22 +269,19 @@ public class wms_GetMap {
static void getMap() {
String wms_url = execute_programme.wms_url;
String directory = execute_programme.directory;
String wms_png = execute_programme.wms_png;
System.out.println("Accessing WMS and downloading .png of Boston to local directory at: " + wms_png + "... ");
String wms_url = GoogleEarthTweetMapper.wms_url;
String wms_png = GoogleEarthTweetMapper.wms_png;
// Constructing a WebMapServer object:
// Check if WMS URL is valid
URL url = null;
try {
System.out.println("Testing Heigit's wms service URL... ");
System.out.print("Testing Heigit's wms service URL... ");
url = new URL(wms_url);
System.out.println("URL vaid.");
} catch (MalformedURLException e) {
System.out.println("Error related to URL.");
}
// Construct WMS object
WebMapServer wms = null;
try {
wms = new WebMapServer(url);
......@@ -235,17 +292,17 @@ public class wms_GetMap {
}
System.out.println("No errors in communicating with the server.");
// You can retrieve a WMSCapabilities directly from your WebMapService. This capabilities bean is split into three sections: Service, Request, and Layer.
// Access WMSCapabilities directly from the WMS. This capabilities bean is split into three sections: Service, Request, and Layer.
WMSCapabilities capabilities = wms.getCapabilities();
// Get information on the service
String serverName = capabilities.getService().getName();
String serverTitle = capabilities.getService().getTitle();
// Get Map Request: ask the client to create a GetMapRequest object. MAKE SURE TO IMPORT THE CORRECT GETMAPREQUEST: import org.geotools.ows.wms.request.GetMapRequest;
// Get Map Request: ask client to create a GetMapRequest object
GetMapRequest request = wms.createGetMapRequest();
// Configure the request object:
// Configure the request object
request.addLayer("osm_auto:all", "default");
request.setFormat("image/png");
request.setDimensions("1000", "1000");
......@@ -254,39 +311,37 @@ public class wms_GetMap {
request.setVersion("1.1.1");
request.setBBox("-71.13,42.32,-71.03,42.42");
Scanner askServiceInfo = new Scanner(System.in); //warning coming from non-closed scanner
// 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 answer;
System.out.println("Would you like additional information on the WMS service while the programme runs? Type Y for yes or anything else for no and hit enter.");
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();
// askServiceInfo.close();
if(answer.contains("Y") || answer.contains("y") || answer.contains("yes") || answer.contains("Yes")) {
System.out.println("The WMS capabilities are being retreived from a server called: " + serverName +"\nAnd the server's title is :" + serverTitle +".\n\n" +
"The requested image will be stored as a .png with dimensions of 1000 x 1000 pixels." +
"The coordinate reference system is set to ESPG:4326");
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());
} else {
System.out.println("Alright.");
}
System.out.println("\n\nRequested URL: " + request.getFinalURL());
try {
GetMapResponse response = (GetMapResponse) wms.issueRequest(request);
BufferedImage image = ImageIO.read(response.getInputStream());
ImageIO.write(image, "png", new File(directory + "\\boston.png"));
ImageIO.write(image, "png", new File(wms_png));
} catch (IOException e) {
System.out.println("There was an error writing the image.");
System.out.println("\nThere was an error writing the image.");
} catch (ServiceException e) {
e.printStackTrace();
}
System.out.println("Image was successfully saved at: " + directory + "\\boston.png");
}
System.out.println("\nImage was successfully saved at: " + wms_png);
}
}
```
</details>
......@@ -295,21 +350,19 @@ public class wms_GetMap {
<details><summary>See Console Output</summary>
```
Accessing WMS and downloading .png of Boston to local directory at: C:\Users\Christina\Documents\EoT\boston.png...
Testing Heigit's wms service URL...
URL vaid.
No errors in communicating with the server.
Testing Heigit's wms service URL... No errors in communicating with the server.
Would you like additional information on the WMS service while the programme runs? Type Y for yes or anything else for no and hit enter.
y
The WMS capabilities are being retreived from a server called: OGC:WMS
And the server's title is :OSM-WMS Uni Heidelberg.
The requested image will be stored as a .png with dimensions of 1000 x 1000 pixels.
The coordinate reference system is set to ESPG:4326
Requested GetMap URL: http://maps.heigit.org/osm-wms/service?REQUEST=GetMap&FORMAT=image%2Fpng&SRS=EPSG:4326&BBOX=-71.13,42.32,-71.03,42.42&VERSION=1.1.1&STYLES=default&SERVICE=WMS&WIDTH=1000&HEIGHT=1000&TRANSPARENT=TRUE&LAYERS=osm_auto%3Aall
The requested image will be stored as a .png with dimensions of 1000 x 1000 pixels.The coordinate reference system is set to ESPG:4326
Requested URL: http://maps.heigit.org/osm-wms/service?REQUEST=GetMap&FORMAT=image%2Fpng&SRS=EPSG:4326&BBOX=-71.13,42.32,-71.03,42.42&VERSION=1.1.1&STYLES=default&SERVICE=WMS&WIDTH=1000&HEIGHT=1000&TRANSPARENT=TRUE&LAYERS=osm_auto%3Aall
Image was successfully saved at: C:\Users\Christina\Documents\EoT\boston.png
Step 1 completed.
Image was successfully saved at: C:\Users\Public\Documents\boston.png
--- Step 1 completed. ---
```
</details>
......
......