# HG changeset patch # User Sascha L. Teichmann # Date 1409904556 -7200 # Node ID 67b663ed049617dc768d1bd3445fa06d5f501678 # Parent 59e50aa0c6c2b2b85670dd0fa71e90e58bbfc91c Anti programming: Removed TIM parser which ist not needed any longer. diff -r 59e50aa0c6c2 -r 67b663ed0496 backend/src/main/java/org/dive4elements/river/importer/parsers/tim/LexiComparator.java --- a/backend/src/main/java/org/dive4elements/river/importer/parsers/tim/LexiComparator.java Thu Sep 04 17:47:32 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.importer.parsers.tim; - -import java.util.Comparator; - -public class LexiComparator implements Comparator { - - public static final LexiComparator CMP = new LexiComparator(); - - @Override - public int compare(Coordinate a, Coordinate b) { - if (a.x < b.x) return -1; - if (a.x > b.x) return +1; - if (a.y < b.y) return -1; - if (a.y > b.y) return +1; - return 0; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 59e50aa0c6c2 -r 67b663ed0496 backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java --- a/backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java Thu Sep 04 17:47:32 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.importer.parsers.tim; - -/** Two coordinates and a helper. */ -public class Line { - - public Coordinate a; - public Coordinate b; - - public Line() { - } - - public Line(Coordinate a, Coordinate b) { - this.a = a; - this.b = b; - } - - /** Project coordinate to line. */ - public double distanceToFirst(Coordinate c) { - - double nx = b.x - a.x; - double ny = b.y - a.y; - - double len = Math.sqrt(nx*nx + ny*ny); - - nx /= len; - ny /= len; - - double px = c.x - a.x; - double py = c.y - a.y; - - return nx*px + ny*py; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 59e50aa0c6c2 -r 67b663ed0496 backend/src/main/java/org/dive4elements/river/importer/parsers/tim/TIMParser.java --- a/backend/src/main/java/org/dive4elements/river/importer/parsers/tim/TIMParser.java Thu Sep 04 17:47:32 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ - -package org.dive4elements.river.importer.parsers.tim; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.log4j.Logger; - -import org.dive4elements.river.backend.utils.EpsilonComparator; - -/** Parser for single .tim files. */ -public class TIMParser -{ - /** Private logger. */ - private static Logger logger = Logger.getLogger(TIMParser.class); - - /** Proper encoding. */ - public static final String ENCODING = - System.getProperty("tim.encoding", "ISO-8859-1"); - - /** Map of stations (km) to points (xyz). */ - protected Map> lines; - - public TIMParser() { - lines = new TreeMap>(EpsilonComparator.CMP); - } - - /** Access map of stations (km) to coordinates (xyz). */ - public Map> getLines() { - return lines; - } - - /** Get number of lines (data). */ - public int numLines() { - return lines.size(); - } - - /** Parse single .tim file. */ - public void load(String filename) throws IOException { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - new FileInputStream(filename), ENCODING)); - try { - String row; - while ((row = reader.readLine()) != null) { - if (row.length() < 54) { - logger.warn("row too short"); - continue; - } - double station, x, y, z; - try { - station = Double.parseDouble(row.substring( 9, 16))/1000d; - x = Double.parseDouble(row.substring(20, 30))/1000d; - y = Double.parseDouble(row.substring(30, 40))/1000d; - z = Double.parseDouble(row.substring(47, 54))/10000d; - } catch (NumberFormatException nfe) { - logger.warn("Invalid row"); - continue; - } - - Double km = station; - - List line = lines.get(km); - if (line == null) { - line = new ArrayList(); - lines.put(km, line); - } - - line.add(new Coordinate(x, y, z)); - } - // Bring coords in lexicographical order. - sortCoordinates(); - } finally { - reader.close(); - } - } - - /** Sort coordinates of lines lexicographically. */ - protected void sortCoordinates() { - for (List line: lines.values()) { - Collections.sort(line, LexiComparator.CMP); - } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :