Commit 405be881 authored by duminil's avatar duminil
Browse files

RegionChooser : Choosing where to extract zip file from novaFACTORY.

parent 5fc7827a
...@@ -3,15 +3,20 @@ ...@@ -3,15 +3,20 @@
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task; import javafx.concurrent.Task;
...@@ -89,16 +94,36 @@ protected Integer call() throws Exception { ...@@ -89,16 +94,36 @@ protected Integer call() throws Exception {
new Thread(task).start(); new Thread(task).start();
} }
public void doSomethingWithThisZIP(String zipFilename) { public void doSomethingWithThisZIP(String zipFilename) throws IOException {
System.out.println("Extract zipFile " + zipFilename + " to " + "unkownlocation"); ZipFile zipFile = new ZipFile(zipFilename);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry ze = entries.nextElement();
if (ze.getName().toLowerCase().contains("gml")) {
File extractedCityGML = selectSaveFileWithDialog(null, ze.getName(), "");
if (extractedCityGML != null) {
InputStream cityGMLInputStream = zipFile.getInputStream(ze);
System.out.println("Extract zipFile " + zipFilename + " to " + extractedCityGML);
FileOutputStream fos = new FileOutputStream(extractedCityGML);
byte[] bytes = new byte[1024];
int length;
while ((length = cityGMLInputStream.read(bytes)) >= 0) {
fos.write(bytes, 0, length);
}
cityGMLInputStream.close();
fos.close();
System.out.println("Extracted");
}
}
}
zipFile.close();
} }
public void downloadRegionFromCityGML(String wktPolygon, String project, String citygml) throws IOException, public void downloadRegionFromCityGML(String wktPolygon, String project, String citygml) throws IOException,
ParseException { ParseException {
StringBuffer sb = selectRegionDirectlyFromCityGML(citygmlPath(project, citygml), wktPolygon); StringBuffer sb = selectRegionDirectlyFromCityGML(citygmlPath(project, citygml), wktPolygon);
File buildingIdsFile = selectSaveFileWithDialog(project, citygml); File buildingIdsFile = selectSaveFileWithDialog(project, citygml, "selected_region");
if (buildingIdsFile != null) { if (buildingIdsFile != null) {
BufferedWriter writer = Files.newBufferedWriter(buildingIdsFile.toPath()); BufferedWriter writer = Files.newBufferedWriter(buildingIdsFile.toPath());
writer.write(sb.toString()); writer.write(sb.toString());
...@@ -149,12 +174,20 @@ public StringBuffer selectRegionDirectlyFromCityGML(Path citygmlPath, String wkt ...@@ -149,12 +174,20 @@ public StringBuffer selectRegionDirectlyFromCityGML(Path citygmlPath, String wkt
} }
private File selectSaveFileWithDialog(String project, String citygml) { private File selectSaveFileWithDialog(String project, String citygml, String suffix) {
Stage mainStage = (Stage) Browser.this.getScene().getWindow(); Stage mainStage = (Stage) Browser.this.getScene().getWindow();
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save CITYGML ids"); fileChooser.setTitle("Save CITYGML ids");
fileChooser.setInitialDirectory(repo.resolve(project + ".simstadt").toFile()); if (project != null) {
fileChooser.setInitialFileName(citygml.replace(".", "_selected_region.")); fileChooser.setInitialDirectory(repo.resolve(project + ".simstadt").toFile());
} else {
fileChooser.setInitialDirectory(repo.toFile());
}
if (suffix.isEmpty()) {
fileChooser.setInitialFileName(citygml);
} else {
fileChooser.setInitialFileName(citygml.replace(".", "_" + suffix + "."));
}
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("GML files (*.gml)", "*.gml"); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("GML files (*.gml)", "*.gml");
fileChooser.getExtensionFilters().add(extFilter); fileChooser.getExtensionFilters().add(extFilter);
return fileChooser.showSaveDialog(mainStage); return fileChooser.showSaveDialog(mainStage);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment