Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1014 / libraries / libCq_CMS_praster / src / org / cresques / io / GeoFile.java @ 13593

History | View | Annotate | Download (5.29 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
     * Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent
61
     * guardado en el fichero .rmf asociado a la imagen.  En caso de que no exista este fichero no habr?
62
     * transformaci?n
63
     */
64
    protected AffineTransform        transformRMF = null;
65
    /**
66
     * Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent
67
     * guardado en el fichero .tfw asociado a la imagen o en la cabecera de la misma.
68
     */
69
    protected AffineTransform        transformTFW = null;
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 = translateFileName(n);
83

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

    
92
    public String translateFileName(String fileName) {
93
            return fileName;
94
    }
95
    
96
    public String getName() {
97
        return name;
98
    }
99

    
100
    public void setName(String n) {
101
        name = n;
102
    }
103

    
104
    public long getFileSize() {
105
        return fileSize;
106
    }
107

    
108
    public void setFileSize(long sz) {
109
        fileSize = sz;
110
    }
111

    
112
    public IProjection getProjection() {
113
        return proj;
114
    }
115

    
116
    public void setProjection(IProjection p) {
117
        proj = p;
118
    }
119

    
120
    abstract public void reProject(ICoordTrans rp);
121

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

    
145
    abstract public GeoFile load();
146

    
147
    abstract public void close();
148

    
149
    abstract public IObjList getObjects();
150

    
151
    /**
152
     * Filtra espacios en blanco. Deja solo uno por
153
     */
154
    public static String filterWS(String buf) {
155
        boolean lastCharWhite = false;
156
        String str = "";
157
        buf = buf.trim();
158

    
159
        for (int i = 0; i < buf.length(); i++) {
160
            char c = buf.charAt(i);
161

    
162
            if (Character.isWhitespace(c)) {
163
                if (lastCharWhite) {
164
                    continue;
165
                }
166

    
167
                lastCharWhite = true;
168
                c = ' ';
169
            } else {
170
                lastCharWhite = false;
171
            }
172

    
173
            str += c;
174
        }
175

    
176
        return str;
177
    }
178

    
179
    protected long getTime() {
180
        return (new Date()).getTime();
181
    }
182
}