[Dive4elements-commits] [PATCH] Log the number of points of cross sections to see the effect of the simplification

Wald Commits scm-commit at wald.intevation.org
Sun Feb 24 21:38:20 CET 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1361738289 -3600
# Branch slt-simplify-cross-sections
# Node ID ca45dd039b547027674a94f87be99bdf10f3b939
# Parent  7bbee0cfc171f756da78b1cf1801869fe4a923c6
Log the number of points of cross sections to see the effect of the simplification.

diff -r 7bbee0cfc171 -r ca45dd039b54 flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Sun Feb 24 17:29:52 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Sun Feb 24 21:38:09 2013 +0100
@@ -172,19 +172,19 @@
     implements    CrossSectionParser.Callback {
 
         private Set<HashedFile> files = new HashSet<HashedFile>();
-        private String type;
-
+        private String          type;
 
         /**
          * Create new Callback, given type which is used for logging
          * purposes only.
          */
-        public ImportRiverCrossSectionParserCallback (String type) {
+        public ImportRiverCrossSectionParserCallback(String type) {
             this.type = type;
         }
 
 
         /** Accept file if not duplicate. */
+        @Override
         public boolean accept(File file) {
             HashedFile hf = new HashedFile(file);
             boolean success = files.add(hf);
@@ -196,14 +196,60 @@
 
 
         /** Add crosssection. */
+        @Override
         public void parsed(CrossSectionParser parser) {
            log.debug("callback from " + type + " parser");
 
-           addCrossSections(parser);
+            String  description = parser.getDescription();
+            Integer year        = parser.getYear();
+            ImportTimeInterval ti = year != null
+                ? new ImportTimeInterval(yearToDate(year))
+                : null;
+
+            Map<Double, List<XY>> data = parser.getData();
+
+            List<ImportCrossSectionLine> lines =
+                new ArrayList<ImportCrossSectionLine>(data.size());
+
+            Double simplificationEpsilon =
+                Config.INSTANCE.getCrossSectionSimplificationEpsilon();
+
+            long numReadPoints      = 0L;
+            long numRemainingPoints = 0L;
+
+            for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
+                Double   km     = entry.getKey();
+                List<XY> points = entry.getValue();
+                numReadPoints += points.size();
+                if (simplificationEpsilon != null) {
+                    points = DouglasPeuker.simplify(points, simplificationEpsilon);
+                }
+                numRemainingPoints += points.size();
+                lines.add(new ImportCrossSectionLine(km, points));
+            }
+
+            ImportRiver.this.addCrossSections(description, ti, lines);
+
+            double percent = numReadPoints > 0L
+                ? ((double)numRemainingPoints/numReadPoints)*100d
+                : 0d;
+
+            log.info(String.format(
+                "Number of points in cross section: %d / %d (%.2f%%)",
+                numReadPoints, numRemainingPoints, percent));
         }
     } // ImportRiverCrossSectionParserCallback 
 
 
+    private void addCrossSections(
+        String                       description,
+        ImportTimeInterval           ti,
+        List<ImportCrossSectionLine> lines
+    ) {
+        crossSections.add(new ImportCrossSection(this, description, ti, lines));
+    }
+
+
     public ImportRiver() {
         hyks                      = new ArrayList<ImportHYK>();
         crossSections             = new ArrayList<ImportCrossSection>();
@@ -938,36 +984,6 @@
     }
 
 
-    /** Add cross sections with description, years and lines to
-     * store. */
-    private void addCrossSections(CrossSectionParser parser) {
-        String  description = parser.getDescription();
-        Integer year        = parser.getYear();
-        ImportTimeInterval ti = year != null
-            ? new ImportTimeInterval(yearToDate(year))
-            : null;
-
-        Map<Double, List<XY>> data = parser.getData();
-
-        List<ImportCrossSectionLine> lines =
-            new ArrayList<ImportCrossSectionLine>(data.size());
-
-        Double simplificationEpsilon =
-            Config.INSTANCE.getCrossSectionSimplificationEpsilon();
-
-        for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
-            Double   km     = entry.getKey();
-            List<XY> points = entry.getValue();
-            if (simplificationEpsilon != null) {
-                points = DouglasPeuker.simplify(points, simplificationEpsilon);
-            }
-            lines.add(new ImportCrossSectionLine(km, points));
-        }
-
-        crossSections.add(new ImportCrossSection(
-            this, description, ti, lines));
-    }
-
     /** Create a W80 Parser and parse w80 files found. */
     public void parseW80s() {
         if (Config.INSTANCE.skipW80s()) {
@@ -1003,6 +1019,7 @@
 
         ImportRiverCrossSectionParserCallback da50Callback =
             new ImportRiverCrossSectionParserCallback("da50");
+
         parser.parseDA50s(riverDir, da50Callback);
     }
 
@@ -1024,6 +1041,7 @@
 
         ImportRiverCrossSectionParserCallback da66Callback =
             new ImportRiverCrossSectionParserCallback("da66");
+
         parser.parseDA66s(riverDir, da66Callback);
     }
 


More information about the Dive4elements-commits mailing list