Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into various-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickackermann committed Nov 21, 2024
2 parents 100b0e9 + 72f845a commit c521dba
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/ch/geowerkstatt/lk2dxf/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
import org.apache.logging.log4j.core.layout.PatternLayout;

import java.io.File;
import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

public final class Main {
Expand All @@ -46,6 +51,7 @@ private Main() { }
* Application entry point.
*/
public static void main(String[] args) {
Instant start = Instant.now();
Options cliOptions = createCliOptions();
CommandLine commandLine = parseCommandLine(cliOptions, args);

Expand All @@ -65,6 +71,11 @@ public static void main(String[] args) {
if (!processFiles(options.get())) {
System.exit(1);
}

Instant end = Instant.now();
Duration duration = Duration.between(start, end);
String formattedDuration = String.format("%02dh:%02dm:%02ds.%03dms", duration.toHours(), duration.toMinutesPart(), duration.toSecondsPart(), duration.toMillisPart());
LOGGER.info("Processing took {}", formattedDuration);
}
}
}
Expand All @@ -76,6 +87,8 @@ public static void main(String[] args) {
*/
private static boolean processFiles(LK2DxfOptions options) {
Optional<Geometry> perimeter = options.parsePerimeter();
AtomicInteger objectCounter = new AtomicInteger();
Map<String, AtomicInteger> layerCounters = new HashMap<>();

ObjectMapper objectMapper;
try {
Expand All @@ -93,7 +106,13 @@ private static boolean processFiles(LK2DxfOptions options) {
objects = objects.filter(o -> perimeter.get().intersects(o.geometry()));
}

objects.forEach(o -> o.writeToDxf(dxfWriter));
objects.forEach(o -> {
o.writeToDxf(dxfWriter);

objectCounter.incrementAndGet();
String layer = o.layerMapping().layer();
layerCounters.computeIfAbsent(layer, k -> new AtomicInteger()).incrementAndGet();
});
} catch (Exception e) {
LOGGER.error("Failed to process file: {}", xtfFile, e);
return false;
Expand All @@ -104,6 +123,12 @@ private static boolean processFiles(LK2DxfOptions options) {
return false;
}

LOGGER.info("The output DXF file contains {} mapped objects", objectCounter.get());
layerCounters.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.forEach(entry -> LOGGER.info("Layer {}: {} objects", entry.getKey(), entry.getValue().get()));

return true;
}

Expand Down

0 comments on commit c521dba

Please sign in to comment.