Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / TrkFile.java @ 2249

History | View | Annotate | Download (4 KB)

1
/*
2
 * Created on 21-jun-2005
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.cresques.io;
48

    
49
import java.io.DataInputStream;
50
import java.io.EOFException;
51
import java.io.FileInputStream;
52
import java.io.FileNotFoundException;
53
import java.io.IOException;
54
import java.io.InputStream;
55

    
56
import org.cresques.cts.ICoordTrans;
57
import org.cresques.cts.IProjection;
58
import org.cresques.px.IObjList;
59
import org.cresques.px.PxObjList;
60
import org.cresques.px.gml.LineString;
61

    
62
/**
63
 * @author luisw
64
 */
65
public class TrkFile  extends GeoFile {
66

    
67
        private DataInputStream is;
68
        long l = 0;
69
        LineString line;
70

    
71
        public TrkFile(IProjection proj, String name) {
72
                super(proj, name);
73
        }
74
        /* (no Javadoc)
75
         * @see org.cresques.io.GeoFile#load()
76
         */
77
        public GeoFile load() {
78
                try {
79
                        return load(new FileInputStream(name));
80
                } catch (NumberFormatException e) {
81
                        // TODO Bloque catch generado autom?ticamente
82
                        e.printStackTrace();
83
                } catch (FileNotFoundException e) {
84
                        // TODO Bloque catch generado autom?ticamente
85
                        e.printStackTrace();
86
                } catch (Exception e) {
87
                        // TODO Bloque catch generado autom?ticamente
88
                        e.printStackTrace();
89
                }
90
                return this;
91
        }
92
        
93
        public GeoFile load(InputStream is) throws NumberFormatException, Exception {
94
                System.out.println("Trk: Cargando '"+name+"' ...");
95
                this.is = new DataInputStream(is);
96
                line = new LineString();
97
                while (readPoint()) {
98
                        l++;
99
                }
100
                extent.add(line.getExtent());
101
                is.close();
102
                System.out.println("Trk: '"+name+"' cargado. ("+l+" puntos).");
103
                return this;
104
        }
105
        
106
        public boolean readPoint() {
107
                int        h, m, s, sgn = 1;
108
                double        D, M, S;
109
                double lat, lng;
110
                try {
111
                        h = is.readUnsignedByte();
112
                        m = is.readUnsignedByte();
113
                        s = is.readUnsignedByte();
114
                        is.skipBytes(1);
115
                        D = is.readUnsignedByte();
116
                        M = is.readByte();
117
                        S = is.readUnsignedShort();
118
                        S /= 1000.0;
119
                        if (M<0) {
120
                                sgn = -1;
121
                                M *= -1;
122
                        } else sgn = 1;
123
                        lat = sgn * (D + (M/60D+S/3600D));
124
                        D = is.readUnsignedByte();
125
                        M = is.readByte();
126
                        S = is.readUnsignedShort();
127
                        S /= 1000.0;
128
                        if (M<0) {
129
                                sgn = -1;
130
                                M *= -1;
131
                        } else sgn = 1;
132
                        lng = sgn * (D + (M/60D+S/3600D));
133
                        line.add(proj.createPoint(lng, lat));
134
                } catch (EOFException eof) {
135
                        return false;
136
                } catch (IOException e) {
137
                        // TODO Bloque catch generado autom?ticamente
138
                        e.printStackTrace();
139
                        return false;
140
                }
141
                return true;
142
        }
143
        /* (no Javadoc)
144
         * @see org.cresques.io.GeoFile#reProject(org.cresques.geo.ReProjection)
145
         */
146
        public IObjList getObjects() {
147
                IObjList oList = new PxObjList(proj);
148
                oList.add(line);
149
                return oList;
150
        }
151
        public void reProject(ICoordTrans rp) {
152
                line.reProject(rp);
153
                setProjection(rp.getPDest());
154
        }
155
        /* (non-Javadoc)
156
         * @see org.cresques.io.GeoFile#close()
157
         */
158
        public void close() {
159
                // TODO Auto-generated method stub
160
                
161
        }
162

    
163

    
164
}