Commit b8437c3c authored by duminil's avatar duminil
Browse files

Save selected building IDs as a txt file.

parent 4f424697
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.Path;
import java.nio.file.Paths;
......@@ -14,6 +17,7 @@
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javax.xml.stream.XMLStreamException;
import netscape.javascript.JSObject;
......@@ -66,34 +70,53 @@ public void downloadRegion(String wktPolygon) {
}
public int downloadRegionFromCityGML(String wktPolygon, String project, String citygml, JSObject featureOverlay)
throws SAXParseException, XMLStreamException, ParseException {
// System.out.println("FROM JAVA : DO SOMETHING with " + wktPolygon + " from \n" + project + ">" + citygml);
throws SAXParseException, XMLStreamException, ParseException, IOException {
//FIXME: Why is this so slow?
SimStadtModel model = SimStadtProject.loadModelWithoutSchemaValidation(citygmlPath(project, citygml).toFile());
Geometry poly = wktReader.read(wktPolygon);
final GeometryFactory gf = new GeometryFactory();
//TODO: What's the easiest way to get WGS84 coordinates of building center?
for (Building building : model.getCityDoctorBuildings()) {
BoundingShape boundedBy = building.getCitygmlBuilding().getBoundedBy();
if (boundedBy != null) {
Envelope envelope = boundedBy.getEnvelope();
if (envelope != null) {
List<Double> l = envelope.getLowerCorner().getValue();
List<Double> h = envelope.getUpperCorner().getValue();
double x = (l.get(0) + h.get(0)) * 0.5;
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());
System.out.println(building.getGmlId());
File buildingIdsFile = selectSaveFileWithDialog(project, citygml);
if (buildingIdsFile != null) {
BufferedWriter writer = Files.newBufferedWriter(buildingIdsFile.toPath());
//TODO: What's the easiest way to get WGS84 coordinates of building center?
for (Building building : model.getCityDoctorBuildings()) {
BoundingShape boundedBy = building.getCitygmlBuilding().getBoundedBy();
if (boundedBy != null) {
Envelope envelope = boundedBy.getEnvelope();
if (envelope != null) {
List<Double> l = envelope.getLowerCorner().getValue();
List<Double> h = envelope.getUpperCorner().getValue();
double x = (l.get(0) + h.get(0)) * 0.5;
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();
}
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) {
return Files.isReadable(citygmlPath(project, citygml));
}
......
......@@ -245,7 +245,7 @@ function downloadRegionFromCityGML(i) {
var end = new Date().getTime();
var time = end - start;
console.log('DL Execution time: ' + time);
$('#dataPanel').append("Imported buildings : " + buildings_count);
// $('#dataPanel').append("Imported buildings : " + buildings_count);
$("html").removeClass("wait");
}, 100);
}
......@@ -267,10 +267,10 @@ function displayInfo() {
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/>";
}
$('#dataPanel').append("WGS84 Coordinates<br/>");
$('#dataPanel').append(wgs84_coords + "<br/>\n");
$('#dataPanel').append("GSK3 Coordinates<br/>");
$('#dataPanel').append(gsk3_coords + "<br/>\n");
// $('#dataPanel').append("WGS84 Coordinates<br/>");
// $('#dataPanel').append(wgs84_coords + "<br/>\n");
// $('#dataPanel').append("GSK3 Coordinates<br/>");
// $('#dataPanel').append(gsk3_coords + "<br/>\n");
$('#dataPanel').append("Area" + "<br/>\n");
$('#dataPanel').append((Math.round(area / 1000) / 10).toString() + " ha<br/><br/>\n");
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