Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/uinfo/parsers/VegetationParser.java @ 9401:361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
author | mschaefer |
---|---|
date | Tue, 14 Aug 2018 14:02:26 +0200 |
parents | df6f1b5806f6 |
children | 6146358c4842 |
comparison
equal
deleted
inserted
replaced
9400:8e100593aec3 | 9401:361de818f76e |
---|---|
43 | 43 |
44 private static final Pattern META_COLUMNTITLES = Pattern.compile("^#*\\s*Vegetationstyp\\s*;.+", Pattern.CASE_INSENSITIVE); | 44 private static final Pattern META_COLUMNTITLES = Pattern.compile("^#*\\s*Vegetationstyp\\s*;.+", Pattern.CASE_INSENSITIVE); |
45 | 45 |
46 private enum ColTitlePattern { | 46 private enum ColTitlePattern { |
47 OVERFLOW_LIMIT("((.)|(Ue))berflutungsdauer-bis\\s*\\[(.*)\\].*"), // | 47 OVERFLOW_LIMIT("((.)|(Ue))berflutungsdauer-bis\\s*\\[(.*)\\].*"), // |
48 CLASSNO("Vegetationsklasse.*"); | 48 CLASSNO("Vegetationsklasse.*"), // |
49 COLOR_R("Rot"), // | |
50 COLOR_G("Gr((.)|(ue))n"), // | |
51 COLOR_B("Blau"); | |
49 | 52 |
50 private final Pattern pattern; | 53 private final Pattern pattern; |
51 | 54 |
52 ColTitlePattern(final String regexp) { | 55 ColTitlePattern(final String regexp) { |
53 this.pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE); | 56 this.pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE); |
151 logError("Column of the overflow duration limit and/or vegetation zone class could not be identified"); | 154 logError("Column of the overflow duration limit and/or vegetation zone class could not be identified"); |
152 this.headerParsingState = ParsingState.STOP; | 155 this.headerParsingState = ParsingState.STOP; |
153 return true; | 156 return true; |
154 } | 157 } |
155 this.previousClassNo = 0; | 158 this.previousClassNo = 0; |
156 this.previousDaysLimit = 0; | 159 this.previousDaysLimit = -1; |
157 return true; | 160 return true; |
158 } | 161 } |
159 | 162 |
160 @Override | 163 @Override |
161 protected VegetationZoneImport createKmLineImport(final Double km, final String[] values) { | 164 protected VegetationZoneImport createKmLineImport(final Double km, final String[] values) { |
162 int daysLimit = 365; | 165 int daysLimit = 366; |
163 int classNo = 0; | 166 int classNo = 0; |
164 try { | 167 try { |
165 if (!values[this.cols.get(ColTitlePattern.OVERFLOW_LIMIT)].trim().isEmpty()) | 168 if (!values[this.cols.get(ColTitlePattern.OVERFLOW_LIMIT)].trim().isEmpty()) |
166 daysLimit = Integer.parseInt(values[this.cols.get(ColTitlePattern.OVERFLOW_LIMIT)]); | 169 daysLimit = Integer.parseInt(values[this.cols.get(ColTitlePattern.OVERFLOW_LIMIT)]); |
167 classNo = Integer.parseInt(values[this.cols.get(ColTitlePattern.CLASSNO)]); | 170 classNo = Integer.parseInt(values[this.cols.get(ColTitlePattern.CLASSNO)]); |
178 // if (!this.types.containsKey(Integer.valueOf(classNo))) { | 181 // if (!this.types.containsKey(Integer.valueOf(classNo))) { |
179 // logError("Unknown vegetation zone class: line " + this.in.getLineNumber()); | 182 // logError("Unknown vegetation zone class: line " + this.in.getLineNumber()); |
180 // return null; | 183 // return null; |
181 // } | 184 // } |
182 this.previousClassNo = classNo; | 185 this.previousClassNo = classNo; |
183 final Integer minDays = Integer.valueOf(this.previousDaysLimit); | 186 final int minDays = this.previousDaysLimit + 1; |
184 this.previousDaysLimit = daysLimit + 1; | 187 this.previousDaysLimit = daysLimit; |
185 return new VegetationZoneImport(classNo, minDays, Integer.valueOf(this.previousDaysLimit)); | 188 final int red = (this.cols.get(ColTitlePattern.COLOR_R) >= 0) ? Integer.parseInt(values[this.cols.get(ColTitlePattern.COLOR_R)]) : 0; |
189 final int green = (this.cols.get(ColTitlePattern.COLOR_G) >= 0) ? Integer.parseInt(values[this.cols.get(ColTitlePattern.COLOR_G)]) : 0; | |
190 final int blue = (this.cols.get(ColTitlePattern.COLOR_B) >= 0) ? Integer.parseInt(values[this.cols.get(ColTitlePattern.COLOR_B)]) : 0; | |
191 return new VegetationZoneImport(classNo, minDays, daysLimit, red, green, blue); | |
186 } | 192 } |
187 } | 193 } |