Commit 7fc7500d authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Suppress EPSG logs during nested parsing

parent 2c676fd5
......@@ -19,7 +19,6 @@
package de.hft.stuttgart.citydoctor2.parser;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
......@@ -80,7 +79,6 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xmlobjects.schema.SchemaHandler;
import org.xmlobjects.schema.SchemaHandlerException;
import org.xmlobjects.stream.XMLReader;
......@@ -272,7 +270,7 @@ public class CityGmlParser {
}
try {
parseEpsgCodeFromFile(file, config);
parseEpsgCodeFromFile(file, config, verbose);
CityGMLInputFactory in = context.createCityGMLInputFactory()
.withChunking(ChunkOptions.chunkByProperties(chunkProperties).skipCityModel(false));
try (ObservedInputStream ois = new ObservedInputStream(file.toFile())) {
......@@ -301,7 +299,7 @@ public class CityGmlParser {
public static void streamCityGml(Path file, ParserConfiguration config, ProgressListener l,
CityGmlConsumer cityObjectConsumer, String outputFile) throws CityGmlParseException {
parseEpsgCodeFromFile(file, config);
parseEpsgCodeFromFile(file, config, true);
startReadingCityGmlFile(file, config, l, cityObjectConsumer, outputFile);
}
......@@ -503,15 +501,15 @@ public class CityGmlParser {
}
}
private static void parseEpsgCodeFromFile(Path file, ParserConfiguration config) throws CityGmlParseException {
private static void parseEpsgCodeFromFile(Path file, ParserConfiguration config, boolean verbose) throws CityGmlParseException {
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file.toFile()))) {
parseEpsgCodeFromStream(bis, config);
parseEpsgCodeFromStream(bis, config, verbose);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new CityGmlParseException("Failed to read CityGML file", e);
}
}
private static void parseEpsgCodeFromStream(InputStream is, ParserConfiguration config)
private static void parseEpsgCodeFromStream(InputStream is, ParserConfiguration config, boolean verbose)
throws ParserConfigurationException, SAXException {
SAXParser parser = FACTORY.newSAXParser();
CityGmlHandler handler = new CityGmlHandler();
......@@ -519,14 +517,14 @@ public class CityGmlParser {
parser.parse(new InputSource(is), handler);
} catch (EnvelopeFoundException e) {
try {
parseCoordinateSystem(config, handler);
parseCoordinateSystem(config, handler, verbose);
} catch (Exception e2) {
logEpsgParseError(e2);
}
} catch (Exception e) {
logEpsgParseError(e);
}
if (handler.getEpsg() == null && logger.isInfoEnabled()) {
if (handler.getEpsg() == null && logger.isInfoEnabled() && verbose) {
logger.info(Localization.getText("CityGmlParser.missingEPSGCode"));
}
......@@ -539,7 +537,7 @@ public class CityGmlParser {
}
}
private static void parseCoordinateSystem(ParserConfiguration config, CityGmlHandler handler) {
private static void parseCoordinateSystem(ParserConfiguration config, CityGmlHandler handler, boolean verbose) {
if (handler.getEpsg() == null) {
return;
}
......@@ -547,14 +545,14 @@ public class CityGmlParser {
if (crs == null) {
// could not find a coordinate system for srsName
// assuming metric system
if (logger.isInfoEnabled()) {
if (logger.isInfoEnabled() && verbose) {
logger.info(Localization.getText("CityGmlParser.missingEPSGCode"));
}
return;
}
if (crs.getProjection().getUnits() == Units.METRES) {
// coordinate system is in meters, do not convert
if (logger.isInfoEnabled()) {
if (logger.isInfoEnabled() && verbose) {
logger.info(Localization.getText("CityGmlParser.noConversionNeeded"));
}
return;
......@@ -579,11 +577,15 @@ public class CityGmlParser {
CoordinateReferenceSystem utm;
if (centerLat < 0) {
// south
logger.info(Localization.getText("CityGmlParser.convertCrsToUtmZoneS"), zone);
if (logger.isInfoEnabled() && verbose) {
logger.info(Localization.getText("CityGmlParser.convertCrsToUtmZoneS"), zone);
}
utm = CRS_FACTORY.createFromParameters("UTM", "+proj=utm +ellps=WGS84 +units=m +zone=" + zone + " +south");
} else {
// north
logger.info(Localization.getText("CityGmlParser.convertCrsToUtmZoneN"), zone);
if (logger.isInfoEnabled() && verbose) {
logger.info(Localization.getText("CityGmlParser.convertCrsToUtmZoneN"), zone);
}
utm = CRS_FACTORY.createFromParameters("UTM", "+proj=utm +ellps=WGS84 +units=m +zone=" + zone);
}
config.setCoordinateSystem(crs, utm);
......
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