Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / TrkFile.java @ 199

History | View | Annotate | Download (2.68 KB)

1
/*
2
 * Creado el 21-jun-2004
3
 */
4
package org.cresques.io;
5

    
6
import java.io.DataInputStream;
7
import java.io.EOFException;
8
import java.io.FileInputStream;
9
import java.io.FileNotFoundException;
10
import java.io.IOException;
11
import java.io.InputStream;
12

    
13
import org.cresques.cts.ICoordTrans;
14
import org.cresques.cts.IProjection;
15
import org.cresques.px.IObjList;
16
import org.cresques.px.PxObjList;
17
import org.cresques.px.gml.LineString;
18

    
19
/**
20
 * @author luisw
21
 */
22
public class TrkFile  extends GeoFile {
23

    
24
        private DataInputStream is;
25
        long l = 0;
26
        LineString line;
27

    
28
        public TrkFile(IProjection proj, String name) {
29
                super(proj, name);
30
        }
31
        /* (no Javadoc)
32
         * @see org.cresques.io.GeoFile#load()
33
         */
34
        public GeoFile load() {
35
                try {
36
                        return load(new FileInputStream(name));
37
                } catch (NumberFormatException e) {
38
                        // TODO Bloque catch generado autom?ticamente
39
                        e.printStackTrace();
40
                } catch (FileNotFoundException e) {
41
                        // TODO Bloque catch generado autom?ticamente
42
                        e.printStackTrace();
43
                } catch (Exception e) {
44
                        // TODO Bloque catch generado autom?ticamente
45
                        e.printStackTrace();
46
                }
47
                return this;
48
        }
49
        
50
        public GeoFile load(InputStream is) throws NumberFormatException, Exception {
51
                System.out.println("Trk: Cargando '"+name+"' ...");
52
                this.is = new DataInputStream(is);
53
                line = new LineString();
54
                while (readPoint()) {
55
                        l++;
56
                }
57
                extent.add(line.getExtent());
58
                is.close();
59
                System.out.println("Trk: '"+name+"' cargado. ("+l+" puntos).");
60
                return this;
61
        }
62
        
63
        public boolean readPoint() {
64
                int        h, m, s, sgn = 1;
65
                double        D, M, S;
66
                double lat, lng;
67
                try {
68
                        h = is.readUnsignedByte();
69
                        m = is.readUnsignedByte();
70
                        s = is.readUnsignedByte();
71
                        is.skipBytes(1);
72
                        D = is.readUnsignedByte();
73
                        M = is.readByte();
74
                        S = is.readUnsignedShort();
75
                        S /= 1000.0;
76
                        if (M<0) {
77
                                sgn = -1;
78
                                M *= -1;
79
                        } else sgn = 1;
80
                        lat = sgn * (D + (M/60D+S/3600D));
81
                        D = is.readUnsignedByte();
82
                        M = is.readByte();
83
                        S = is.readUnsignedShort();
84
                        S /= 1000.0;
85
                        if (M<0) {
86
                                sgn = -1;
87
                                M *= -1;
88
                        } else sgn = 1;
89
                        lng = sgn * (D + (M/60D+S/3600D));
90
                        line.add(proj.createPoint(lng, lat));
91
                } catch (EOFException eof) {
92
                        return false;
93
                } catch (IOException e) {
94
                        // TODO Bloque catch generado autom?ticamente
95
                        e.printStackTrace();
96
                        return false;
97
                }
98
                return true;
99
        }
100
        /* (no Javadoc)
101
         * @see org.cresques.io.GeoFile#reProject(org.cresques.geo.ReProjection)
102
         */
103
        public IObjList getObjects() {
104
                IObjList oList = new PxObjList(proj);
105
                oList.add(line);
106
                return oList;
107
        }
108
        public void reProject(ICoordTrans rp) {
109
                line.reProject(rp);
110
                setProjection(rp.getPDest());
111
        }
112
        /* (non-Javadoc)
113
         * @see org.cresques.io.GeoFile#close()
114
         */
115
        public void close() {
116
                // TODO Auto-generated method stub
117
                
118
        }
119

    
120

    
121
}