comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java @ 5084:ca45dd039b54 slt-simplify-cross-sections

Log the number of points of cross sections to see the effect of the simplification.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 24 Feb 2013 21:38:09 +0100
parents 7bbee0cfc171
children
comparison
equal deleted inserted replaced
5083:7bbee0cfc171 5084:ca45dd039b54
170 /** Callback-implementation for CrossSectionParsers. */ 170 /** Callback-implementation for CrossSectionParsers. */
171 private class ImportRiverCrossSectionParserCallback 171 private class ImportRiverCrossSectionParserCallback
172 implements CrossSectionParser.Callback { 172 implements CrossSectionParser.Callback {
173 173
174 private Set<HashedFile> files = new HashSet<HashedFile>(); 174 private Set<HashedFile> files = new HashSet<HashedFile>();
175 private String type; 175 private String type;
176
177 176
178 /** 177 /**
179 * Create new Callback, given type which is used for logging 178 * Create new Callback, given type which is used for logging
180 * purposes only. 179 * purposes only.
181 */ 180 */
182 public ImportRiverCrossSectionParserCallback (String type) { 181 public ImportRiverCrossSectionParserCallback(String type) {
183 this.type = type; 182 this.type = type;
184 } 183 }
185 184
186 185
187 /** Accept file if not duplicate. */ 186 /** Accept file if not duplicate. */
187 @Override
188 public boolean accept(File file) { 188 public boolean accept(File file) {
189 HashedFile hf = new HashedFile(file); 189 HashedFile hf = new HashedFile(file);
190 boolean success = files.add(hf); 190 boolean success = files.add(hf);
191 if (!success) { 191 if (!success) {
192 log.warn(type + " file '" + file + "' seems to be a duplicate."); 192 log.warn(type + " file '" + file + "' seems to be a duplicate.");
194 return success; 194 return success;
195 } 195 }
196 196
197 197
198 /** Add crosssection. */ 198 /** Add crosssection. */
199 @Override
199 public void parsed(CrossSectionParser parser) { 200 public void parsed(CrossSectionParser parser) {
200 log.debug("callback from " + type + " parser"); 201 log.debug("callback from " + type + " parser");
201 202
202 addCrossSections(parser); 203 String description = parser.getDescription();
204 Integer year = parser.getYear();
205 ImportTimeInterval ti = year != null
206 ? new ImportTimeInterval(yearToDate(year))
207 : null;
208
209 Map<Double, List<XY>> data = parser.getData();
210
211 List<ImportCrossSectionLine> lines =
212 new ArrayList<ImportCrossSectionLine>(data.size());
213
214 Double simplificationEpsilon =
215 Config.INSTANCE.getCrossSectionSimplificationEpsilon();
216
217 long numReadPoints = 0L;
218 long numRemainingPoints = 0L;
219
220 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
221 Double km = entry.getKey();
222 List<XY> points = entry.getValue();
223 numReadPoints += points.size();
224 if (simplificationEpsilon != null) {
225 points = DouglasPeuker.simplify(points, simplificationEpsilon);
226 }
227 numRemainingPoints += points.size();
228 lines.add(new ImportCrossSectionLine(km, points));
229 }
230
231 ImportRiver.this.addCrossSections(description, ti, lines);
232
233 double percent = numReadPoints > 0L
234 ? ((double)numRemainingPoints/numReadPoints)*100d
235 : 0d;
236
237 log.info(String.format(
238 "Number of points in cross section: %d / %d (%.2f%%)",
239 numReadPoints, numRemainingPoints, percent));
203 } 240 }
204 } // ImportRiverCrossSectionParserCallback 241 } // ImportRiverCrossSectionParserCallback
242
243
244 private void addCrossSections(
245 String description,
246 ImportTimeInterval ti,
247 List<ImportCrossSectionLine> lines
248 ) {
249 crossSections.add(new ImportCrossSection(this, description, ti, lines));
250 }
205 251
206 252
207 public ImportRiver() { 253 public ImportRiver() {
208 hyks = new ArrayList<ImportHYK>(); 254 hyks = new ArrayList<ImportHYK>();
209 crossSections = new ArrayList<ImportCrossSection>(); 255 crossSections = new ArrayList<ImportCrossSection>();
936 } 982 }
937 }); 983 });
938 } 984 }
939 985
940 986
941 /** Add cross sections with description, years and lines to
942 * store. */
943 private void addCrossSections(CrossSectionParser parser) {
944 String description = parser.getDescription();
945 Integer year = parser.getYear();
946 ImportTimeInterval ti = year != null
947 ? new ImportTimeInterval(yearToDate(year))
948 : null;
949
950 Map<Double, List<XY>> data = parser.getData();
951
952 List<ImportCrossSectionLine> lines =
953 new ArrayList<ImportCrossSectionLine>(data.size());
954
955 Double simplificationEpsilon =
956 Config.INSTANCE.getCrossSectionSimplificationEpsilon();
957
958 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
959 Double km = entry.getKey();
960 List<XY> points = entry.getValue();
961 if (simplificationEpsilon != null) {
962 points = DouglasPeuker.simplify(points, simplificationEpsilon);
963 }
964 lines.add(new ImportCrossSectionLine(km, points));
965 }
966
967 crossSections.add(new ImportCrossSection(
968 this, description, ti, lines));
969 }
970
971 /** Create a W80 Parser and parse w80 files found. */ 987 /** Create a W80 Parser and parse w80 files found. */
972 public void parseW80s() { 988 public void parseW80s() {
973 if (Config.INSTANCE.skipW80s()) { 989 if (Config.INSTANCE.skipW80s()) {
974 log.info("skip parsing W80s"); 990 log.info("skip parsing W80s");
975 return; 991 return;
1001 .getParentFile() // Hydrologie 1017 .getParentFile() // Hydrologie
1002 .getParentFile(); // <river> 1018 .getParentFile(); // <river>
1003 1019
1004 ImportRiverCrossSectionParserCallback da50Callback = 1020 ImportRiverCrossSectionParserCallback da50Callback =
1005 new ImportRiverCrossSectionParserCallback("da50"); 1021 new ImportRiverCrossSectionParserCallback("da50");
1022
1006 parser.parseDA50s(riverDir, da50Callback); 1023 parser.parseDA50s(riverDir, da50Callback);
1007 } 1024 }
1008 1025
1009 1026
1010 /** Create a DA66 Parser and parse the da66 files found. */ 1027 /** Create a DA66 Parser and parse the da66 files found. */
1022 .getParentFile() // Hydrologie 1039 .getParentFile() // Hydrologie
1023 .getParentFile(); // <river> 1040 .getParentFile(); // <river>
1024 1041
1025 ImportRiverCrossSectionParserCallback da66Callback = 1042 ImportRiverCrossSectionParserCallback da66Callback =
1026 new ImportRiverCrossSectionParserCallback("da66"); 1043 new ImportRiverCrossSectionParserCallback("da66");
1044
1027 parser.parseDA66s(riverDir, da66Callback); 1045 parser.parseDA66s(riverDir, da66Callback);
1028 } 1046 }
1029 1047
1030 /** Create a PRFParser and let it parse the prf files found. */ 1048 /** Create a PRFParser and let it parse the prf files found. */
1031 public void parsePRFs() { 1049 public void parsePRFs() {

http://dive4elements.wald.intevation.org