svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / GeoInfo.java @ 15948
History | View | Annotate | Download (6.8 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.dataset; |
20 |
|
21 |
import java.awt.geom.AffineTransform; |
22 |
import java.util.Date; |
23 |
|
24 |
import org.cresques.cts.IProjection; |
25 |
import org.cresques.geo.Projected; |
26 |
import org.gvsig.raster.dataset.io.IRegistrableRasterFormat; |
27 |
import org.gvsig.raster.datastruct.Extent; |
28 |
|
29 |
|
30 |
/**
|
31 |
* Ancestro de todos los formatos geogr?ficos
|
32 |
*
|
33 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
34 |
*/
|
35 |
public abstract class GeoInfo implements Projected { |
36 |
protected IProjection proj = null; |
37 |
protected long fileSize = 0; |
38 |
protected long bytesReaded = 0; |
39 |
protected long lineCnt = 0; |
40 |
protected String name; |
41 |
/**
|
42 |
* Transformaci?n creada a partir de la informaci?n de georreferencia de la propia imagen.
|
43 |
* Esta informaci?n est? en la cabecera o en ficheros worldfile.
|
44 |
*/
|
45 |
protected AffineTransform ownTransformation = null; |
46 |
/**
|
47 |
* Transformaci?n asignada de forma externa, bien desde el fichero rmf o asignada directamente por
|
48 |
* el usuario.
|
49 |
*/
|
50 |
protected AffineTransform externalTransformation = null; |
51 |
|
52 |
|
53 |
public GeoInfo() {
|
54 |
} |
55 |
|
56 |
public GeoInfo(IProjection p, Object param) { |
57 |
proj = p; |
58 |
if(param instanceof String) |
59 |
name = translateFileName((String)param);
|
60 |
else if(param instanceof IRegistrableRasterFormat) |
61 |
name = ((IRegistrableRasterFormat)param).getFormatID(); |
62 |
else
|
63 |
name = String.valueOf(System.currentTimeMillis()); |
64 |
ownTransformation = new AffineTransform(); |
65 |
externalTransformation = new AffineTransform(); |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Traduce el nombre del fichero por un alias asignado por el propio
|
70 |
* driver. Cuando es traducido por un alias el driver intentar? abrir el alias y no
|
71 |
* el fichero. Esto es util porque algunos formatos tienen la extensi?n en el fichero de
|
72 |
* cabecera pero lo que se abre realmente es el fichero de datos.
|
73 |
* @param fileName
|
74 |
* @return
|
75 |
*/
|
76 |
public String translateFileName(String fileName) { |
77 |
return fileName;
|
78 |
} |
79 |
|
80 |
public String getFName() { |
81 |
return name;
|
82 |
} |
83 |
|
84 |
public void setFName(String n) { |
85 |
name = n; |
86 |
} |
87 |
|
88 |
public long getFileSize() { |
89 |
return fileSize;
|
90 |
} |
91 |
|
92 |
public void setFileSize(long sz) { |
93 |
fileSize = sz; |
94 |
} |
95 |
|
96 |
public IProjection getProjection() {
|
97 |
return proj;
|
98 |
} |
99 |
|
100 |
public void setProjection(IProjection p) { |
101 |
proj = p; |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Extent completo del raster.
|
106 |
* @return Extent
|
107 |
*/
|
108 |
abstract public Extent getExtent(); |
109 |
|
110 |
/**
|
111 |
* Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el
|
112 |
* extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
|
113 |
* pero para un raster rotado ser? igual al extent del raster como si no
|
114 |
* tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
|
115 |
* vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
|
116 |
* aplicado.
|
117 |
* @return Extent
|
118 |
*/
|
119 |
abstract public Extent getExtentWithoutRot(); |
120 |
|
121 |
abstract public GeoInfo load(); |
122 |
|
123 |
abstract public void close(); |
124 |
|
125 |
/**
|
126 |
* Filtra espacios en blanco. Deja solo uno por
|
127 |
*/
|
128 |
public static String filterWS(String buf) { |
129 |
boolean lastCharWhite = false; |
130 |
String str = ""; |
131 |
buf = buf.trim(); |
132 |
|
133 |
for (int i = 0; i < buf.length(); i++) { |
134 |
char c = buf.charAt(i);
|
135 |
|
136 |
if (Character.isWhitespace(c)) { |
137 |
if (lastCharWhite) {
|
138 |
continue;
|
139 |
} |
140 |
|
141 |
lastCharWhite = true;
|
142 |
c = ' ';
|
143 |
} else {
|
144 |
lastCharWhite = false;
|
145 |
} |
146 |
|
147 |
str += c; |
148 |
} |
149 |
|
150 |
return str;
|
151 |
} |
152 |
|
153 |
protected long getTime() { |
154 |
return (new Date()).getTime(); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* Obtiene la proyecci?n asociada al dataset en formato de cadena de texto
|
159 |
* @return Proyecci?n
|
160 |
*/
|
161 |
public String getWktProjection() throws RasterDriverException { |
162 |
return null; |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Asigna una transformaci?n al raster para que se tenga en cuenta en la asignaci?n del setView.
|
167 |
* Esta asignaci?n recalcula el extent, el requestExtent y asigna el AffineTransform que se
|
168 |
* usar? para la transformaci?n. Esta transformaci?n ser? considerada como si la imagen tuviera
|
169 |
* asociado un rmf.
|
170 |
* @param t Transformaci?n af?n a aplicar
|
171 |
*/
|
172 |
public void setAffineTransform(AffineTransform t) { |
173 |
externalTransformation = (AffineTransform)t.clone();
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Obtiene la transformaci?n afin aplicada en las peticiones con coordenadas reales. Esta
|
178 |
* corresponde al producto matricial entre la transformaci?n de la propia georreferenciaci?n
|
179 |
* del raster (ownTransformation) y la transformaci?n que se le aplique de forma externa. Si
|
180 |
* esta ?ltima no existe ser? la matriz identidad.
|
181 |
*
|
182 |
* @return Matriz de la transformaci?n af?n.
|
183 |
*/
|
184 |
public AffineTransform getAffineTransform() { |
185 |
return externalTransformation;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Elimina la matriz de transformaci?n asociada al raster y que se tiene en cuenta para
|
190 |
* el setView. Este reseteo tendr? en cuenta que si el raster tiene asociado un rmf
|
191 |
* esta transformaci?n no ser? eliminada sino que se asignar? la correspondiente al rmf
|
192 |
* existente.
|
193 |
* @return devuelve true si tiene fichero rmf asociado y false si no lo tiene.
|
194 |
*/
|
195 |
public void resetAffineTransform() { |
196 |
externalTransformation.setToIdentity(); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Obtiene la matriz de transformaci?n del propio raster. Esta matriz es la encargada
|
201 |
* de convertir las coordenadas de la petici?n en coordenadas a las que se pide a la libreria.
|
202 |
* En gdal, por ejemplo, se piden las coordenadas a la libreria en coordenadas pixel por lo que
|
203 |
* esta matriz tendr? la georreferenciaci?n asociada en el worldfile o cabecera. Otras librerias como
|
204 |
* ermapper la petici?n a la libreria se hace en coordenadas geograficas que son las mismas en las
|
205 |
* que pide el usuario de gvSIG por lo que esta matriz en este caso se inicializa con la identidad.
|
206 |
* @return
|
207 |
*/
|
208 |
public AffineTransform getOwnTransformation() { |
209 |
return ownTransformation;
|
210 |
} |
211 |
|
212 |
} |