diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLWriter.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLWriter.java index c69030b6..c414f14e 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLWriter.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLWriter.java @@ -82,6 +82,7 @@ public class GMLWriter { private final AeriusGMLVersion version; private Boolean formattedOutput = Boolean.TRUE; + private boolean withRepresentation = true; public GMLWriter(final ReceptorGridSettings rgs, final ReferenceGenerator referenceGenerator) { this(rgs, referenceGenerator, LATEST_WRITER_VERSION); @@ -102,6 +103,13 @@ public void setFormattedOutput(final Boolean formattedOutput) { this.formattedOutput = formattedOutput; } + /** + * If called GML Receptors won't be generated with the hexagon representation geometry. + */ + public void setNoReceptorRepresentation() { + this.withRepresentation = false; + } + /** * Get a map of the GML representation (String) for each {@link EmissionSourceFeature} object. * @@ -359,7 +367,7 @@ public void write(final OutputStream outputStream, final IsScenario scenario, fi } private InternalGMLWriter createInternalWriter() throws AeriusException { - return new InternalGMLWriter(receptorGridSettings, referenceGenerator, formattedOutput, version); + return new InternalGMLWriter(receptorGridSettings, referenceGenerator, formattedOutput, version, withRepresentation); } } diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/InternalGMLWriter.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/InternalGMLWriter.java index 249eee9a..26db5b86 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/InternalGMLWriter.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/InternalGMLWriter.java @@ -87,8 +87,9 @@ final class InternalGMLWriter { private final Boolean formattedOutput; InternalGMLWriter(final ReceptorGridSettings rgs, final ReferenceGenerator referenceGenerator, final Boolean formattedOutput, - final AeriusGMLVersion version) throws AeriusException { - writer = GMLVersionWriterFactory.createGMLVersionWriter(rgs.getZoomLevel1(), GMLSchema.getSRSName(rgs.getEPSG().getSrid()), version); + final AeriusGMLVersion version, final boolean withRepresentation) throws AeriusException { + writer = GMLVersionWriterFactory.createGMLVersionWriter(rgs.getZoomLevel1(), GMLSchema.getSRSName(rgs.getEPSG().getSrid()), version, + withRepresentation); this.referenceGenerator = referenceGenerator; this.schema = GMLVersionWriterFactory.getSchema(version); this.formattedOutput = formattedOutput; diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java index 8d7aa901..646e36b2 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java @@ -23,18 +23,19 @@ import nl.overheid.aerius.shared.domain.geo.HexagonZoomLevel; import nl.overheid.aerius.shared.exception.AeriusException; -public class GMLVersionWriterFactory { +public final class GMLVersionWriterFactory { + + private GMLVersionWriterFactory() { + // Util class + } public static GMLVersionWriter createGMLVersionWriter(final HexagonZoomLevel zoomLevel1, final String srsName, - final AeriusGMLVersion aeriusGMLVersion) { - switch (aeriusGMLVersion) { - case V5_1: - return new GMLVersionWriterV51(zoomLevel1, srsName); - case V6_0: - return new GMLVersionWriterV60(zoomLevel1, srsName); - default: - throw new IllegalArgumentException("Aerius GML version is not supported"); - } + final AeriusGMLVersion aeriusGMLVersion, final boolean withRepresentation) { + return switch (aeriusGMLVersion) { + case V5_1 -> new GMLVersionWriterV51(zoomLevel1, srsName); + case V6_0 -> new GMLVersionWriterV60(zoomLevel1, srsName, withRepresentation); + default -> throw new IllegalArgumentException("Aerius GML version is not supported"); + }; } public static Schema getSchema(final AeriusGMLVersion aeriusGMLVersion) throws AeriusException { diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/GMLVersionWriterV60.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/GMLVersionWriterV60.java index 82a3ddd5..3898daf5 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/GMLVersionWriterV60.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/GMLVersionWriterV60.java @@ -81,11 +81,11 @@ public class GMLVersionWriterV60 implements GMLVersionWriter { private final CIMLKMeasure2GML measure2gml; private final CIMLKDispersionLine2GML dispersionLine2gml; - public GMLVersionWriterV60(final HexagonZoomLevel zoomLevel1, final String srsName) { + public GMLVersionWriterV60(final HexagonZoomLevel zoomLevel1, final String srsName, final boolean withRepresentation) { geometry2gml = new Geometry2GML(srsName); source2gml = new Source2GML(geometry2gml); building2gml = new Building2GML(geometry2gml); - result2gml = new Result2GML(geometry2gml, zoomLevel1); + result2gml = new Result2GML(geometry2gml, zoomLevel1, withRepresentation); measure2gml = new CIMLKMeasure2GML(geometry2gml); dispersionLine2gml = new CIMLKDispersionLine2GML(geometry2gml); } diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/Result2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/Result2GML.java index a7f5cbcc..a24e240c 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/Result2GML.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v6_0/togml/Result2GML.java @@ -60,10 +60,12 @@ final class Result2GML { private final Geometry2GML geometry2gml; private final HexagonZoomLevel zoomLevel1; + private final boolean withRepresentation; - public Result2GML(final Geometry2GML geometry2gml, final HexagonZoomLevel zoomLevel1) { + public Result2GML(final Geometry2GML geometry2gml, final HexagonZoomLevel zoomLevel1, final boolean withRepresentation) { this.geometry2gml = geometry2gml; this.zoomLevel1 = zoomLevel1; + this.withRepresentation = withRepresentation; } /** @@ -147,7 +149,7 @@ private List fromEntityReferences(final List getResults(final CalculationPoint aeriusPoint, final Substance[] substances) { final List substanceList = Arrays.asList(substances); final List results = toResultProperties(aeriusPoint, substanceList); diff --git a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLReaderTest.java b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLReaderTest.java index 1bbb7916..5575e856 100644 --- a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLReaderTest.java +++ b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLReaderTest.java @@ -229,7 +229,7 @@ private static MetaData getMetaData() throws AeriusException { metaDataInput.getOptions().getRblCalculationOptions().setMonitorSrm2Year(MONITOR_SRM2_YEAR); metaDataInput.setResultsIncluded(true); final InternalGMLWriter writer = new InternalGMLWriter(gridSettings, GMLTestDomain.TEST_REFERENCE_GENERATOR, Boolean.TRUE, - GMLWriter.LATEST_WRITER_VERSION); + GMLWriter.LATEST_WRITER_VERSION, true); return writer.getWriter().metaData2GML(metaDataInput); } diff --git a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterPerformanceTest.java b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterPerformanceTest.java index 4d422ba8..3cdbb1ec 100644 --- a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterPerformanceTest.java +++ b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterPerformanceTest.java @@ -50,7 +50,7 @@ class GMLWriterPerformanceTest { @Test void testConvertMetaData() throws IOException, AeriusException { final InternalGMLWriter writer = new InternalGMLWriter(GMLTestDomain.getExampleGridSettings(), GMLTestDomain.TEST_REFERENCE_GENERATOR, - Boolean.TRUE, GMLWriter.LATEST_WRITER_VERSION); + Boolean.TRUE, GMLWriter.LATEST_WRITER_VERSION, true); final int numberOfSources = 800000; final List sourceFeatures = new ArrayList<>(numberOfSources); diff --git a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterTest.java b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterTest.java index 48cfb52a..f86d140c 100644 --- a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterTest.java +++ b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLWriterTest.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -69,6 +70,7 @@ class GMLWriterTest { private static final String RECEPTORS_CONCENTRATION_ONLY_FILE = "test_receptors_concentration_only"; private static final String RECEPTORS_EDGE_EFFECT_FILE = "test_receptors_edge_effect"; private static final String RECEPTORS_ALL_FILE = "test_receptors"; + private static final Object RECEPTORS_NO_REPRESENTATION = "test_receptors_no_representation"; private static final String MIXED_FEATURES_FILE = "test_mixed_features"; private static final String PATH_CURRENT_VERSION = GMLWriter.LATEST_WRITER_VERSION.name().toLowerCase() + "/"; @@ -110,7 +112,7 @@ void testConvertInvalidSources() throws IOException, AeriusException { final List sources1 = getExampleEmissionSources(); sources1.get(0).setGeometry(null); - final IllegalArgumentException e = assertThrows( + assertThrows( IllegalArgumentException.class, () -> getConversionResult(converter, sources1), "Emissionsource not allowed to have no geometry."); @@ -216,24 +218,32 @@ private List getExampleEmissionSources() { private static Stream convertReceptorsData() { return Stream.of( - Arguments.of(RECEPTORS_ALL_FILE, true, true, false), - Arguments.of(RECEPTORS_DEPOSITION_ONLY_FILE, true, false, false), - Arguments.of(RECEPTORS_CONCENTRATION_ONLY_FILE, false, true, false), - Arguments.of(RECEPTORS_EDGE_EFFECT_FILE, true, true, true)); + Arguments.of(RECEPTORS_ALL_FILE, Set.of(ConvertReceptorsOptions.INCLUDE_DEPOSITION, ConvertReceptorsOptions.INCLUDE_CONCENTRATION)), + Arguments.of(RECEPTORS_DEPOSITION_ONLY_FILE, Set.of(ConvertReceptorsOptions.INCLUDE_DEPOSITION)), + Arguments.of(RECEPTORS_CONCENTRATION_ONLY_FILE, Set.of(ConvertReceptorsOptions.INCLUDE_CONCENTRATION)), + Arguments.of(RECEPTORS_EDGE_EFFECT_FILE, Set.of(ConvertReceptorsOptions.INCLUDE_DEPOSITION, ConvertReceptorsOptions.INCLUDE_CONCENTRATION, + ConvertReceptorsOptions.INCLUDE_OVERLAPPING)), + Arguments.of(RECEPTORS_NO_REPRESENTATION, Set.of(ConvertReceptorsOptions.INCLUDE_DEPOSITION, ConvertReceptorsOptions.INCLUDE_CONCENTRATION, + ConvertReceptorsOptions.NO_REPRESENTATION))); } @ParameterizedTest(name = "Testfile: {0}") @MethodSource("convertReceptorsData") - void testConvertReceptors(final String receptorFile, final boolean includeDeposition, final boolean includeConcentration, - final boolean includeOverlapping) throws IOException, AeriusException { - final ArrayList receptors = getExampleAeriusPoints(includeDeposition, includeConcentration, includeOverlapping); + void testConvertReceptors(final String receptorFile, final Set options) throws IOException, AeriusException { + final ArrayList receptors = getExampleAeriusPoints( + ConvertReceptorsOptions.INCLUDE_DEPOSITION.in(options), + ConvertReceptorsOptions.INCLUDE_CONCENTRATION.in(options), + ConvertReceptorsOptions.INCLUDE_OVERLAPPING.in(options)); final MetaDataInput metaDataInput = getMetaDataInput(new ScenarioMetaData()); metaDataInput.setName(null); metaDataInput.setReference(null); metaDataInput.setSituationType(null); metaDataInput.setResultsIncluded(true); final GMLWriter writer = new GMLWriter(RECEPTOR_GRID_SETTINGS, GMLTestDomain.TEST_REFERENCE_GENERATOR); - String result; + if (ConvertReceptorsOptions.NO_REPRESENTATION.in(options)) { + writer.setNoReceptorRepresentation(); + } + final String result; try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { writer.writeAeriusPoints(bos, receptors, metaDataInput); result = bos.toString(StandardCharsets.UTF_8.name()); @@ -387,4 +397,26 @@ private ScenarioMetaData getScenarioMetaData() { return metaData; } + private enum ConvertReceptorsOptions { + /** + * Include deposition results. + */ + INCLUDE_DEPOSITION, + /** + * Include concentration results. + */ + INCLUDE_CONCENTRATION, + /** + * Include edge effect results. + */ + INCLUDE_OVERLAPPING, + /** + * Don't include hexagon representation geometry. + */ + NO_REPRESENTATION; + + public boolean in(final Set options) { + return options.contains(this); + } + } } diff --git a/source/imaer-gml/src/test/resources/gml/v6_0/test_receptors_no_representation.gml b/source/imaer-gml/src/test/resources/gml/v6_0/test_receptors_no_representation.gml new file mode 100644 index 00000000..7bded25c --- /dev/null +++ b/source/imaer-gml/src/test/resources/gml/v6_0/test_receptors_no_representation.gml @@ -0,0 +1,216 @@ + + + + + + + 2013 + + + + + NATURE_AREA + NOX + NH3 + NO2 + CONCENTRATION + DEPOSITION + 3.0 + + + monitor_srm2_year + 2030 + + + + + OFF_SITE_REDUCTION + Our Other Situation + OtherReferenceThingy + + + + + + + V1.1 + SomeDBVersion + + + + + + + + + NL.IMAER + CP.1 + + + + + 137558.0 456251.0 + + + + + 95.8 + + + + + 8546.77 + + + + + 3.001 + + + + + 968.3 + + + + + + + + + NL.IMAER + CP.2 + + + + + 207413.0 475162.0 + + + + + 1574.4 + + + + + 787.2 + + + + + 98.4 + + + + + 49.2 + + + + + 50380.8 + + + + + 12595.2 + + + + + 201523.2 + + + DB-team 1e depositie + + + + + + + NL.IMAER + CP.3 + + + + + 207403.0 475102.0 + + + DB-team 2e depositie + + + + + + + NL.IMAER + SP.1_19 + + + + + 137548.0 137548.0 + + + + + 223.03 + + + + + 382.11 + + + + + 9.006 + + + + + 32.1 + + + 2 + + + + + + + NL.IMAER + SP.2_19 + + + + + 137538.0 456231.0 + + + + + 42.42 + + + + + 182.31 + + + + + 5.0 + + + + + 22.3 + + + 2 + + +