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