Ignore:
Timestamp:
2006-03-25T16:21:09+01:00 (18 years ago)
Author:
imi
Message:
  • refactored GpsPoint to be immutable and added LatLon and NorthEast
  • refactored Bounding Box calculations
  • various other renames
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/io/RawGpsReader.java

    r64 r71  
    1111import org.jdom.Namespace;
    1212import org.jdom.input.SAXBuilder;
    13 import org.openstreetmap.josm.data.GeoPoint;
     13import org.openstreetmap.josm.data.coor.LatLon;
    1414
    1515/**
    16  * Read raw gps data from a gpx file. Only way points with their waies segments
     16 * Read raw gps data from a gpx file. Only way points with their ways segments
    1717 * and waypoints are imported.
    1818 * @author imi
     
    4242         * Parse and return the read data
    4343         */
    44         public Collection<Collection<GeoPoint>> parse() throws JDOMException, IOException {
     44        public Collection<Collection<LatLon>> parse() throws JDOMException, IOException {
    4545                final SAXBuilder builder = new SAXBuilder();
    4646                builder.setValidation(false);
     
    5555         */
    5656        @SuppressWarnings("unchecked")
    57         private Collection<Collection<GeoPoint>> parseData(Element root) throws JDOMException {
    58                 Collection<Collection<GeoPoint>> data = new LinkedList<Collection<GeoPoint>>();
     57        private Collection<Collection<LatLon>> parseData(Element root) throws JDOMException {
     58                Collection<Collection<LatLon>> data = new LinkedList<Collection<LatLon>>();
    5959
    6060                // workaround for bug where the server adds /gpx.asd to the namespace
     
    6262               
    6363                for (Object o : root.getChildren("wpt", GPX)) {
    64                         Collection<GeoPoint> line = new LinkedList<GeoPoint>();
    65                         line.add(new GeoPoint(parseDouble((Element)o, LatLon.lat), parseDouble((Element)o, LatLon.lon)));
     64                        Collection<LatLon> line = new LinkedList<LatLon>();
     65                        line.add(new LatLon(parseDouble((Element)o, LatLonAttr.lat), parseDouble((Element)o, LatLonAttr.lon)));
    6666                        data.add(line);
    6767                }
    6868                for (Object o : root.getChildren("rte", GPX)) {
    69                         Collection<GeoPoint> line = parseLine(((Element)o).getChildren("rtept", GPX));
     69                        Collection<LatLon> line = parseLine(((Element)o).getChildren("rtept", GPX));
    7070                        if (!line.isEmpty())
    7171                                data.add(line);
     
    7373                for (Object o : root.getChildren("trk", GPX)) {
    7474                        for (Object seg : ((Element)o).getChildren("trkseg", GPX)) {
    75                                 Collection<GeoPoint> line = parseLine(((Element)seg).getChildren("trkpt", GPX));
     75                                Collection<LatLon> line = parseLine(((Element)seg).getChildren("trkpt", GPX));
    7676                                if (!line.isEmpty())
    7777                                        data.add(line);
     
    8181        }
    8282
    83         enum LatLon {lat, lon}
     83        private enum LatLonAttr {lat, lon}
    8484        /**
    8585         * Return a parsed float value from the element behind the object o.
     
    8888         * @throws JDOMException If the absolute of the value is out of bound.
    8989         */
    90         private double parseDouble(Element e, LatLon attr) throws JDOMException {
     90        private double parseDouble(Element e, LatLonAttr attr) throws JDOMException {
    9191                double d = Double.parseDouble(e.getAttributeValue(attr.toString()));
    92                 if (Math.abs(d) > (attr == LatLon.lat ? 90 : 180))
     92                if (Math.abs(d) > (attr == LatLonAttr.lat ? 90 : 180))
    9393                        throw new JDOMException("Data error: "+attr+" value '"+d+"' is out of bound.");
    9494                return d;
     
    9999         * points read.
    100100         */
    101         private Collection<GeoPoint> parseLine(List<Element> wpt) throws JDOMException {
    102                 Collection<GeoPoint> data = new LinkedList<GeoPoint>();
     101        private Collection<LatLon> parseLine(List<Element> wpt) throws JDOMException {
     102                Collection<LatLon> data = new LinkedList<LatLon>();
    103103                for (Element e : wpt)
    104                         data.add(new GeoPoint(parseDouble(e, LatLon.lat), parseDouble(e, LatLon.lon)));
     104                        data.add(new LatLon(parseDouble(e, LatLonAttr.lat), parseDouble(e, LatLonAttr.lon)));
    105105                return data;
    106106        }
Note: See TracChangeset for help on using the changeset viewer.