Commit 1ef35568 authored by duminil's avatar duminil
Browse files

RegionChooser : Find out which buildings are inside polygon.

parent e218f4b4
...@@ -12,5 +12,6 @@ ...@@ -12,5 +12,6 @@
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="lib/Proj4J.jar"/> <classpathentry kind="lib" path="lib/Proj4J.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/SimStadtRepository"/> <classpathentry combineaccessrules="false" kind="src" path="/SimStadtRepository"/>
<classpathentry kind="lib" path="lib/jts-1.13.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
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.List;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State; import javafx.concurrent.Worker.State;
...@@ -16,7 +17,18 @@ ...@@ -16,7 +17,18 @@
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;
import org.citygml4j.model.gml.feature.BoundingShape;
import org.citygml4j.model.gml.geometry.primitives.DirectPosition;
import org.citygml4j.model.gml.geometry.primitives.Envelope;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import de.hft.stuttgart.citydoctor.datastructure.Building;
import eu.simstadt.admin.SimStadtBuilding;
import eu.simstadt.admin.SimStadtModel; import eu.simstadt.admin.SimStadtModel;
import eu.simstadt.admin.SimStadtProject; import eu.simstadt.admin.SimStadtProject;
...@@ -45,6 +57,7 @@ class Browser extends Region ...@@ -45,6 +57,7 @@ class Browser extends Region
public class JavaScriptFXBridge public class JavaScriptFXBridge
{ {
private Path repo; private Path repo;
private WKTReader wktReader = new WKTReader();
public JavaScriptFXBridge() { public JavaScriptFXBridge() {
repo = Paths.get("../TestRepository"); repo = Paths.get("../TestRepository");
...@@ -55,10 +68,32 @@ public void downloadRegion(String wktPolygon) { ...@@ -55,10 +68,32 @@ public void downloadRegion(String wktPolygon) {
} }
public int downloadRegionFromCityGML(String wktPolygon, String project, String citygml) public int downloadRegionFromCityGML(String wktPolygon, String project, String citygml)
throws SAXParseException, XMLStreamException { throws SAXParseException, XMLStreamException, ParseException {
//Browser.this.getScene().getRoot().setCursor(Cursor.WAIT); //Browser.this.getScene().getRoot().setCursor(Cursor.WAIT);
System.out.println("FROM JAVA : DO SOMETHING with " + wktPolygon + " from \n" + project + ">" + citygml); System.out.println("FROM JAVA : DO SOMETHING with " + wktPolygon + " from \n" + project + ">" + citygml);
SimStadtModel model = SimStadtProject.loadModelWithoutSchemaValidation(citygmlPath(project, citygml).toFile()); SimStadtModel model = SimStadtProject.loadModelWithoutSchemaValidation(citygmlPath(project, citygml).toFile());
Geometry poly = wktReader.read(wktPolygon);
final GeometryFactory gf = new GeometryFactory();
System.out.println(poly);
//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)) {
System.out.println(building.getGmlId());
}
}
}
}
return model.getCityDoctorBuildings().size(); return model.getCityDoctorBuildings().size();
} }
......
...@@ -174,6 +174,7 @@ function findIntersections() { ...@@ -174,6 +174,7 @@ function findIntersections() {
} }
function downloadRegionFromCityGML(i) { function downloadRegionFromCityGML(i) {
//TODO: Disable all links
$("html").addClass("wait"); $("html").addClass("wait");
var feature = kml_source.getFeatures()[i]; var feature = kml_source.getFeatures()[i];
// Waiting 100ms in order to let the cursor change // Waiting 100ms in order to let the cursor change
...@@ -228,6 +229,7 @@ $('#reset').click(function() { ...@@ -228,6 +229,7 @@ $('#reset').click(function() {
draw.finishDrawing(); draw.finishDrawing();
} finally { } finally {
$('#dataPanel').empty(); $('#dataPanel').empty();
$("html").removeClass("wait");
featureOverlay.getFeatures().clear(); featureOverlay.getFeatures().clear();
intersections.clear(); intersections.clear();
reset_btn.disabled = true; reset_btn.disabled = true;
...@@ -244,7 +246,7 @@ $('#send').click(function() { ...@@ -244,7 +246,7 @@ $('#send').click(function() {
function sketchAsWKT() { function sketchAsWKT() {
var wktFormat = new ol.format.WKT(); var wktFormat = new ol.format.WKT();
return wktFormat.writeFeature(sketch, { return wktFormat.writeFeature(sketch, {
dataProjection : ol.proj.get('EPSG:4326'), dataProjection : ol.proj.get('EPSG:31467'),
featureProjection : ol.proj.get('EPSG:3857') featureProjection : ol.proj.get('EPSG:3857')
}) })
} }
......
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