root / branches / v10+Piloto / libraries / libCq_CMS_praster / src / org / cresques / io / data / Grid.java @ 9604
History | View | Annotate | Download (8.75 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.cresques.io.data; |
20 |
|
21 |
import org.cresques.io.GeoRasterFile; |
22 |
import org.cresques.io.datastruct.Histogram; |
23 |
import org.cresques.io.datastruct.Statistic; |
24 |
import org.cresques.io.exceptions.FileFoundInListException; |
25 |
import org.cresques.px.Extent; |
26 |
import org.cresques.px.PxRaster; |
27 |
import org.cresques.util.Utilities; |
28 |
|
29 |
public class Grid implements IQueryableRaster, IWritableRaster { |
30 |
|
31 |
private GeoRasterMultiFile grmf = new GeoRasterMultiFile(null); |
32 |
private RasterBuf rasterBuf = null; |
33 |
private Histogram histogram = null; |
34 |
private PxRaster pxRaster = null; |
35 |
private Statistic stats = null; |
36 |
private int width = 0; |
37 |
private int height = 0; |
38 |
|
39 |
private double m_dNoDataValue = -99999; //TODO:temporal |
40 |
|
41 |
/**
|
42 |
* Constructor
|
43 |
*/
|
44 |
public Grid(){}
|
45 |
|
46 |
/**
|
47 |
* Constructor
|
48 |
* @param grf Lista de geoRasterFile
|
49 |
*/
|
50 |
public Grid(GeoRasterFile[] grf){ |
51 |
for(int i = 0; i< grf.length; i++) |
52 |
addFile(grf[i]); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* Constructor
|
57 |
* @param grf GeoRasterFile
|
58 |
*/
|
59 |
public Grid(GeoRasterFile grf){
|
60 |
addFile(grf); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Asigna el renderizador para el calculo de histogramas a partir
|
65 |
* de la visualizaci?n.
|
66 |
* @param pxR Renderizador.
|
67 |
*/
|
68 |
public void addRenderizer(PxRaster pxR){ |
69 |
this.pxRaster = pxR;
|
70 |
this.stats = pxR.stats;
|
71 |
this.getHistogram().addRenderizer(pxR);
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* A?ade un GeoRasterFile al Grid
|
76 |
* @param grf GeoRasterFile a a?adir
|
77 |
*/
|
78 |
public void addFile(GeoRasterFile grf){ |
79 |
try{
|
80 |
grmf.addFile(grf); |
81 |
width = grf.getWidth(); |
82 |
height = grf.getHeight(); |
83 |
}catch(FileFoundInListException e){
|
84 |
//El fichero est? en la lista por lo que no lo a?adimos
|
85 |
} |
86 |
} |
87 |
|
88 |
/**
|
89 |
* Elimina un GeoRasterFile del Grid
|
90 |
* @param grf GeoRasterFile a eliminar
|
91 |
*/
|
92 |
public void removeFile(GeoRasterFile grf){ |
93 |
grmf.removeFile(grf); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Obtiene la estructura que contiene la lista de ficheros del Grid
|
98 |
* @return GeoRasterMultiFile
|
99 |
*/
|
100 |
public GeoRasterMultiFile getGeoRasterMultiFile(){
|
101 |
return grmf;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Libera el buffer de memoria
|
106 |
*/
|
107 |
public void free(){ |
108 |
rasterBuf = null;
|
109 |
System.gc();
|
110 |
} |
111 |
|
112 |
/**
|
113 |
* Resetea la asignaci?n de dibujado de las bandas de la imagen
|
114 |
* sobre el DataImage cuando se hace un update para esta banda.
|
115 |
*/
|
116 |
public void clearDrawableBand(){ |
117 |
for(int i = 0; i< grmf.getFileCount(); i++) |
118 |
grmf.getBands().clearDrawableBand(); |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Para este GeoRasterFile asigna que bandas se pintaran
|
123 |
* sobre el RasterBuf cuando se haga un update. Cada posici?n del vector es una banda
|
124 |
* del rasterBuf y el contenido de esa posici?n es la banda de la imagen que se dibujar?
|
125 |
* sobre ese RasterBuf.
|
126 |
* @param drawableBands .
|
127 |
*/
|
128 |
public void addDrawableBands(int[] drawableBands){ |
129 |
for(int i = 0; i< drawableBands.length; i++) |
130 |
grmf.getBands().addDrawableBand(i, drawableBands[i]); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Asigna el ?rea de interes en coordenadas del mundo real. Si las coordenadas exceden del tama?o de la imagen
|
135 |
* estas coordenadas son ajustadas el extent.
|
136 |
* @param x Coordenada X, esquina superior izquierda
|
137 |
* @param y Coordenada Y, esquina superior izquierda
|
138 |
* @param w Ancho del ?rea
|
139 |
* @param h Alto del ?rea
|
140 |
* @throws ArrayIndexOutOfBoundsException
|
141 |
*/
|
142 |
public void setAreaOfInterest(double x, double y, double w, double h) throws ArrayIndexOutOfBoundsException{ |
143 |
Extent ext = new Extent(x, y, x + w, y + h);
|
144 |
ext = Utilities.calculateAdjustedView(ext, grmf.getExtent());
|
145 |
|
146 |
rasterBuf = grmf.getWindowRaster(x, y, w, h); |
147 |
//width = rasterBuf.getWidth();
|
148 |
//height = rasterBuf.getHeight();
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* Asigna el ?rea de interes en coordenadas pixel. Si las coordenadas exceden del tama?o de la imagen
|
153 |
* lanza una excepci?n.
|
154 |
* @param x Coordenada X, esquina superior izquierda
|
155 |
* @param y Coordenada Y, esquina superior izquierda
|
156 |
* @param w Ancho del ?rea
|
157 |
* @param h Alto del ?rea
|
158 |
* @throws ArrayIndexOutOfBoundsException
|
159 |
*/
|
160 |
public void setAreaOfInterest(int x, int y, int w, int h) throws ArrayIndexOutOfBoundsException{ |
161 |
if((x + w) > getWidth() || (y + h) > getHeight())
|
162 |
throw new ArrayIndexOutOfBoundsException("Out of Image"); |
163 |
|
164 |
rasterBuf = grmf.getWindowRaster(x, y, w, h); |
165 |
//width = rasterBuf.getWidth();
|
166 |
//height = rasterBuf.getHeight();
|
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAreaOfInterest(double, double, double, double, int, int)
|
172 |
*/
|
173 |
public int[] setAreaOfInterest(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight) throws ArrayIndexOutOfBoundsException{ |
174 |
//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada
|
175 |
Extent dataExtent = new Extent(minX, minY, maxX, maxY);
|
176 |
dataExtent = Utilities.calculateAdjustedView(dataExtent, grmf.getExtent());
|
177 |
|
178 |
rasterBuf = grmf.getWindowRaster(minX, minY, maxX, maxY, bufWidth, bufHeight); |
179 |
return null; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Ajusta el ?rea del grid a un ancho y un alto dado en pixeles. Este ajuste se har?
|
184 |
* en relaci?n a un m?todo de interpolaci?n definido en el par?metro.
|
185 |
* @param w Ancho de la nueva imagen.
|
186 |
* @param h Alto de la nueva imagen.
|
187 |
* @param interpolation M?todo de interpolaci?n que se usar? en el ajuste.
|
188 |
* @param bands Bandas que se desea en el nuevo RasterBuf ajustado. Si este par?metro es null
|
189 |
* se usar?n todas las bandas de la imagen.
|
190 |
*/
|
191 |
public void setAdjustedWindow(int w, int h, int interpolationMethod, int[] bands){ |
192 |
if(w == width && h == height)
|
193 |
return;
|
194 |
switch(interpolationMethod){
|
195 |
case IQueryableRaster.INTERPOLATION_NearestNeighbour:
|
196 |
rasterBuf = rasterBuf.adjustRasterNearestNeighbour(w, h, bands); |
197 |
break;
|
198 |
case IQueryableRaster.INTERPOLATION_Bilinear:
|
199 |
System.out.println("Method not implemented yet"); |
200 |
break;
|
201 |
case IQueryableRaster.INTERPOLATION_InverseDistance:
|
202 |
System.out.println("Method not implemented yet"); |
203 |
break;
|
204 |
case IQueryableRaster.INTERPOLATION_BicubicSpline:
|
205 |
System.out.println("Method not implemented yet"); |
206 |
break;
|
207 |
case IQueryableRaster.INTERPOLATION_BSpline:
|
208 |
System.out.println("Method not implemented yet"); |
209 |
break;
|
210 |
} |
211 |
//width = rasterBuf.getWidth();
|
212 |
//height = rasterBuf.getHeight();
|
213 |
} |
214 |
|
215 |
public RasterBuf getData(int x, int y, int w, int h) { |
216 |
|
217 |
return null; |
218 |
} |
219 |
|
220 |
/**
|
221 |
* Obtiene el tipo de datos del grid.
|
222 |
* @return entero que representa el tipo de dato de las celdas del grid.
|
223 |
*/
|
224 |
public int getDataType() { |
225 |
return grmf.getDataType()[0]; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* Obtiene la altura del grid.
|
230 |
* @return altura en celdas del grid.
|
231 |
*/
|
232 |
public int getHeight() { |
233 |
return height;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Obtiene la anchura del grid.
|
238 |
* @return anchura en celdas del grid.
|
239 |
*/
|
240 |
public int getWidth() { |
241 |
return width;
|
242 |
} |
243 |
|
244 |
public double getXCellSize() { |
245 |
|
246 |
//TODO:remove this
|
247 |
Extent e = grmf.getExtent(); |
248 |
double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / (double) width; |
249 |
|
250 |
return dCellsize;
|
251 |
|
252 |
} |
253 |
|
254 |
public double getYCellSize() { |
255 |
|
256 |
return 0; |
257 |
} |
258 |
|
259 |
public boolean isNoData(int x, int y, int band) { |
260 |
|
261 |
return false; |
262 |
|
263 |
} |
264 |
|
265 |
public void setNoDataValue(double dNoDataValue){ |
266 |
|
267 |
//TODO:temporal
|
268 |
m_dNoDataValue = dNoDataValue; |
269 |
} |
270 |
|
271 |
public double getNoDataValue(){ |
272 |
|
273 |
return m_dNoDataValue;
|
274 |
|
275 |
} |
276 |
|
277 |
public void setDataType(int dt) { |
278 |
|
279 |
} |
280 |
|
281 |
public int getBandCount(){ |
282 |
if(rasterBuf != null) |
283 |
return rasterBuf.getBandCount();
|
284 |
else
|
285 |
return this.getGeoRasterMultiFile().getBandCount(); |
286 |
} |
287 |
|
288 |
/**
|
289 |
* Obtiene el buffer de datos del grid
|
290 |
* @return RasterBuf
|
291 |
*/
|
292 |
public RasterBuf getRasterBuf() {
|
293 |
return rasterBuf;
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* Obtiene el objeto histograma asociado al grid
|
298 |
* @return
|
299 |
*/
|
300 |
public Histogram getHistogram() {
|
301 |
if(histogram == null) |
302 |
histogram = new Histogram(this); |
303 |
|
304 |
return histogram;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Obtiene la clase para estadisticas
|
309 |
* @return
|
310 |
*/
|
311 |
public Statistic getStatistic() {
|
312 |
return stats;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Evalua si una coordenada pixel cae dentro de la imagen.
|
317 |
* @param x coordenada pixel X
|
318 |
* @param y coordenada pixel Y
|
319 |
*/
|
320 |
public boolean isPixelInGrid(int x, int y){ |
321 |
return (x >= 0 && y >= 0 && x <= getWidth() && y <= getHeight()); |
322 |
} |
323 |
|
324 |
/**
|
325 |
* Extent del grid
|
326 |
*/
|
327 |
public Extent getExtent(){
|
328 |
return grmf.getExtent();
|
329 |
} |
330 |
} |
331 |
|