Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java @ 5083:7bbee0cfc171 slt-simplify-cross-sections
Added experimental Douglas Peuker simplification of cross sections.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 24 Feb 2013 17:29:52 +0100 |
parents | 05ff91146ddd |
children | ca45dd039b54 |
comparison
equal
deleted
inserted
replaced
5082:fb4d87274f28 | 5083:7bbee0cfc171 |
---|---|
1 package de.intevation.flys.importer; | 1 package de.intevation.flys.importer; |
2 | 2 |
3 import java.io.File; | 3 import de.intevation.artifacts.common.utils.FileTools.HashedFile; |
4 import java.io.IOException; | |
5 import java.sql.SQLException; | |
6 import java.util.ArrayList; | |
7 import java.util.Calendar; | |
8 import java.util.Date; | |
9 import java.util.HashSet; | |
10 import java.util.List; | |
11 import java.util.Map; | |
12 import java.util.Set; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.hibernate.Query; | |
16 import org.hibernate.Session; | |
17 import org.hibernate.exception.ConstraintViolationException; | |
18 | 4 |
19 import de.intevation.artifacts.common.utils.FileTools; | 5 import de.intevation.artifacts.common.utils.FileTools; |
20 import de.intevation.artifacts.common.utils.FileTools.HashedFile; | 6 |
21 import de.intevation.flys.importer.parsers.AnnotationClassifier; | 7 import de.intevation.flys.importer.parsers.AnnotationClassifier; |
22 import de.intevation.flys.importer.parsers.AnnotationsParser; | 8 import de.intevation.flys.importer.parsers.AnnotationsParser; |
23 import de.intevation.flys.importer.parsers.BedHeightEpochParser; | 9 import de.intevation.flys.importer.parsers.BedHeightEpochParser; |
24 import de.intevation.flys.importer.parsers.BedHeightSingleParser; | 10 import de.intevation.flys.importer.parsers.BedHeightSingleParser; |
25 import de.intevation.flys.importer.parsers.CrossSectionParser; | 11 import de.intevation.flys.importer.parsers.CrossSectionParser; |
37 import de.intevation.flys.importer.parsers.SedimentYieldParser; | 23 import de.intevation.flys.importer.parsers.SedimentYieldParser; |
38 import de.intevation.flys.importer.parsers.W80Parser; | 24 import de.intevation.flys.importer.parsers.W80Parser; |
39 import de.intevation.flys.importer.parsers.WaterlevelDifferencesParser; | 25 import de.intevation.flys.importer.parsers.WaterlevelDifferencesParser; |
40 import de.intevation.flys.importer.parsers.WaterlevelParser; | 26 import de.intevation.flys.importer.parsers.WaterlevelParser; |
41 import de.intevation.flys.importer.parsers.WstParser; | 27 import de.intevation.flys.importer.parsers.WstParser; |
28 | |
42 import de.intevation.flys.model.River; | 29 import de.intevation.flys.model.River; |
43 import de.intevation.flys.model.Unit; | 30 import de.intevation.flys.model.Unit; |
31 | |
32 import de.intevation.flys.utils.DouglasPeuker; | |
33 | |
34 import java.io.File; | |
35 import java.io.IOException; | |
36 | |
37 import java.sql.SQLException; | |
38 | |
39 import java.util.ArrayList; | |
40 import java.util.Calendar; | |
41 import java.util.Date; | |
42 import java.util.HashSet; | |
43 import java.util.List; | |
44 import java.util.Map; | |
45 import java.util.Set; | |
46 | |
47 import org.apache.log4j.Logger; | |
48 | |
49 import org.hibernate.Query; | |
50 import org.hibernate.Session; | |
51 | |
52 import org.hibernate.exception.ConstraintViolationException; | |
44 | 53 |
45 | 54 |
46 /** Import all river-related data (files) that can be found. */ | 55 /** Import all river-related data (files) that can be found. */ |
47 public class ImportRiver | 56 public class ImportRiver |
48 { | 57 { |
157 | 166 |
158 protected River peer; | 167 protected River peer; |
159 | 168 |
160 | 169 |
161 /** Callback-implementation for CrossSectionParsers. */ | 170 /** Callback-implementation for CrossSectionParsers. */ |
162 class ImportRiverCrossSectionParserCallback implements CrossSectionParser.Callback { | 171 private class ImportRiverCrossSectionParserCallback |
163 Set<HashedFile> files = new HashSet<HashedFile>(); | 172 implements CrossSectionParser.Callback { |
164 String type; | 173 |
174 private Set<HashedFile> files = new HashSet<HashedFile>(); | |
175 private String type; | |
165 | 176 |
166 | 177 |
167 /** | 178 /** |
168 * Create new Callback, given type which is used for logging | 179 * Create new Callback, given type which is used for logging |
169 * purposes only. | 180 * purposes only. |
183 return success; | 194 return success; |
184 } | 195 } |
185 | 196 |
186 | 197 |
187 /** Add crosssection. */ | 198 /** Add crosssection. */ |
188 public void parsed(CrossSectionParser parser) { | 199 public void parsed(CrossSectionParser parser) { |
189 log.debug("callback from " + type + " parser"); | 200 log.debug("callback from " + type + " parser"); |
190 | 201 |
191 addCrossSections(parser); | 202 addCrossSections(parser); |
192 } | 203 } |
193 } // ImportRiverCrossSectionParserCallback | 204 } // ImportRiverCrossSectionParserCallback |
939 Map<Double, List<XY>> data = parser.getData(); | 950 Map<Double, List<XY>> data = parser.getData(); |
940 | 951 |
941 List<ImportCrossSectionLine> lines = | 952 List<ImportCrossSectionLine> lines = |
942 new ArrayList<ImportCrossSectionLine>(data.size()); | 953 new ArrayList<ImportCrossSectionLine>(data.size()); |
943 | 954 |
955 Double simplificationEpsilon = | |
956 Config.INSTANCE.getCrossSectionSimplificationEpsilon(); | |
957 | |
944 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) { | 958 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) { |
945 Double km = entry.getKey(); | 959 Double km = entry.getKey(); |
946 List<XY> points = entry.getValue(); | 960 List<XY> points = entry.getValue(); |
961 if (simplificationEpsilon != null) { | |
962 points = DouglasPeuker.simplify(points, simplificationEpsilon); | |
963 } | |
947 lines.add(new ImportCrossSectionLine(km, points)); | 964 lines.add(new ImportCrossSectionLine(km, points)); |
948 } | 965 } |
949 | 966 |
950 crossSections.add(new ImportCrossSection( | 967 crossSections.add(new ImportCrossSection( |
951 ImportRiver.this, description, ti, lines)); | 968 this, description, ti, lines)); |
952 } | 969 } |
953 | 970 |
954 /** Create a W80 Parser and parse w80 files found. */ | 971 /** Create a W80 Parser and parse w80 files found. */ |
955 public void parseW80s() { | 972 public void parseW80s() { |
956 if (Config.INSTANCE.skipW80s()) { | 973 if (Config.INSTANCE.skipW80s()) { |
1078 } | 1095 } |
1079 } | 1096 } |
1080 } | 1097 } |
1081 | 1098 |
1082 public void storeCrossSections() { | 1099 public void storeCrossSections() { |
1083 if (!Config.INSTANCE.skipPRFs() || !Config.INSTANCE.skipDA66s() || !Config.INSTANCE.skipDA50s() || !Config.INSTANCE.skipW80s()) { | 1100 if (!Config.INSTANCE.skipPRFs() |
1101 || !Config.INSTANCE.skipDA66s() | |
1102 || !Config.INSTANCE.skipDA50s() | |
1103 || !Config.INSTANCE.skipW80s()) { | |
1084 log.info("store cross sections"); | 1104 log.info("store cross sections"); |
1085 getPeer(); | 1105 getPeer(); |
1086 for (ImportCrossSection crossSection: crossSections) { | 1106 for (ImportCrossSection crossSection: crossSections) { |
1087 crossSection.storeDependencies(); | 1107 crossSection.storeDependencies(); |
1088 } | 1108 } |