Statistics
| Revision:

root / trunk / libraries / libCresques / src / org / cresques / io / GeoFile.java @ 13167

History | View | Annotate | Download (5.17 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.util.Date;
28

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

    
35

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

    
77
    public GeoFile() {
78
    }
79

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

    
84
        if (name != null) {
85
            name = DataSourceSE.normalize(name);
86
        }
87
        extent = new Extent();
88
              transformRMF = new AffineTransform();
89
            transformTFW = new AffineTransform();
90
    }
91

    
92
    public String getName() {
93
        return name;
94
    }
95

    
96
    public void setName(String n) {
97
        name = n;
98
    }
99

    
100
    public long getFileSize() {
101
        return fileSize;
102
    }
103

    
104
    public void setFileSize(long sz) {
105
        fileSize = sz;
106
    }
107

    
108
    public IProjection getProjection() {
109
        return proj;
110
    }
111

    
112
    public void setProjection(IProjection p) {
113
        proj = p;
114
    }
115

    
116
    abstract public void reProject(ICoordTrans rp);
117

    
118
    /**
119
     * Extent completo del raster. Este contiene las coordenadas reales tanto
120
     * para un raster rotado como sin rotar. Este extent coincide con requestExtent
121
     * cuando el raster no tiene rotaci?n.
122
     * @return Extent 
123
     */
124
    public Extent getExtent() {
125
        return extent;
126
    }
127
    
128
    /**
129
     * Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el 
130
     * extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
131
     * pero para un raster rotado ser? igual al extent del raster como si no 
132
     * tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
133
     * vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
134
     * aplicado.
135
     * @return Extent
136
     */
137
    public Extent getExtentForRequest() {
138
        return requestExtent;
139
    }
140
    
141
    abstract public GeoFile load();
142

    
143
    abstract public void close();
144

    
145
    abstract public IObjList getObjects();
146

    
147
    /**
148
     * Filtra espacios en blanco. Deja solo uno por
149
     */
150
    public static String filterWS(String buf) {
151
        boolean lastCharWhite = false;
152
        String str = "";
153
        buf = buf.trim();
154

    
155
        for (int i = 0; i < buf.length(); i++) {
156
            char c = buf.charAt(i);
157

    
158
            if (Character.isWhitespace(c)) {
159
                if (lastCharWhite) {
160
                    continue;
161
                }
162

    
163
                lastCharWhite = true;
164
                c = ' ';
165
            } else {
166
                lastCharWhite = false;
167
            }
168

    
169
            str += c;
170
        }
171

    
172
        return str;
173
    }
174

    
175
    protected long getTime() {
176
        return (new Date()).getTime();
177
    }
178
}