Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_910 / libraries / libCq CMS for java.old / src / org / cresques / io / GeoFile.java @ 11275

History | View | Annotate | Download (5.2 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
    
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
              transformRMF = new AffineTransform();
90
            transformTFW = new AffineTransform();
91
    }
92

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

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

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

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

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

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

    
117
    abstract public void reProject(ICoordTrans rp);
118

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

    
144
    abstract public void close();
145

    
146
    abstract public IObjList getObjects();
147

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

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

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

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

    
170
            str += c;
171
        }
172

    
173
        return str;
174
    }
175

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