Commit 6d96f1b5 authored by Eric Duminil's avatar Eric Duminil
Browse files

RegionChooser: SonarLint

parent ed1874c9
...@@ -348,8 +348,6 @@ public File buildImportJobFile(ImportJobDescription jobDescriptor) ...@@ -348,8 +348,6 @@ public File buildImportJobFile(ImportJobDescription jobDescriptor)
zos.close(); zos.close();
return zippedCityGMLFile; return zippedCityGMLFile;
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import javax.xml.stream.XMLStreamException;
import org.xml.sax.SAXParseException;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader; import com.vividsolutions.jts.io.WKTReader;
...@@ -69,31 +67,19 @@ public void refreshHulls() { ...@@ -69,31 +67,19 @@ public void refreshHulls() {
@Override @Override
public Void call() throws IOException { public Void call() throws IOException {
ConvexHullCalculator.extractHullsForEveryCityGML(repo, ConvexHullCalculator.extractHullsForEveryCityGML(repo,
(hullKML -> { hullKML -> Platform.runLater(() -> jsApp.call("addCityGmlHull", hullKML)));
Platform.runLater(new Runnable() {
@Override
public void run() {
jsApp.call("addCityGmlHull", hullKML);
}
});
}));
return null; return null;
} }
}; };
task.setOnRunning(e -> { task.setOnRunning(e -> jsApp.call("display", "Importing citgyml. Please wait."));
jsApp.call("display", "Importing citgyml. Please wait.");
});
task.setOnSucceeded(e -> { task.setOnSucceeded(e -> jsApp.call("ready"));
jsApp.call("ready");
});
new Thread(task).start(); new Thread(task).start();
} }
public void downloadRegion(String wktPolygon, String productName, JSObject novaFactoryLayer) public void downloadRegion(String wktPolygon, String productName, JSObject novaFactoryLayer) {
throws InterruptedException {
//TODO: Ask nf Server about available regions //TODO: Ask nf Server about available regions
Task<Integer> task = new Task<Integer>() { Task<Integer> task = new Task<Integer>() {
@Override @Override
...@@ -108,44 +94,44 @@ protected Integer call() throws Exception { ...@@ -108,44 +94,44 @@ protected Integer call() throws Exception {
} }
public void extractZIPtoGML(String zipFilename) throws IOException { public void extractZIPtoGML(String zipFilename) throws IOException {
ZipFile zipFile = new ZipFile(zipFilename); try (ZipFile zipFile = new ZipFile(zipFilename)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries(); Enumeration<? extends ZipEntry> entries = zipFile.entries();
String userName = System.getProperty("user.name"); String userName = System.getProperty("user.name");
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipEntry ze = entries.nextElement(); ZipEntry ze = entries.nextElement();
String zeName = ze.getName(); String zeName = ze.getName();
if (zeName.toLowerCase().contains("gml")) { if (zeName.toLowerCase().contains("gml")) {
File extractedCityGML = selectSaveFileWithDialog(null, File extractedCityGML = selectSaveFileWithDialog(null,
zeName.replace("_GML.", ".").replace(userName, "novaFACTORY"), ""); zeName.replace("_GML.", ".").replace(userName, "novaFACTORY"), "");
if (extractedCityGML != null) { if (extractedCityGML != null) {
InputStream cityGMLInputStream = zipFile.getInputStream(ze); try (
BufferedReader cityGMLZipReader = new BufferedReader(new InputStreamReader(cityGMLInputStream)); InputStream cityGMLInputStream = zipFile.getInputStream(ze);
BufferedWriter cityGMLOutput = Files.newBufferedWriter(extractedCityGML.toPath()); BufferedReader cityGMLZipReader = new BufferedReader(
String buf = null; new InputStreamReader(cityGMLInputStream));
while ((buf = cityGMLZipReader.readLine()) != null) { BufferedWriter cityGMLOutput = Files.newBufferedWriter(extractedCityGML.toPath());) {
cityGMLOutput.write(buf.replace("srsName=\"\"", "srsName=\"EPSG:31467\"")); //TODO: Get EPSG:id from NovaFactory Server? String buf = null;
//TODO: Get EPSG:id from NovaFactory Server?
while ((buf = cityGMLZipReader.readLine()) != null) {
cityGMLOutput.write(buf.replace("srsName=\"\"", "srsName=\"EPSG:31467\""));
}
}
LOGGER.info("Extracted");
} }
cityGMLZipReader.close();
cityGMLInputStream.close();
cityGMLOutput.close();
LOGGER.info("Extracted");
} }
} }
} }
zipFile.close();
} }
public void downloadRegionFromCityGML(String wktPolygon, String project, String citygml, String srsName) public void downloadRegionFromCityGML(String wktPolygon, String project, String citygml, String srsName)
throws IOException, ParseException, SAXParseException, XMLStreamException, NumberFormatException, throws IOException, ParseException, XPathParseException, NavException, XPathEvalException {
XPathParseException, NavException, XPathEvalException { StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath(project, citygml), wktPolygon,
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath(project, citygml), wktPolygon,
srsName); srsName);
File buildingIdsFile = selectSaveFileWithDialog(project, citygml, "selected_region"); File buildingIdsFile = selectSaveFileWithDialog(project, citygml, "selected_region");
if (buildingIdsFile != null) { if (buildingIdsFile != null) {
BufferedWriter writer = Files.newBufferedWriter(buildingIdsFile.toPath()); try (BufferedWriter writer = Files.newBufferedWriter(buildingIdsFile.toPath())) {
writer.write(sb.toString()); writer.write(sb.toString());
writer.close(); }
} }
} }
...@@ -181,21 +167,18 @@ private Path citygmlPath(String project, String citygml) { ...@@ -181,21 +167,18 @@ private Path citygmlPath(String project, String citygml) {
} }
public void importNovaFactoryBoundingBoxes() throws IOException { public void importNovaFactoryBoundingBoxes() throws IOException {
BufferedReader nf_csv = new BufferedReader(new InputStreamReader( try (BufferedReader nfCSV = new BufferedReader(new InputStreamReader(
RegionChooserFX.class.getResourceAsStream("website/data/novafactory_products.csv"))); RegionChooserFX.class.getResourceAsStream("website/data/novafactory_products.csv")))) {
nf_csv.readLine(); String sCurrentLine = nfCSV.readLine(); // Header information is ignored.
String sCurrentLine; while ((sCurrentLine = nfCSV.readLine()) != null) {
while ((sCurrentLine = nf_csv.readLine()) != null) { String[] values = sCurrentLine.trim().split(",");
String[] values = sCurrentLine.trim().split(","); String product = values[1];
String product = values[1]; String[] srs = values[3].split(" ");
// String description = values[2]; String epsgId = srs[srs.length - 1];
String[] srs = values[3].split(" "); jsApp.call("addNovaFactoryProduct", values[8], values[9], values[10], values[11], product,
String epsgId = srs[srs.length - 1]; epsgId);
// System.out.println(product); }
jsApp.call("addNovaFactoryProduct", values[8], values[9], values[10], values[11], product,
epsgId);
} }
nf_csv.close();
} }
} }
......
...@@ -44,13 +44,13 @@ ...@@ -44,13 +44,13 @@
* @throws XPathParseException * @throws XPathParseException
* @throws NumberFormatException * @throws NumberFormatException
*/ */
static public StringBuffer selectRegionDirectlyFromCityGML(Path citygmlPath, String wktPolygon, String srsName) static StringBuilder selectRegionDirectlyFromCityGML(Path citygmlPath, String wktPolygon, String srsName)
throws ParseException, NumberFormatException, XPathParseException, NavException, XPathEvalException, throws ParseException, XPathParseException, NavException, XPathEvalException,
IOException { IOException {
int buildingsCount = 0; int buildingsCount = 0;
int foundBuildingsCount = 0; int foundBuildingsCount = 0;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
Geometry poly = wktReader.read(wktPolygon); Geometry poly = wktReader.read(wktPolygon);
CityGmlIterator citygml = new CityGmlIterator(citygmlPath); CityGmlIterator citygml = new CityGmlIterator(citygmlPath);
......
...@@ -35,7 +35,7 @@ public void testExtractRegionWithLocalCRS() throws NumberFormatException, XPathP ...@@ -35,7 +35,7 @@ public void testExtractRegionWithLocalCRS() throws NumberFormatException, XPathP
Path citygmlPath = project.resolve(citygml); Path citygmlPath = project.resolve(citygml);
CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath); CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath);
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, localCRS.getName()); StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, localCRS.getName());
assertTrue("One weird shaped roof should be inside the region", assertTrue("One weird shaped roof should be inside the region",
sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB")); sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"));
} }
...@@ -54,7 +54,7 @@ public void testExtractRegionWithWGS84() throws ParseException, IOException, Num ...@@ -54,7 +54,7 @@ public void testExtractRegionWithWGS84() throws ParseException, IOException, Num
Polygon wgs84Polygon = (Polygon) reader.read(wgs84WktPolygon); Polygon wgs84Polygon = (Polygon) reader.read(wgs84WktPolygon);
CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath); CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath);
String localWktPolygon = writer.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS)); String localWktPolygon = writer.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS));
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon, StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
localCRS.getName()); localCRS.getName());
assertTrue("One weird shaped roof should be inside the region", assertTrue("One weird shaped roof should be inside the region",
sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB")); sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"));
...@@ -103,7 +103,7 @@ public void testExtractRegionWithOldCoordinates() throws ParseException, IOExcep ...@@ -103,7 +103,7 @@ public void testExtractRegionWithOldCoordinates() throws ParseException, IOExcep
Polygon wgs84Polygon = (Polygon) reader.read(wgs84WktPolygon); Polygon wgs84Polygon = (Polygon) reader.read(wgs84WktPolygon);
CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath); CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath);
String localWktPolygon = writer.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS)); String localWktPolygon = writer.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS));
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon, StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
localCRS.getName()); localCRS.getName());
assertTrue("One weird shaped roof should be inside the region", assertTrue("One weird shaped roof should be inside the region",
......
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