From 242c38073af38e7b096de87f41e55557701dab71 Mon Sep 17 00:00:00 2001 From: Dominic Burger Date: Thu, 7 Nov 2024 11:49:33 +0100 Subject: [PATCH 1/3] Define XTF to DXF layer mappings --- .gitignore | 3 ++ build.gradle | 2 + .../lk2dxf/mapping/LayerMapping.java | 24 +++++++++ .../lk2dxf/mapping/MappingConverter.java | 29 +++++++++++ .../lk2dxf/mapping/MappingReader.java | 47 ++++++++++++++++++ src/main/resources/mappings.csv | 49 +++++++++++++++++++ .../lk2dxf/mapping/MappingConverterTest.java | 39 +++++++++++++++ .../lk2dxf/mapping/MappingReaderTest.java | 22 +++++++++ 8 files changed, 215 insertions(+) create mode 100644 src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java create mode 100644 src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverter.java create mode 100644 src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingReader.java create mode 100644 src/main/resources/mappings.csv create mode 100644 src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverterTest.java create mode 100644 src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java diff --git a/.gitignore b/.gitignore index 7577384..e745b3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Created by https://www.toptal.com/developers/gitignore/api/intellij,java,gradle # Edit at https://www.toptal.com/developers/gitignore?templates=intellij,java,gradle +# Resources in build output +bin/ + ### Intellij ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 diff --git a/build.gradle b/build.gradle index 904abdf..4ccf62e 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,8 @@ dependencies { implementation 'commons-cli:commons-cli:1.9.0' + implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.18.1' + testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' } diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java new file mode 100644 index 0000000..7770b89 --- /dev/null +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java @@ -0,0 +1,24 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.List; +import java.util.Map; + +public record LayerMapping( + String layer, + String objectType, + String geometry, + int color, + String orientation, + String vAlign, + String hAlign, + String text, + String symbol, + String linetype, + double lineweight, + double textsize, + String font, + @JsonDeserialize(converter = MappingConverter.class) + Map> mapping) { +} diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverter.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverter.java new file mode 100644 index 0000000..d9477d6 --- /dev/null +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverter.java @@ -0,0 +1,29 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import com.fasterxml.jackson.databind.util.StdConverter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class MappingConverter extends StdConverter>> { + /** + * Pattern to match key-value pairs using the format {@code key=value} separated by whitespace. + */ + private static final Pattern MAPPING_PATTERN = Pattern.compile("(?<=^|\\s)(.*?)=(.*?)(?=$|\\s)"); + private static final Pattern VALUE_SEPARATOR = Pattern.compile("\\|"); + + @Override + public Map> convert(String s) { + Map> mappings = new HashMap<>(); + Matcher matcher = MAPPING_PATTERN.matcher(s); + while (matcher.find()) { + String key = matcher.group(1); + String value = matcher.group(2); + mappings.put(key, List.of(VALUE_SEPARATOR.split(value))); + } + return mappings; + } +} diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingReader.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingReader.java new file mode 100644 index 0000000..eb9539c --- /dev/null +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/MappingReader.java @@ -0,0 +1,47 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.MappingIterator; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.dataformat.csv.CsvMapper; +import com.fasterxml.jackson.dataformat.csv.CsvParser; +import com.fasterxml.jackson.dataformat.csv.CsvSchema; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +public final class MappingReader { + private static final String MAPPING_RESOURCE = "/mappings.csv"; + private static final CsvMapper MAPPER = CsvMapper + .builder() + .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) + .build(); + + private MappingReader() { } + + /** + * Reads the XTF to DXF layer mappings from the CSV resource file. + * + * @return the list of mappings + * @throws IOException if an I/O error occurs + */ + public static List readMappings() throws IOException { + CsvSchema headerSchema = CsvSchema.emptySchema().withHeader(); + ObjectReader reader = MAPPER + .readerFor(LayerMapping.class) + .with(headerSchema) + .with(CsvParser.Feature.TRIM_SPACES); + + try ( + InputStream csvStream = openMappingResource(); + MappingIterator it = reader.readValues(csvStream) + ) { + return it.readAll(); + } + } + + private static InputStream openMappingResource() { + return MappingReader.class.getResourceAsStream(MAPPING_RESOURCE); + } +} diff --git a/src/main/resources/mappings.csv b/src/main/resources/mappings.csv new file mode 100644 index 0000000..357f742 --- /dev/null +++ b/src/main/resources/mappings.csv @@ -0,0 +1,49 @@ +Layer ,ObjectType ,Geometry ,Color ,Orientation ,VAlign ,HAlign ,Text ,Symbol ,Linetype ,Lineweight ,Textsize ,Font ,Mapping +STILLGELEGTE-LEITUNGEN ,LKLinie ,Linie ,8 , , , , , ,Crossed ,0.25 , , ,Status=tot +ABW-LINIEFWK-GENAU ,LKLinie ,Linie ,210 , , , , , ,Continuous ,0.25 , , ,Objektart=Abwasser.Fernwirkkabel Lagebestimmung=genau +ABW-LINIEFWK-UNGENAU ,LKLinie ,Linie ,210 , , , , , ,Dashed ,0.25 , , ,Objektart=Abwasser.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +ABW-LINIE-GENAU ,LKLinie ,Linie ,210 , , , , , ,Continuous ,0.25 , , ,Objektart=Abwasser.Haltung_Kanal|Abwasser.Schutzrohr Lagebestimmung=genau +ABW-LINIE-UNGENAU ,LKLinie ,Linie ,210 , , , , , ,Dashed ,0.25 , , ,Objektart=Abwasser.Haltung_Kanal|Abwasser.Schutzrohr Lagebestimmung=ungenau|unbekannt +ABW-FLAECHE ,LKFlaeche ,Flaeche ,210 , , , , , , , , , ,Objektart=Abwasser +ABW-PUNKT ,LKPunkt ,SymbolPos ,210 ,SymbolOri , , , ,BAW15 , , , , ,Objektart=Abwasser +ABW-TEXT ,LKObjekt_Text ,TextPos ,210 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Abwasser +ELE-LINIE-GENAU ,LKLinie ,Linie ,10 , , , , , ,Continuous ,0.25 , , ,Objektart=Elektrizitaet.Trasse.unterirdisch Lagebestimmung=genau +ELE-LINIE-UNGENAU ,LKLinie ,Linie ,10 , , , , , ,Dashed ,0.25 , , ,Objektart=Elektrizitaet.Trasse.unterirdisch Lagebestimmung=ungenau|unbekannt +ELE-LINIE-OBERIRDISCH ,LKLinie ,Linie ,10 , , , , , ,Continuous ,0.25 , , ,Objektart=Elektrizitaet.Trasse.oberirdisch|Elektrizitaet.AnkerStrebe +ELE-FLAECHE ,LKFlaeche ,Flaeche ,10 , , , , , , , , , ,Objektart=Elektrizitaet +ELE-PUNKT ,LKPunkt ,SymbolPos ,10 ,SymbolOri , , , ,BEW978 , , , , ,Objektart=Elektrizitaet +ELE-TEXT ,LKObjekt_Text ,TextPos ,10 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Elektrizitaet +GAS-LINIEFWK-GENAU ,LKLinie ,Linie ,22 , , , , , ,Continuous ,0.25 , , ,Objektart=Gas.Fernwirkkabel Labebestimmung=genau +GAS-LINIEFWK-UNGENAU ,LKLinie ,Linie ,22 , , , , , ,Dashed ,0.25 , , ,Objektart=Gas.Fernwirkkabel Labebestimmung=ungenau|unbekannt +GAS-LINIE-GENAU ,LKLinie ,Linie ,22 , , , , , ,Continuous ,0.25 , , ,Objektart=Gas.Leitung|Gas.Schutzrohr Labebestimmung=genau +GAS-LINIE-UNGENAU ,LKLinie ,Linie ,22 , , , , , ,Dashed ,0.25 , , ,Objektart=Gas.Leitung|Gas.Schutzrohr Labebestimmung=ungenau|unbekannt +GAS-FLAECHE ,LKFlaeche ,Flaeche ,22 , , , , , , , , , ,Objektart=Gas +GAS-PUNKT ,LKPunkt ,SymbolPos ,22 ,SymbolOri , , , ,BGA957 , , , , ,Objektart=Gas +GAS-TEXT ,LKObjekt_Text ,TextPos ,22 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Gas +WAS-LINIEFWK-GENAU ,LKLinie ,Linie ,170 , , , , , ,Continuous ,0.25 , , ,Objektart=Wasser.Fernwirkkabel Lagebestimmung=genau +WAS-LINIEFWK-UNGENAU ,LKLinie ,Linie ,170 , , , , , ,Dashed ,0.25 , , ,Objektart=Wasser.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +WAS-LINIE-GENAU ,LKLinie ,Linie ,170 , , , , , ,Continuous ,0.25 , , ,Objektart=Wasser.Leitung|Wasser.Schutzrohr Lagebestimmung=genau +WAS-LINIE-UNGENAU ,LKLinie ,Linie ,170 , , , , , ,Dashed ,0.25 , , ,Objektart=Wasser.Leitung|Wasser.Schutzrohr Lagebestimmung=ungenau|unbekannt +WAS-FLAECHE ,LKFlaeche ,Flaeche ,170 , , , , , , , , , ,Objektart=Wasser +WAS-PUNKT ,LKPunkt ,SymbolPos ,170 ,SymbolOri , , , ,BWA15 , , , , ,Objektart=Wasser +WAS-TEXT ,LKObjekt_Text ,TextPos ,170 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Wasser +FER-LINIEFWK-GENAU ,LKLinie ,Linie ,30 , , , , , ,Continuous ,0.25 , , ,Objektart=Fernwaerme.Fernwirkkabel Lagebestimmung=genau +FER-LINIEFWK-UNGENAU ,LKLinie ,Linie ,30 , , , , , ,Dashed ,0.25 , , ,Objektart=Fernwaerme.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +FER-LINIE-GENAU ,LKLinie ,Linie ,30 , , , , , ,Continuous ,0.25 , , ,Objektart=Fernwaerme.Trasse Lagebestimmung=genau +FER-LINIE-UNGENAU ,LKLinie ,Linie ,30 , , , , , ,Dashed ,0.25 , , ,Objektart=Fernwaerme.Trasse Lagebestimmung=ungenau|unbekannt +FER-FLAECHE ,LKFlaeche ,Flaeche ,30 , , , , , , , , , ,Objektart=Fernwaerme +FER-PUNKT ,LKPunkt ,SymbolPos ,30 ,SymbolOri , , , ,BWA965 , , , , ,Objektart=Fernwaerme +FER-TEXT ,LKObjekt_Text ,TextPos ,30 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Fernwaerme +KOM-LINIE-GENAU ,LKLinie ,Linie ,80 , , , , , ,Continuous ,0.25 , , ,Objektart=Kommunikation.Trasse.unterirdisch Lagebestimmung=genau +KOM-LINIE-UNGENAU ,LKLinie ,Linie ,80 , , , , , ,Dashed ,0.25 , , ,Objektart=Kommunikation.Trasse.unterirdisch Lagebestimmung=ungenau|unbekannt +KOM-LINIE-OBERIRDISCH ,LKLinie ,Linie ,80 , , , , , ,Continuous ,0.25 , , ,Objektart=Kommunikation.Trasse.oberirdisch +KOM-FLAECHE ,LKFlaeche ,Flaeche ,80 , , , , , , , , , ,Objektart=Kommunikation +KOM-PUNKT ,LKPunkt ,SymbolPos ,80 ,SymbolOri , , , ,BEW15 , , , , ,Objektart=Kommunikation +KOM-TEXT ,LKObjekt_Text ,TextPos ,80 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Kommunikation +WEI-LINIEFWK-GENAU ,LKLinie ,Linie ,50 , , , , , ,Continuous ,0.25 , , ,Objektart=weitereMedien.Fernwirkkabel Lagebestimmung=genau +WEI-LINIEFWK-UNGENAU ,LKLinie ,Linie ,50 , , , , , ,Dashed ,0.25 , , ,Objektart=weitereMedien.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +WEI-LINIE-GENAU ,LKLinie ,Linie ,50 , , , , , ,Continuous ,0.25 , , ,Objektart=weitereMedien.Leitung|weitereMedien.Schutzrohr Lagebestimmung=genau +WEI-LINIE-UNGENAU ,LKLinie ,Linie ,50 , , , , , ,Dashed ,0.25 , , ,Objektart=weitereMedien.Leitung|weitereMedien.Schutzrohr Lagebestimmung=ungenau|unbekannt +WEI-FLAECHE ,LKFlaeche ,Flaeche ,50 , , , , , , , , , ,Objektart=weitereMedien +WEI-PUNKT ,LKPunkt ,SymbolPos ,50 ,SymbolOri , , , ,BEW15 , , , , ,Objektart=weitereMedien +WEI-TEXT ,LKObjekt_Text ,TextPos ,50 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=weitereMedien diff --git a/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverterTest.java b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverterTest.java new file mode 100644 index 0000000..f176930 --- /dev/null +++ b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingConverterTest.java @@ -0,0 +1,39 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public final class MappingConverterTest { + @Test + public void convertSingleValue() { + var converter = new MappingConverter(); + var result = converter.convert("key=value"); + assertEquals(Map.of("key", List.of("value")), result); + } + + @Test + public void convertMultipleMappings() { + var converter = new MappingConverter(); + var result = converter.convert("key=value key2=abc"); + + var expected = Map.of( + "key", List.of("value"), + "key2", List.of("abc")); + assertEquals(expected, result); + } + + @Test + public void convertMultipleValues() { + var converter = new MappingConverter(); + var result = converter.convert("key=value1|value2 key2=abc"); + + var expected = Map.of( + "key", List.of("value1", "value2"), + "key2", List.of("abc")); + assertEquals(expected, result); + } +} diff --git a/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java new file mode 100644 index 0000000..c1db0a7 --- /dev/null +++ b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java @@ -0,0 +1,22 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public final class MappingReaderTest { + @Test + public void readMappings() throws IOException { + List mappings = MappingReader.readMappings(); + + assertTrue(mappings.stream().noneMatch(m -> m.layer().isBlank()), "Layer is required"); + assertTrue(mappings.stream().noneMatch(m -> m.objectType().isBlank()), "ObjectType is required"); + assertTrue(mappings.stream().noneMatch(m -> m.geometry().isBlank()), "Geometry is required"); + assertTrue(mappings.stream().noneMatch(m -> m.mapping().isEmpty()), "Mapping is required"); + assertEquals("STILLGELEGTE-LEITUNGEN", mappings.getFirst().layer()); + } +} From 83bcb465439d6decd3cff705103246b6758ce000 Mon Sep 17 00:00:00 2001 From: Dominic Burger Date: Thu, 7 Nov 2024 16:56:39 +0100 Subject: [PATCH 2/3] Map IomObjects to DXF layers --- .../java/ch/geowerkstatt/lk2dxf/Main.java | 9 +- ...{GeometryObject.java => MappedObject.java} | 14 +-- .../lk2dxf/mapping/ObjectMapper.java | 99 ++++++++++++++++ src/test/data/MapperTest/MapWithText.xtf | 112 ++++++++++++++++++ .../lk2dxf/mapping/ObjectMapperTest.java | 31 +++++ 5 files changed, 254 insertions(+), 11 deletions(-) rename src/main/java/ch/geowerkstatt/lk2dxf/{GeometryObject.java => MappedObject.java} (81%) create mode 100644 src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java create mode 100644 src/test/data/MapperTest/MapWithText.xtf create mode 100644 src/test/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapperTest.java diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/Main.java b/src/main/java/ch/geowerkstatt/lk2dxf/Main.java index 4c0dac1..efcf7b2 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/Main.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/Main.java @@ -1,5 +1,6 @@ package ch.geowerkstatt.lk2dxf; +import ch.geowerkstatt.lk2dxf.mapping.ObjectMapper; import com.vividsolutions.jts.geom.Geometry; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; @@ -54,18 +55,18 @@ public static void main(String[] args) { private static void processFiles(LK2DxfOptions options) { Optional perimeter = options.parsePerimeter(); + AtomicInteger counter = new AtomicInteger(); for (String xtfFile : options.xtfFiles()) { try (LKMapXtfReader reader = new LKMapXtfReader(new File(xtfFile))) { - AtomicInteger counter = new AtomicInteger(); - Stream objects = reader.readObjects() - .map(GeometryObject::create); + ObjectMapper mapper = new ObjectMapper(); + Stream objects = mapper.mapObjects(reader.readObjects()); if (perimeter.isPresent()) { objects = objects.filter(o -> perimeter.get().intersects(o.geometry())); } - objects.forEach(o -> System.out.println(counter.incrementAndGet() + ": " + o.iomObject().getobjectoid())); + objects.forEach(o -> System.out.println(counter.incrementAndGet() + ": " + o.iomObject().getobjectoid() + " -> " + o.layerMapping().layer())); } catch (Exception e) { System.err.println("Failed to process file: " + xtfFile); e.printStackTrace(); diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/GeometryObject.java b/src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java similarity index 81% rename from src/main/java/ch/geowerkstatt/lk2dxf/GeometryObject.java rename to src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java index 6804717..7505dee 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/GeometryObject.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java @@ -1,5 +1,6 @@ package ch.geowerkstatt.lk2dxf; +import ch.geowerkstatt.lk2dxf.mapping.LayerMapping; import ch.interlis.iom.IomObject; import ch.interlis.iom_j.itf.impl.jtsext.geom.JtsextGeometryFactory; import ch.interlis.iox.IoxException; @@ -7,7 +8,7 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; -public record GeometryObject(Geometry geometry, IomObject iomObject) { +public record MappedObject(Geometry geometry, IomObject iomObject, LayerMapping layerMapping) { private static final String BASKET_NAME = "SIA405_LKMap_2015_LV95.SIA405_LKMap"; private static final GeometryFactory GEOMETRY_FACTORY = new JtsextGeometryFactory(); @@ -18,16 +19,15 @@ public record GeometryObject(Geometry geometry, IomObject iomObject) { * @throws IllegalArgumentException If the object tag is not supported. * @throws RuntimeException If an error occurs while extracting the geometry. */ - public static GeometryObject create(IomObject iomObject) { + public static MappedObject create(IomObject iomObject, LayerMapping layerMapping) { try { Geometry geometry = switch (iomObject.getobjecttag()) { - case BASKET_NAME + ".LKPunkt" -> readPoint(iomObject, "SymbolPos"); - case BASKET_NAME + ".LKLinie" -> readLine(iomObject, "Linie"); - case BASKET_NAME + ".LKFlaeche" -> readSurface(iomObject, "Flaeche"); - case BASKET_NAME + ".LKObjekt_Text" -> readPoint(iomObject, "TextPos"); + case BASKET_NAME + ".LKPunkt", BASKET_NAME + ".LKObjekt_Text" -> readPoint(iomObject, layerMapping.geometry()); + case BASKET_NAME + ".LKLinie" -> readLine(iomObject, layerMapping.geometry()); + case BASKET_NAME + ".LKFlaeche" -> readSurface(iomObject, layerMapping.geometry()); default -> throw new IllegalArgumentException("Unsupported object tag: " + iomObject.getobjecttag()); }; - return new GeometryObject(geometry, iomObject); + return new MappedObject(geometry, iomObject, layerMapping); } catch (IoxException e) { throw new RuntimeException("Error creating geometry for object with id \"" + iomObject.getobjectoid() + "\".", e); } diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java new file mode 100644 index 0000000..144d9cf --- /dev/null +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java @@ -0,0 +1,99 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import ch.geowerkstatt.lk2dxf.MappedObject; +import ch.interlis.iom.IomObject; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; +import java.util.stream.Stream; + +public final class ObjectMapper { + private static final String OBJECT_TYPE_ATTRIBUTE = "Objektart"; + private static final String OBJECT_REF_ATTRIBUTE = "LKObjektRef"; + private static final List LAYER_MAPPINGS; + + private final Map objectTypeCache = new HashMap<>(); + private final List objectsWithRef = new ArrayList<>(); + + static { + try { + LAYER_MAPPINGS = MappingReader.readMappings(); + } catch (IOException e) { + throw new RuntimeException("Failed to read layer mappings.", e); + } + } + + /** + * Maps the given {@link IomObject} stream to a stream containing their layer information. + * @param iomObjects The {@link IomObject} stream to map. + * @return A stream of mapped objects. + */ + public Stream mapObjects(Stream iomObjects) { + // Combine streams using flatMap instead of concat to process objectsWithRef + // after all objects have been processed by the first stream. + var combinedStream = Stream.>>>of( + () -> iomObjects.map(this::mapObject), + () -> objectsWithRef.stream().map(this::getLayerMapping) + ).flatMap(Supplier::get); + + return combinedStream + .filter(Optional::isPresent) + .map(Optional::get); + } + + private Optional mapObject(IomObject iomObject) { + String objectType = iomObject.getattrvalue(OBJECT_TYPE_ATTRIBUTE); + if (objectType == null) { + // Process objects with reference (LKObjekt_Text) after all other objects have been read. + objectsWithRef.add(iomObject); + return Optional.empty(); + } + + objectTypeCache.put(iomObject.getobjectoid(), objectType); + return getLayerMapping(iomObject); + } + + private Optional getLayerMapping(IomObject iomObject) { + Optional layerMapping = LAYER_MAPPINGS.stream() + .filter(mapping -> matchesMapping(mapping, iomObject)) + .findFirst(); + if (layerMapping.isEmpty()) { + System.err.println("No mapping found for object with id \"" + iomObject.getobjectoid() + "\"."); + } + return layerMapping.map(mapping -> MappedObject.create(iomObject, mapping)); + } + + private boolean matchesMapping(LayerMapping layerMapping, IomObject iomObject) { + if (!iomObject.getobjecttag().endsWith("." + layerMapping.objectType())) { + return false; + } + + return layerMapping.mapping() + .entrySet() + .stream() + .allMatch(e -> { + String attrName = e.getKey(); + String attrValue = getAttributeValue(iomObject, attrName); + List values = e.getValue(); + return values.contains(attrValue) || matchesEnumSubValue(values, attrValue); + }); + } + + private String getAttributeValue(IomObject iomObject, String attributeName) { + String attrValue = iomObject.getattrvalue(attributeName); + if (attrValue == null && attributeName.equals(OBJECT_TYPE_ATTRIBUTE)) { + String lkObjektId = iomObject.getattrobj(OBJECT_REF_ATTRIBUTE, 0).getobjectrefoid(); + attrValue = objectTypeCache.get(lkObjektId); + } + return attrValue; + } + + private boolean matchesEnumSubValue(List allowedValues, String attrValue) { + return allowedValues.stream().anyMatch(value -> attrValue.startsWith(value + ".")); + } +} diff --git a/src/test/data/MapperTest/MapWithText.xtf b/src/test/data/MapperTest/MapWithText.xtf new file mode 100644 index 0000000..c4799e1 --- /dev/null +++ b/src/test/data/MapperTest/MapWithText.xtf @@ -0,0 +1,112 @@ + + + + + + + + + + test data + + + + + basket1object001 + + + Test + Test + 20241030 + + + Test + unbekannt + in_Betrieb + + + + + + 2669992.781 + 1208904.666 + + + 2669971.614 + 1206904.416 + + + 2672924.364 + 1206936.166 + + + 2672818.531 + 1208915.250 + + + 2669992.781 + 1208904.666 + + + + + + Wasser.unbekannt + + + basket1object002 + + + Test + Test + 20241030 + + + Test + unbekannt + in_Betrieb + + + 2669992.781 + 1208904.666 + + + Wasser.Absperrorgan + + + + + 2669999.999 + 1208900.000 + + + 45.5 + Left + Top + Leitungskataster + Test content + + + + basket1object004 + + + Test + Test + 20241030 + + + Test + ungenau + in_Betrieb + + + 2669992.781 + 1208904.666 + + + Fernwaerme.unbekannt + + + + \ No newline at end of file diff --git a/src/test/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapperTest.java b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapperTest.java new file mode 100644 index 0000000..40476e9 --- /dev/null +++ b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapperTest.java @@ -0,0 +1,31 @@ +package ch.geowerkstatt.lk2dxf.mapping; + +import ch.geowerkstatt.lk2dxf.LKMapXtfReader; +import ch.interlis.iom.IomObject; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public final class ObjectMapperTest { + private static final String TEST_FILE = "src/test/data/MapperTest/MapWithText.xtf"; + + @Test + public void mapObject() throws Exception { + try (LKMapXtfReader xtfReader = new LKMapXtfReader(new File(TEST_FILE))) { + ObjectMapper mapper = new ObjectMapper(); + + List objects = xtfReader.readObjects().toList(); + assertEquals(4, objects.size()); + + String[] layerMappings = mapper.mapObjects(objects.stream()) + .map(o -> o.layerMapping().layer()) + .toArray(String[]::new); + String[] expected = new String[] {"WAS-FLAECHE", "WAS-PUNKT", "FER-PUNKT", "FER-TEXT"}; + assertArrayEquals(expected, layerMappings); + } + } +} From d9a38347ef4bce172d032ce6b1f9febaedf9c66a Mon Sep 17 00:00:00 2001 From: Dominic Burger Date: Thu, 7 Nov 2024 16:57:36 +0100 Subject: [PATCH 3/3] Add geometry type column to mappings --- .../ch/geowerkstatt/lk2dxf/MappedObject.java | 9 +- .../lk2dxf/mapping/LayerMapping.java | 3 +- .../lk2dxf/mapping/ObjectMapper.java | 2 +- src/main/resources/mappings.csv | 98 +++++++++---------- .../lk2dxf/mapping/MappingReaderTest.java | 3 +- 5 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java b/src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java index 7505dee..4502adb 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/MappedObject.java @@ -9,7 +9,6 @@ import com.vividsolutions.jts.geom.GeometryFactory; public record MappedObject(Geometry geometry, IomObject iomObject, LayerMapping layerMapping) { - private static final String BASKET_NAME = "SIA405_LKMap_2015_LV95.SIA405_LKMap"; private static final GeometryFactory GEOMETRY_FACTORY = new JtsextGeometryFactory(); /** @@ -21,10 +20,10 @@ public record MappedObject(Geometry geometry, IomObject iomObject, LayerMapping */ public static MappedObject create(IomObject iomObject, LayerMapping layerMapping) { try { - Geometry geometry = switch (iomObject.getobjecttag()) { - case BASKET_NAME + ".LKPunkt", BASKET_NAME + ".LKObjekt_Text" -> readPoint(iomObject, layerMapping.geometry()); - case BASKET_NAME + ".LKLinie" -> readLine(iomObject, layerMapping.geometry()); - case BASKET_NAME + ".LKFlaeche" -> readSurface(iomObject, layerMapping.geometry()); + Geometry geometry = switch (layerMapping.geometryType()) { + case "Point" -> readPoint(iomObject, layerMapping.geometry()); + case "Line" -> readLine(iomObject, layerMapping.geometry()); + case "Surface" -> readSurface(iomObject, layerMapping.geometry()); default -> throw new IllegalArgumentException("Unsupported object tag: " + iomObject.getobjecttag()); }; return new MappedObject(geometry, iomObject, layerMapping); diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java index 7770b89..70f6e2b 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/LayerMapping.java @@ -7,7 +7,8 @@ public record LayerMapping( String layer, - String objectType, + String objectClass, + String geometryType, String geometry, int color, String orientation, diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java index 144d9cf..a082355 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java @@ -69,7 +69,7 @@ private Optional getLayerMapping(IomObject iomObject) { } private boolean matchesMapping(LayerMapping layerMapping, IomObject iomObject) { - if (!iomObject.getobjecttag().endsWith("." + layerMapping.objectType())) { + if (!iomObject.getobjecttag().endsWith("." + layerMapping.objectClass())) { return false; } diff --git a/src/main/resources/mappings.csv b/src/main/resources/mappings.csv index 357f742..d7cff53 100644 --- a/src/main/resources/mappings.csv +++ b/src/main/resources/mappings.csv @@ -1,49 +1,49 @@ -Layer ,ObjectType ,Geometry ,Color ,Orientation ,VAlign ,HAlign ,Text ,Symbol ,Linetype ,Lineweight ,Textsize ,Font ,Mapping -STILLGELEGTE-LEITUNGEN ,LKLinie ,Linie ,8 , , , , , ,Crossed ,0.25 , , ,Status=tot -ABW-LINIEFWK-GENAU ,LKLinie ,Linie ,210 , , , , , ,Continuous ,0.25 , , ,Objektart=Abwasser.Fernwirkkabel Lagebestimmung=genau -ABW-LINIEFWK-UNGENAU ,LKLinie ,Linie ,210 , , , , , ,Dashed ,0.25 , , ,Objektart=Abwasser.Fernwirkkabel Lagebestimmung=ungenau|unbekannt -ABW-LINIE-GENAU ,LKLinie ,Linie ,210 , , , , , ,Continuous ,0.25 , , ,Objektart=Abwasser.Haltung_Kanal|Abwasser.Schutzrohr Lagebestimmung=genau -ABW-LINIE-UNGENAU ,LKLinie ,Linie ,210 , , , , , ,Dashed ,0.25 , , ,Objektart=Abwasser.Haltung_Kanal|Abwasser.Schutzrohr Lagebestimmung=ungenau|unbekannt -ABW-FLAECHE ,LKFlaeche ,Flaeche ,210 , , , , , , , , , ,Objektart=Abwasser -ABW-PUNKT ,LKPunkt ,SymbolPos ,210 ,SymbolOri , , , ,BAW15 , , , , ,Objektart=Abwasser -ABW-TEXT ,LKObjekt_Text ,TextPos ,210 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Abwasser -ELE-LINIE-GENAU ,LKLinie ,Linie ,10 , , , , , ,Continuous ,0.25 , , ,Objektart=Elektrizitaet.Trasse.unterirdisch Lagebestimmung=genau -ELE-LINIE-UNGENAU ,LKLinie ,Linie ,10 , , , , , ,Dashed ,0.25 , , ,Objektart=Elektrizitaet.Trasse.unterirdisch Lagebestimmung=ungenau|unbekannt -ELE-LINIE-OBERIRDISCH ,LKLinie ,Linie ,10 , , , , , ,Continuous ,0.25 , , ,Objektart=Elektrizitaet.Trasse.oberirdisch|Elektrizitaet.AnkerStrebe -ELE-FLAECHE ,LKFlaeche ,Flaeche ,10 , , , , , , , , , ,Objektart=Elektrizitaet -ELE-PUNKT ,LKPunkt ,SymbolPos ,10 ,SymbolOri , , , ,BEW978 , , , , ,Objektart=Elektrizitaet -ELE-TEXT ,LKObjekt_Text ,TextPos ,10 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Elektrizitaet -GAS-LINIEFWK-GENAU ,LKLinie ,Linie ,22 , , , , , ,Continuous ,0.25 , , ,Objektart=Gas.Fernwirkkabel Labebestimmung=genau -GAS-LINIEFWK-UNGENAU ,LKLinie ,Linie ,22 , , , , , ,Dashed ,0.25 , , ,Objektart=Gas.Fernwirkkabel Labebestimmung=ungenau|unbekannt -GAS-LINIE-GENAU ,LKLinie ,Linie ,22 , , , , , ,Continuous ,0.25 , , ,Objektart=Gas.Leitung|Gas.Schutzrohr Labebestimmung=genau -GAS-LINIE-UNGENAU ,LKLinie ,Linie ,22 , , , , , ,Dashed ,0.25 , , ,Objektart=Gas.Leitung|Gas.Schutzrohr Labebestimmung=ungenau|unbekannt -GAS-FLAECHE ,LKFlaeche ,Flaeche ,22 , , , , , , , , , ,Objektart=Gas -GAS-PUNKT ,LKPunkt ,SymbolPos ,22 ,SymbolOri , , , ,BGA957 , , , , ,Objektart=Gas -GAS-TEXT ,LKObjekt_Text ,TextPos ,22 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Gas -WAS-LINIEFWK-GENAU ,LKLinie ,Linie ,170 , , , , , ,Continuous ,0.25 , , ,Objektart=Wasser.Fernwirkkabel Lagebestimmung=genau -WAS-LINIEFWK-UNGENAU ,LKLinie ,Linie ,170 , , , , , ,Dashed ,0.25 , , ,Objektart=Wasser.Fernwirkkabel Lagebestimmung=ungenau|unbekannt -WAS-LINIE-GENAU ,LKLinie ,Linie ,170 , , , , , ,Continuous ,0.25 , , ,Objektart=Wasser.Leitung|Wasser.Schutzrohr Lagebestimmung=genau -WAS-LINIE-UNGENAU ,LKLinie ,Linie ,170 , , , , , ,Dashed ,0.25 , , ,Objektart=Wasser.Leitung|Wasser.Schutzrohr Lagebestimmung=ungenau|unbekannt -WAS-FLAECHE ,LKFlaeche ,Flaeche ,170 , , , , , , , , , ,Objektart=Wasser -WAS-PUNKT ,LKPunkt ,SymbolPos ,170 ,SymbolOri , , , ,BWA15 , , , , ,Objektart=Wasser -WAS-TEXT ,LKObjekt_Text ,TextPos ,170 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Wasser -FER-LINIEFWK-GENAU ,LKLinie ,Linie ,30 , , , , , ,Continuous ,0.25 , , ,Objektart=Fernwaerme.Fernwirkkabel Lagebestimmung=genau -FER-LINIEFWK-UNGENAU ,LKLinie ,Linie ,30 , , , , , ,Dashed ,0.25 , , ,Objektart=Fernwaerme.Fernwirkkabel Lagebestimmung=ungenau|unbekannt -FER-LINIE-GENAU ,LKLinie ,Linie ,30 , , , , , ,Continuous ,0.25 , , ,Objektart=Fernwaerme.Trasse Lagebestimmung=genau -FER-LINIE-UNGENAU ,LKLinie ,Linie ,30 , , , , , ,Dashed ,0.25 , , ,Objektart=Fernwaerme.Trasse Lagebestimmung=ungenau|unbekannt -FER-FLAECHE ,LKFlaeche ,Flaeche ,30 , , , , , , , , , ,Objektart=Fernwaerme -FER-PUNKT ,LKPunkt ,SymbolPos ,30 ,SymbolOri , , , ,BWA965 , , , , ,Objektart=Fernwaerme -FER-TEXT ,LKObjekt_Text ,TextPos ,30 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Fernwaerme -KOM-LINIE-GENAU ,LKLinie ,Linie ,80 , , , , , ,Continuous ,0.25 , , ,Objektart=Kommunikation.Trasse.unterirdisch Lagebestimmung=genau -KOM-LINIE-UNGENAU ,LKLinie ,Linie ,80 , , , , , ,Dashed ,0.25 , , ,Objektart=Kommunikation.Trasse.unterirdisch Lagebestimmung=ungenau|unbekannt -KOM-LINIE-OBERIRDISCH ,LKLinie ,Linie ,80 , , , , , ,Continuous ,0.25 , , ,Objektart=Kommunikation.Trasse.oberirdisch -KOM-FLAECHE ,LKFlaeche ,Flaeche ,80 , , , , , , , , , ,Objektart=Kommunikation -KOM-PUNKT ,LKPunkt ,SymbolPos ,80 ,SymbolOri , , , ,BEW15 , , , , ,Objektart=Kommunikation -KOM-TEXT ,LKObjekt_Text ,TextPos ,80 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Kommunikation -WEI-LINIEFWK-GENAU ,LKLinie ,Linie ,50 , , , , , ,Continuous ,0.25 , , ,Objektart=weitereMedien.Fernwirkkabel Lagebestimmung=genau -WEI-LINIEFWK-UNGENAU ,LKLinie ,Linie ,50 , , , , , ,Dashed ,0.25 , , ,Objektart=weitereMedien.Fernwirkkabel Lagebestimmung=ungenau|unbekannt -WEI-LINIE-GENAU ,LKLinie ,Linie ,50 , , , , , ,Continuous ,0.25 , , ,Objektart=weitereMedien.Leitung|weitereMedien.Schutzrohr Lagebestimmung=genau -WEI-LINIE-UNGENAU ,LKLinie ,Linie ,50 , , , , , ,Dashed ,0.25 , , ,Objektart=weitereMedien.Leitung|weitereMedien.Schutzrohr Lagebestimmung=ungenau|unbekannt -WEI-FLAECHE ,LKFlaeche ,Flaeche ,50 , , , , , , , , , ,Objektart=weitereMedien -WEI-PUNKT ,LKPunkt ,SymbolPos ,50 ,SymbolOri , , , ,BEW15 , , , , ,Objektart=weitereMedien -WEI-TEXT ,LKObjekt_Text ,TextPos ,50 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=weitereMedien +Layer ,ObjectClass ,GeometryType ,Geometry ,Color ,Orientation ,VAlign ,HAlign ,Text ,Symbol ,Linetype ,Lineweight ,Textsize ,Font ,Mapping +STILLGELEGTE-LEITUNGEN ,LKLinie ,Line ,Linie ,8 , , , , , ,Crossed ,0.25 , , ,Status=tot +ABW-LINIEFWK-GENAU ,LKLinie ,Line ,Linie ,210 , , , , , ,Continuous ,0.25 , , ,Objektart=Abwasser.Fernwirkkabel Lagebestimmung=genau +ABW-LINIEFWK-UNGENAU ,LKLinie ,Line ,Linie ,210 , , , , , ,Dashed ,0.25 , , ,Objektart=Abwasser.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +ABW-LINIE-GENAU ,LKLinie ,Line ,Linie ,210 , , , , , ,Continuous ,0.25 , , ,Objektart=Abwasser.Haltung_Kanal|Abwasser.Schutzrohr Lagebestimmung=genau +ABW-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,210 , , , , , ,Dashed ,0.25 , , ,Objektart=Abwasser.Haltung_Kanal|Abwasser.Schutzrohr Lagebestimmung=ungenau|unbekannt +ABW-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,210 , , , , , , , , , ,Objektart=Abwasser +ABW-PUNKT ,LKPunkt ,Point ,SymbolPos ,210 ,SymbolOri , , , ,BAW15 , , , , ,Objektart=Abwasser +ABW-TEXT ,LKObjekt_Text ,Point ,TextPos ,210 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Abwasser +ELE-LINIE-GENAU ,LKLinie ,Line ,Linie ,10 , , , , , ,Continuous ,0.25 , , ,Objektart=Elektrizitaet.Trasse.unterirdisch Lagebestimmung=genau +ELE-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,10 , , , , , ,Dashed ,0.25 , , ,Objektart=Elektrizitaet.Trasse.unterirdisch Lagebestimmung=ungenau|unbekannt +ELE-LINIE-OBERIRDISCH ,LKLinie ,Line ,Linie ,10 , , , , , ,Continuous ,0.25 , , ,Objektart=Elektrizitaet.Trasse.oberirdisch|Elektrizitaet.AnkerStrebe +ELE-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,10 , , , , , , , , , ,Objektart=Elektrizitaet +ELE-PUNKT ,LKPunkt ,Point ,SymbolPos ,10 ,SymbolOri , , , ,BEW978 , , , , ,Objektart=Elektrizitaet +ELE-TEXT ,LKObjekt_Text ,Point ,TextPos ,10 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Elektrizitaet +GAS-LINIEFWK-GENAU ,LKLinie ,Line ,Linie ,22 , , , , , ,Continuous ,0.25 , , ,Objektart=Gas.Fernwirkkabel Labebestimmung=genau +GAS-LINIEFWK-UNGENAU ,LKLinie ,Line ,Linie ,22 , , , , , ,Dashed ,0.25 , , ,Objektart=Gas.Fernwirkkabel Labebestimmung=ungenau|unbekannt +GAS-LINIE-GENAU ,LKLinie ,Line ,Linie ,22 , , , , , ,Continuous ,0.25 , , ,Objektart=Gas.Leitung|Gas.Schutzrohr Labebestimmung=genau +GAS-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,22 , , , , , ,Dashed ,0.25 , , ,Objektart=Gas.Leitung|Gas.Schutzrohr Labebestimmung=ungenau|unbekannt +GAS-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,22 , , , , , , , , , ,Objektart=Gas +GAS-PUNKT ,LKPunkt ,Point ,SymbolPos ,22 ,SymbolOri , , , ,BGA957 , , , , ,Objektart=Gas +GAS-TEXT ,LKObjekt_Text ,Point ,TextPos ,22 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Gas +WAS-LINIEFWK-GENAU ,LKLinie ,Line ,Linie ,170 , , , , , ,Continuous ,0.25 , , ,Objektart=Wasser.Fernwirkkabel Lagebestimmung=genau +WAS-LINIEFWK-UNGENAU ,LKLinie ,Line ,Linie ,170 , , , , , ,Dashed ,0.25 , , ,Objektart=Wasser.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +WAS-LINIE-GENAU ,LKLinie ,Line ,Linie ,170 , , , , , ,Continuous ,0.25 , , ,Objektart=Wasser.Leitung|Wasser.Schutzrohr Lagebestimmung=genau +WAS-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,170 , , , , , ,Dashed ,0.25 , , ,Objektart=Wasser.Leitung|Wasser.Schutzrohr Lagebestimmung=ungenau|unbekannt +WAS-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,170 , , , , , , , , , ,Objektart=Wasser +WAS-PUNKT ,LKPunkt ,Point ,SymbolPos ,170 ,SymbolOri , , , ,BWA15 , , , , ,Objektart=Wasser +WAS-TEXT ,LKObjekt_Text ,Point ,TextPos ,170 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Wasser +FER-LINIEFWK-GENAU ,LKLinie ,Line ,Linie ,30 , , , , , ,Continuous ,0.25 , , ,Objektart=Fernwaerme.Fernwirkkabel Lagebestimmung=genau +FER-LINIEFWK-UNGENAU ,LKLinie ,Line ,Linie ,30 , , , , , ,Dashed ,0.25 , , ,Objektart=Fernwaerme.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +FER-LINIE-GENAU ,LKLinie ,Line ,Linie ,30 , , , , , ,Continuous ,0.25 , , ,Objektart=Fernwaerme.Trasse Lagebestimmung=genau +FER-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,30 , , , , , ,Dashed ,0.25 , , ,Objektart=Fernwaerme.Trasse Lagebestimmung=ungenau|unbekannt +FER-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,30 , , , , , , , , , ,Objektart=Fernwaerme +FER-PUNKT ,LKPunkt ,Point ,SymbolPos ,30 ,SymbolOri , , , ,BWA965 , , , , ,Objektart=Fernwaerme +FER-TEXT ,LKObjekt_Text ,Point ,TextPos ,30 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Fernwaerme +KOM-LINIE-GENAU ,LKLinie ,Line ,Linie ,80 , , , , , ,Continuous ,0.25 , , ,Objektart=Kommunikation.Trasse.unterirdisch Lagebestimmung=genau +KOM-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,80 , , , , , ,Dashed ,0.25 , , ,Objektart=Kommunikation.Trasse.unterirdisch Lagebestimmung=ungenau|unbekannt +KOM-LINIE-OBERIRDISCH ,LKLinie ,Line ,Linie ,80 , , , , , ,Continuous ,0.25 , , ,Objektart=Kommunikation.Trasse.oberirdisch +KOM-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,80 , , , , , , , , , ,Objektart=Kommunikation +KOM-PUNKT ,LKPunkt ,Point ,SymbolPos ,80 ,SymbolOri , , , ,BEW15 , , , , ,Objektart=Kommunikation +KOM-TEXT ,LKObjekt_Text ,Point ,TextPos ,80 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=Kommunikation +WEI-LINIEFWK-GENAU ,LKLinie ,Line ,Linie ,50 , , , , , ,Continuous ,0.25 , , ,Objektart=weitereMedien.Fernwirkkabel Lagebestimmung=genau +WEI-LINIEFWK-UNGENAU ,LKLinie ,Line ,Linie ,50 , , , , , ,Dashed ,0.25 , , ,Objektart=weitereMedien.Fernwirkkabel Lagebestimmung=ungenau|unbekannt +WEI-LINIE-GENAU ,LKLinie ,Line ,Linie ,50 , , , , , ,Continuous ,0.25 , , ,Objektart=weitereMedien.Leitung|weitereMedien.Schutzrohr Lagebestimmung=genau +WEI-LINIE-UNGENAU ,LKLinie ,Line ,Linie ,50 , , , , , ,Dashed ,0.25 , , ,Objektart=weitereMedien.Leitung|weitereMedien.Schutzrohr Lagebestimmung=ungenau|unbekannt +WEI-FLAECHE ,LKFlaeche ,Surface ,Flaeche ,50 , , , , , , , , , ,Objektart=weitereMedien +WEI-PUNKT ,LKPunkt ,Point ,SymbolPos ,50 ,SymbolOri , , , ,BEW15 , , , , ,Objektart=weitereMedien +WEI-TEXT ,LKObjekt_Text ,Point ,TextPos ,50 ,TextOri ,TextVAli ,TextHAli ,Textinhalt , , , ,1.25 ,Cadastra ,Objektart=weitereMedien diff --git a/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java index c1db0a7..e729035 100644 --- a/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java +++ b/src/test/java/ch/geowerkstatt/lk2dxf/mapping/MappingReaderTest.java @@ -14,7 +14,8 @@ public void readMappings() throws IOException { List mappings = MappingReader.readMappings(); assertTrue(mappings.stream().noneMatch(m -> m.layer().isBlank()), "Layer is required"); - assertTrue(mappings.stream().noneMatch(m -> m.objectType().isBlank()), "ObjectType is required"); + assertTrue(mappings.stream().noneMatch(m -> m.objectClass().isBlank()), "ObjectType is required"); + assertTrue(mappings.stream().noneMatch(m -> m.geometryType().isBlank()), "GeometryType is required"); assertTrue(mappings.stream().noneMatch(m -> m.geometry().isBlank()), "Geometry is required"); assertTrue(mappings.stream().noneMatch(m -> m.mapping().isEmpty()), "Mapping is required"); assertEquals("STILLGELEGTE-LEITUNGEN", mappings.getFirst().layer());