Commit b8437c3c authored by duminil's avatar duminil
Browse files

Save selected building IDs as a txt file.

parent 4f424697
package eu.simstadt.regionchooser; package eu.simstadt.regionchooser;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
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;
...@@ -14,6 +17,7 @@ ...@@ -14,6 +17,7 @@
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine; import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView; import javafx.scene.web.WebView;
import javafx.stage.FileChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import netscape.javascript.JSObject; import netscape.javascript.JSObject;
...@@ -66,34 +70,53 @@ public void downloadRegion(String wktPolygon) { ...@@ -66,34 +70,53 @@ public void downloadRegion(String wktPolygon) {
} }
public int downloadRegionFromCityGML(String wktPolygon, String project, String citygml, JSObject featureOverlay) public int downloadRegionFromCityGML(String wktPolygon, String project, String citygml, JSObject featureOverlay)
throws SAXParseException, XMLStreamException, ParseException { throws SAXParseException, XMLStreamException, ParseException, IOException {
// System.out.println("FROM JAVA : DO SOMETHING with " + wktPolygon + " from \n" + project + ">" + citygml); //FIXME: Why is this so slow?
SimStadtModel model = SimStadtProject.loadModelWithoutSchemaValidation(citygmlPath(project, citygml).toFile()); SimStadtModel model = SimStadtProject.loadModelWithoutSchemaValidation(citygmlPath(project, citygml).toFile());
Geometry poly = wktReader.read(wktPolygon); Geometry poly = wktReader.read(wktPolygon);
final GeometryFactory gf = new GeometryFactory(); final GeometryFactory gf = new GeometryFactory();
//TODO: What's the easiest way to get WGS84 coordinates of building center?
for (Building building : model.getCityDoctorBuildings()) { File buildingIdsFile = selectSaveFileWithDialog(project, citygml);
BoundingShape boundedBy = building.getCitygmlBuilding().getBoundedBy(); if (buildingIdsFile != null) {
if (boundedBy != null) { BufferedWriter writer = Files.newBufferedWriter(buildingIdsFile.toPath());
Envelope envelope = boundedBy.getEnvelope();
if (envelope != null) { //TODO: What's the easiest way to get WGS84 coordinates of building center?
List<Double> l = envelope.getLowerCorner().getValue(); for (Building building : model.getCityDoctorBuildings()) {
List<Double> h = envelope.getUpperCorner().getValue(); BoundingShape boundedBy = building.getCitygmlBuilding().getBoundedBy();
double x = (l.get(0) + h.get(0)) * 0.5; if (boundedBy != null) {
double y = (l.get(1) + h.get(1)) * 0.5; Envelope envelope = boundedBy.getEnvelope();
Coordinate coord = new Coordinate(x, y); if (envelope != null) {
Point point = gf.createPoint(coord); List<Double> l = envelope.getLowerCorner().getValue();
if (point.within(poly)) { List<Double> h = envelope.getUpperCorner().getValue();
featureOverlay.call("addMarker", x, y, building.getGmlId()); double x = (l.get(0) + h.get(0)) * 0.5;
System.out.println(building.getGmlId()); double y = (l.get(1) + h.get(1)) * 0.5;
Coordinate coord = new Coordinate(x, y);
Point point = gf.createPoint(coord);
if (point.within(poly)) {
//featureOverlay.call("addMarker", x, y, building.getGmlId());
writer.write(building.getGmlId() + "\r\n");
System.out.println(building.getGmlId());
}
} }
} }
} }
writer.close();
} }
return model.getCityDoctorBuildings().size(); return model.getCityDoctorBuildings().size();
} }
private File selectSaveFileWithDialog(String project, String citygml) {
Stage mainStage = (Stage) Browser.this.getScene().getWindow();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save CITYGML ids");
fileChooser.setInitialDirectory(repo.resolve(project + ".simstadt").toFile());
fileChooser.setInitialFileName(citygml.split("\\.")[0] + "_selected_region");
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)", "*.txt");
fileChooser.getExtensionFilters().add(extFilter);
return fileChooser.showSaveDialog(mainStage);
}
public boolean checkIfCityGMLSAreAvailable(String project, String citygml) { public boolean checkIfCityGMLSAreAvailable(String project, String citygml) {
return Files.isReadable(citygmlPath(project, citygml)); return Files.isReadable(citygmlPath(project, citygml));
} }
......
...@@ -245,7 +245,7 @@ function downloadRegionFromCityGML(i) { ...@@ -245,7 +245,7 @@ function downloadRegionFromCityGML(i) {
var end = new Date().getTime(); var end = new Date().getTime();
var time = end - start; var time = end - start;
console.log('DL Execution time: ' + time); console.log('DL Execution time: ' + time);
$('#dataPanel').append("Imported buildings : " + buildings_count); // $('#dataPanel').append("Imported buildings : " + buildings_count);
$("html").removeClass("wait"); $("html").removeClass("wait");
}, 100); }, 100);
} }
...@@ -267,10 +267,10 @@ function displayInfo() { ...@@ -267,10 +267,10 @@ function displayInfo() {
var gsk3_coord = ol.proj.transform(coords[i], ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:31467')) var gsk3_coord = ol.proj.transform(coords[i], ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:31467'))
gsk3_coords += "(" + gsk3_coord[0] + "," + gsk3_coord[1] + ")<br/>"; gsk3_coords += "(" + gsk3_coord[0] + "," + gsk3_coord[1] + ")<br/>";
} }
$('#dataPanel').append("WGS84 Coordinates<br/>"); // $('#dataPanel').append("WGS84 Coordinates<br/>");
$('#dataPanel').append(wgs84_coords + "<br/>\n"); // $('#dataPanel').append(wgs84_coords + "<br/>\n");
$('#dataPanel').append("GSK3 Coordinates<br/>"); // $('#dataPanel').append("GSK3 Coordinates<br/>");
$('#dataPanel').append(gsk3_coords + "<br/>\n"); // $('#dataPanel').append(gsk3_coords + "<br/>\n");
$('#dataPanel').append("Area" + "<br/>\n"); $('#dataPanel').append("Area" + "<br/>\n");
$('#dataPanel').append((Math.round(area / 1000) / 10).toString() + " ha<br/><br/>\n"); $('#dataPanel').append((Math.round(area / 1000) / 10).toString() + " ha<br/><br/>\n");
findIntersections(); findIntersections();
......
Markdown is supported
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