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