diff --git a/src/eu/simstadt/regionchooser/RegionChooserFX.java b/src/eu/simstadt/regionchooser/RegionChooserFX.java index 7af2b245b6293341f2de31a2b2de016b361df9b0..c90cb07242708e43b81d9d8d666dce3a1aa6dc1a 100644 --- a/src/eu/simstadt/regionchooser/RegionChooserFX.java +++ b/src/eu/simstadt/regionchooser/RegionChooserFX.java @@ -1,5 +1,8 @@ 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)); } diff --git a/website/script/simstadt_openlayers.js b/website/script/simstadt_openlayers.js index 9d6c451798ac38219b49cec7988756cb9ded2f6b..6d2aec48dc77a3502f880dbb07089dcd14608766 100644 --- a/website/script/simstadt_openlayers.js +++ b/website/script/simstadt_openlayers.js @@ -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();