From 72b5962ae240c7066aa95edb23db4fb1224a2653 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Thu, 21 Nov 2024 10:14:19 +0100 Subject: [PATCH] Add Surface and Point objects to integration test --- .../geowerkstatt/lk2dxf/IntegrationTest.java | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/test/java/ch/geowerkstatt/lk2dxf/IntegrationTest.java b/src/test/java/ch/geowerkstatt/lk2dxf/IntegrationTest.java index 99cdb31..f1a6436 100644 --- a/src/test/java/ch/geowerkstatt/lk2dxf/IntegrationTest.java +++ b/src/test/java/ch/geowerkstatt/lk2dxf/IntegrationTest.java @@ -24,7 +24,6 @@ import java.util.Random; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -53,20 +52,22 @@ public void multipleFilesWithPerimeter() throws IOException, URISyntaxException, // Generate input files var files = new ArrayList(); + var objectCount = 2_000; for (int i = 0; i < 3; i++) { var file = new File(TEST_OUT_DIR + "multipleFilesWithPerimeter" + "_" + i + ".xtf"); files.add(file); - writeTestXTF(file, i, 1000); + writeTestXTF(file, i * objectCount, objectCount); } // Run the main method - var perimeter = "Polygon ((740857.55514181009493768 256024.12385561052360572, 607598.44303888664580882 264279.11310092435451224, 526620.92948961758520454 99572.42292061494663358, 578116.33859133732039481 101537.89655045152176172, 625680.80043338367249817 178584.46284004737390205, 706265.21925668546464294 173867.32612843945389614, 740857.55514181009493768 101930.99127641884842888, 795890.81677723571192473 100751.7070985168684274, 740857.55514181009493768 256024.12385561052360572))"; + var perimeter = "Polygon ((2740857.55514180986210704 1256024.12385561061091721, 2607598.44303888687863946 1264279.11310092429630458, 2508533.20150150312110782 1106392.40145171224139631, 2578116.33859133720397949 1101537.89655045163817704, 2625680.80043338378891349 1178584.46284004743210971, 2706265.21925668558105826 1173867.3261284395121038, 2740857.55514180986210704 1101930.99127641879022121, 2795890.81677723582834005 1100751.7070985168684274, 2740857.55514180986210704 1256024.12385561061091721))"; Main.main(Stream.concat(files.stream().map(File::getAbsolutePath), Stream.of(output, "--perimeter", perimeter)).toArray(String[]::new)); // Check output file assertTrue(outputFile.exists()); assertTrue(outputFile.isFile()); - assertEquals(816018, outputFile.length()); + assertTrue(outputFile.length() < 1_150_000, "Output file is too large <" + outputFile.length() + "> did the perimeter filter work?"); + assertTrue(outputFile.length() > 10_000, "The output file is too small <" + outputFile.length() + "> it contains not much more than the default dxf content!"); } private void writeTestXTF(File file, int seed, int objectCount) throws IOException, URISyntaxException, Ili2cException, IoxException { @@ -77,12 +78,14 @@ private void writeTestXTF(File file, int seed, int objectCount) throws IOExcepti try { writer.write(new StartTransferEvent()); writer.write(new StartBasketEvent("SIA405_LKMap_2015_LV95.SIA405_LKMap", "BASKET1")); - for (int i = 0; i < objectCount; i += 2) { - var x = rand.nextDouble() * 300_000 + 510_000; - var y = rand.nextDouble() * 200_000 + 85_000; - var size = rand.nextDouble() * 5000 + 5000; + for (int i = seed; i < objectCount + seed; i += 4) { + var x = rand.nextDouble() * 300_000 + 2510_000; + var y = rand.nextDouble() * 200_000 + 1085_000; + var size = rand.nextDouble() * 7000 + 3000; writer.write(new ObjectEvent(createTextObject(i, x, y, "obj_" + (i + 1)))); writer.write(new ObjectEvent(createLineObject(i + 1, x, y, size))); + writer.write(new ObjectEvent(createFlaecheObject(i + 2, x, y))); + writer.write(new ObjectEvent(createPointObject(i + 3, x, y))); } writer.write(new EndBasketEvent()); writer.write(new EndTransferEvent()); @@ -93,6 +96,7 @@ private void writeTestXTF(File file, int seed, int objectCount) throws IOExcepti private final String[] precisionValues = new String[]{"genau", "unbekannt", "ungenau"}; private final String[] lineObjectTypeValues = new String[]{"Abwasser.Fernwirkkabel", "Abwasser.Haltung_Kanal", "Abwasser.Schutzrohr", "Elektrizitaet.AnkerStrebe", "Elektrizitaet.Trasse.oberirdisch", "Elektrizitaet.Trasse.unterirdisch", "Fernwaerme.Fernwirkkabel", "Fernwaerme.Trasse", "Gas.Fernwirkkabel", "Gas.Leitung", "Gas.Schutzrohr", "Kommunikation.Trasse.oberirdisch", "Kommunikation.Trasse.unterirdisch", "Wasser.Fernwirkkabel", "Wasser.Leitung", "Wasser.Schutzrohr", "weitereMedien.Fernwirkkabel", "weitereMedien.Leitung", "weitereMedien.Schutzrohr"}; + private final String[] objectTypeValues = new String[]{"Abwasser", "Elektrizitaet", "Fernwaerme", "Gas", "Kommunikation", "Wasser", "weitereMedien"}; private final String[] objectStatusValues = new String[]{"ausser_Betrieb", "in_Betrieb", "tot", "unbekannt", "weitere"}; private IomObject createLineObject(int oid, double x, double y, double size) { @@ -108,11 +112,32 @@ private IomObject createLineObject(int oid, double x, double y, double size) { } var polyline = IomObjectHelper.createPolyline(segments.toArray(new IomObject[0])); + var rand = new Random(oid); return IomObjectHelper.createIomObject("SIA405_LKMap_2015_LV95.SIA405_LKMap.LKLinie", "obj_" + oid, o -> o.addattrobj("Linie", polyline), - o -> o.addattrvalue("Objektart", lineObjectTypeValues[oid % lineObjectTypeValues.length]), - o -> o.addattrvalue("Lagebestimmung", precisionValues[oid % precisionValues.length]), - o -> o.addattrvalue("Status", objectStatusValues[oid % objectStatusValues.length]), + o -> o.addattrvalue("Objektart", lineObjectTypeValues[rand.nextInt(lineObjectTypeValues.length)]), + o -> o.addattrvalue("Lagebestimmung", precisionValues[rand.nextInt(precisionValues.length)]), + o -> o.addattrvalue("Status", objectStatusValues[rand.nextInt(objectStatusValues.length)]), + o -> o.addattrvalue("Eigentuemer", "Keine_Angabe")); + } + + private IomObject createFlaecheObject(int oid, double x, double y) { + var rand = new Random(oid); + return IomObjectHelper.createIomObject("SIA405_LKMap_2015_LV95.SIA405_LKMap.LKFlaeche", "obj_" + oid, + o -> o.addattrobj("Flaeche", IomObjectHelper.createRectangleGeometry(Double.toString(x), Double.toString(y), Double.toString(x - 1.5), Double.toString(y + 10))), + o -> o.addattrvalue("Objektart", objectTypeValues[rand.nextInt(objectTypeValues.length)]), + o -> o.addattrvalue("Lagebestimmung", precisionValues[rand.nextInt(precisionValues.length)]), + o -> o.addattrvalue("Status", objectStatusValues[rand.nextInt(objectStatusValues.length)]), + o -> o.addattrvalue("Eigentuemer", "Keine_Angabe")); + } + + private IomObject createPointObject(int oid, double x, double y) { + var rand = new Random(oid); + return IomObjectHelper.createIomObject("SIA405_LKMap_2015_LV95.SIA405_LKMap.LKPunkt", "obj_" + oid, + o -> o.addattrobj("SymbolPos", IomObjectHelper.createCoord(Double.toString(x), Double.toString(y))), + o -> o.addattrvalue("Objektart", objectTypeValues[rand.nextInt(objectTypeValues.length)]), + o -> o.addattrvalue("Lagebestimmung", precisionValues[rand.nextInt(precisionValues.length)]), + o -> o.addattrvalue("Status", objectStatusValues[rand.nextInt(objectStatusValues.length)]), o -> o.addattrvalue("Eigentuemer", "Keine_Angabe")); }