Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / io / GeoFile.java @ 8436

History | View | Annotate | Download (5.45 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Point2D;
28
import java.util.Date;
29

    
30
import org.cresques.cts.ICoordTrans;
31
import org.cresques.cts.IProjection;
32
import org.cresques.geo.Projected;
33
import org.cresques.px.Extent;
34
import org.cresques.px.IObjList;
35

    
36

    
37
/**
38
 * Ancestro de todos los formatos geogr?ficos
39
 *
40
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
41
 */
42
public abstract class GeoFile implements Projected, Extent.Has {
43
    IProjection proj = null;
44
    /**
45
     * Extent completo del raster. Este contiene las coordenadas reales tanto
46
     * para un raster rotado como sin rotar. Este extent coincide con requestExtent
47
     * cuando el raster no tiene rotaci?n. 
48
     */
49
    protected Extent extent = null;
50
    /**
51
     * Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el 
52
     * extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
53
     * pero para un raster rotado ser? igual al extent del raster como si no 
54
     * tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
55
     * vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
56
     * aplicado.
57
     */
58
    protected Extent requestExtent = null;
59
    
60
    
61
    
62
    /**
63
     * Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent
64
     * guardado en el fichero .rmf asociado a la imagen.  En caso de que no exista este fichero no habr?
65
     * transformaci?n
66
     */
67
    protected AffineTransform        transformNewExtent = null;
68
    protected AffineTransform        transformOldExtent = null;
69
    protected Point2D                         extentsRatio = null;
70
    
71
    
72
    protected boolean                        rmfExists = false;
73
    long fileSize = 0;
74
    protected long bytesReaded = 0;
75
    protected long lineCnt = 0;
76
    String name;
77

    
78
    public GeoFile() {
79
    }
80

    
81
    public GeoFile(IProjection p, String n) {
82
        proj = p;
83
        name = n;
84

    
85
        if (name != null) {
86
            name = DataSource.normalize(name);
87
        }
88
        extent = new Extent();
89
        extentsRatio = new Point2D.Double();
90
            transformNewExtent = new AffineTransform();
91
            transformOldExtent = new AffineTransform();
92
    }
93

    
94
    public String getName() {
95
        return name;
96
    }
97

    
98
    public void setName(String n) {
99
        name = n;
100
    }
101

    
102
    public long getFileSize() {
103
        return fileSize;
104
    }
105

    
106
    public void setFileSize(long sz) {
107
        fileSize = sz;
108
    }
109

    
110
    public IProjection getProjection() {
111
        return proj;
112
    }
113

    
114
    public void setProjection(IProjection p) {
115
        proj = p;
116
    }
117

    
118
    abstract public void reProject(ICoordTrans rp);
119

    
120
    /**
121
     * Extent completo del raster. Este contiene las coordenadas reales tanto
122
     * para un raster rotado como sin rotar. Este extent coincide con requestExtent
123
     * cuando el raster no tiene rotaci?n.
124
     * @return Extent 
125
     */
126
    public Extent getExtent() {
127
        return extent;
128
    }
129
    
130
    /**
131
     * Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el 
132
     * extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
133
     * pero para un raster rotado ser? igual al extent del raster como si no 
134
     * tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
135
     * vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
136
     * aplicado.
137
     * @return Extent
138
     */
139
    public Extent getExtentForRequest() {
140
        return requestExtent;
141
    }
142
    /**
143
     * Obtiene la relaci?n entre anchos y altos de la georreferenciaci?n de la imagen y la asignada
144
     * a trav?s del fichero .rmf. Esto se usa para poder realizar transformaciones entre ambos sistemas
145
     * al asignar una vista.
146
     * @return
147
     */
148
    public Point2D getExtentRatio() {
149
        return extentsRatio;
150
    }
151

    
152
    abstract public GeoFile load();
153

    
154
    abstract public void close();
155

    
156
    abstract public IObjList getObjects();
157

    
158
    /**
159
     * Filtra espacios en blanco. Deja solo uno por
160
     */
161
    public static String filterWS(String buf) {
162
        boolean lastCharWhite = false;
163
        String str = "";
164
        buf = buf.trim();
165

    
166
        for (int i = 0; i < buf.length(); i++) {
167
            char c = buf.charAt(i);
168

    
169
            if (Character.isWhitespace(c)) {
170
                if (lastCharWhite) {
171
                    continue;
172
                }
173

    
174
                lastCharWhite = true;
175
                c = ' ';
176
            } else {
177
                lastCharWhite = false;
178
            }
179

    
180
            str += c;
181
        }
182

    
183
        return str;
184
    }
185

    
186
    protected long getTime() {
187
        return (new Date()).getTime();
188
    }
189
}