Mercurial > dive4elements > river
changeset 2815:3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
flys-backend/trunk@4232 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 13 Apr 2012 09:57:37 +0000 (2012-04-13) |
parents | bfd6a7ef0ad5 |
children | 70b4a31a3306 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/LineParser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java |
diffstat | 4 files changed, 210 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Fri Apr 13 09:52:22 2012 +0000 +++ b/flys-backend/ChangeLog Fri Apr 13 09:57:37 2012 +0000 @@ -1,3 +1,16 @@ +2012-04-13 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/importer/parsers/LineParser.java: New. + An abstract parser that might be used to read a file and handle each + line contained in the file seperatly. + + * src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java: + New. Subclasses LineParser. It is able to parse MINFO specific sediment + density files. NOTE: currently just a stub. + + * src/main/java/de/intevation/flys/importer/ImportRiver.java: Prepared to + read MINFO specific sediment density files. + 2012-04-13 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/importer/Config.java: Added a new
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Fri Apr 13 09:52:22 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Fri Apr 13 09:57:37 2012 +0000 @@ -30,6 +30,7 @@ import de.intevation.flys.importer.parsers.AnnotationsParser; import de.intevation.flys.importer.parsers.AnnotationClassifier; import de.intevation.flys.importer.parsers.PegelGltParser; +import de.intevation.flys.importer.parsers.SedimentDensityParser; import de.intevation.flys.importer.parsers.WstParser; import org.hibernate.Session; @@ -67,6 +68,8 @@ public static final String BED_HEIGHT_EPOCH_DIR = "Epochen"; + public static final String SEDIMENT_DENSITY_DIR = "Sedimentdichte"; + protected String name; @@ -96,6 +99,8 @@ protected List<ImportBedHeight> bedHeightEpochs; + protected List<ImportSedimentDensity> sedimentDensities; + protected ImportWst wst; protected ImportUnit wstUnit; @@ -105,13 +110,14 @@ protected River peer; public ImportRiver() { - hyks = new ArrayList<ImportHYK>(); - crossSections = new ArrayList<ImportCrossSection>(); - extraWsts = new ArrayList<ImportWst>(); - fixations = new ArrayList<ImportWst>(); - officialLines = new ArrayList<ImportWst>(); - floodWater = new ArrayList<ImportWst>(); - floodProtection = new ArrayList<ImportWst>(); + hyks = new ArrayList<ImportHYK>(); + crossSections = new ArrayList<ImportCrossSection>(); + extraWsts = new ArrayList<ImportWst>(); + fixations = new ArrayList<ImportWst>(); + officialLines = new ArrayList<ImportWst>(); + floodWater = new ArrayList<ImportWst>(); + floodProtection = new ArrayList<ImportWst>(); + sedimentDensities = new ArrayList<ImportSedimentDensity>(); } public ImportRiver( @@ -176,6 +182,7 @@ parseFloodWater(); parseFloodProtection(); parseBedHeight(); + parseSedimentDensity(); } public void parseFloodProtection() throws IOException { @@ -247,6 +254,36 @@ } + protected void parseSedimentDensity() throws IOException { + log.debug("Parse sediment density"); + + if (Config.INSTANCE.skipSedimentDensity()) { + log.info("skip parsing sediment density."); + return; + } + + File minfoDir = getMinfoDir(); + File sediment = new File(minfoDir, SEDIMENT_DENSITY_DIR); + + File[] files = sediment.listFiles(); + + if (files == null) { + log.warn("Cannot parse directory '" + sediment + "'"); + return; + } + + SedimentDensityParser parser = new SedimentDensityParser(); + + for (File file: files) { + parser.parse(file); + } + + sedimentDensities = parser.getSedimentDensities(); + + log.info("Parsed " + sedimentDensities.size() + " sediment densities."); + } + + protected void parseBedHeightSingles(File dir) throws IOException { log.debug("Parse bed height singles"); @@ -612,6 +649,7 @@ storeFloodWater(); storeFloodProtection(); storeBedHeight(); + storeSedimentDensity(); } public void storeWstUnit() { @@ -774,6 +812,14 @@ } } + public void storeSedimentDensity() { + if (!Config.INSTANCE.skipSedimentDensity()) { + log.info("store sediment density"); + + // TODO + } + } + public void storeAnnotations() { if (!Config.INSTANCE.skipAnnotations()) { River river = getPeer();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/LineParser.java Fri Apr 13 09:57:37 2012 +0000 @@ -0,0 +1,93 @@ +package de.intevation.flys.importer.parsers; + +import java.io.File; + +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +import java.io.IOException; +import java.io.LineNumberReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +import org.apache.log4j.Logger; + + +public abstract class LineParser { + + private static final Logger log = Logger.getLogger(LineParser.class); + + public static final String ENCODING = "ISO-8859-1"; + + public static final Locale DEFAULT_LOCALE = Locale.GERMAN; + + public static final String START_META_CHAR = "#"; + public static final String SEPERATOR_CHAR = ";"; + + + protected abstract void handleLine(String line); + + protected abstract void reset(); + + protected abstract void finish(); + + + /** + * This method reads each line of <i>file</i>. At the beginning, + * <i>reset()</i> is called; afterwars for each line <i>handleLine()</i> is + * called; at the end <i>finish</i> is called. + * + * @param file The file which should be parsed. + */ + public void parse(File file) throws IOException { + log.info("Parsing file '" + file + "'"); + + reset(); + + LineNumberReader in = null; + try { + in = + new LineNumberReader( + new InputStreamReader( + new FileInputStream(file), ENCODING)); + + String line = null; + while ((line = in.readLine()) != null) { + if ((line = line.trim()).length() == 0) { + continue; + } + + handleLine(line); + } + } + finally { + if (in != null) { + in.close(); + } + } + + finish(); + } + + + protected static String stripMetaLine(String line) { + String tmp = line.substring(1, line.length()); + + if (tmp.startsWith(" ")) { + return tmp.substring(1, tmp.length()); + } + else { + return tmp; + } + } + + + public static Date getDateFromYear(int year) { + Calendar cal = Calendar.getInstance(); + cal.set(year, 0, 1); + + return cal.getTime(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java Fri Apr 13 09:57:37 2012 +0000 @@ -0,0 +1,51 @@ +package de.intevation.flys.importer.parsers; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import de.intevation.flys.importer.ImportSedimentDensity; + + +public class SedimentDensityParser extends LineParser { + + private static final Logger log = + Logger.getLogger(SedimentDensityParser.class); + + + protected List<ImportSedimentDensity> sedimentDensities; + + protected ImportSedimentDensity current; + + + public SedimentDensityParser() { + sedimentDensities = new ArrayList<ImportSedimentDensity>(); + } + + + @Override + protected void reset() { + current = new ImportSedimentDensity(); + } + + + @Override + protected void finish() { + if (current != null) { + sedimentDensities.add(current); + } + } + + + @Override + protected void handleLine(String line) { + log.debug("handle line: '" + line + "'"); + } + + + public List<ImportSedimentDensity> getSedimentDensities() { + return sedimentDensities; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :