root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / Grid.java @ 18040
History | View | Annotate | Download (36.5 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.grid; |
20 |
|
21 |
import java.awt.image.DataBuffer; |
22 |
import java.io.IOException; |
23 |
import java.util.Arrays; |
24 |
|
25 |
import org.gvsig.raster.buffer.BufferFactory; |
26 |
import org.gvsig.raster.buffer.RasterBuffer; |
27 |
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException; |
28 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
29 |
import org.gvsig.raster.dataset.IBuffer; |
30 |
import org.gvsig.raster.dataset.IRasterDataSource; |
31 |
import org.gvsig.raster.datastruct.Extent; |
32 |
import org.gvsig.raster.datastruct.Transparency; |
33 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
34 |
|
35 |
/**
|
36 |
* Clase que representa una rejilla de datos raster. Este tipo de grid tiene el interfaz necesario
|
37 |
* de acceso a la informaci?n raster para aplicaciones de analisis raster. Contiene m?todos de acceso al
|
38 |
* dato tanto en lectura como en escritura y encapsula operaciones entre grids. Adem?s contiene
|
39 |
* objetos que contienen las caracter?sticas asociadas a ese grid. Sobre un grid pueden
|
40 |
* aplicarse tambi?n operaciones de filtrado.
|
41 |
*
|
42 |
* Podemos crear un Grid de cinco formas distitas:
|
43 |
* <UL>
|
44 |
* <LI>A partir de una fuente de datos (cargada en el constructor). Se har? una petici?n del extent pasado por par?metro con las bandas seleccionadas por par?metro.</LI>
|
45 |
* <LI>A partir de un extensi?n de capa, una extensi?n de vista, un tipo de dato y un n?mero de datos
|
46 |
* crea un Grid vacio util para escritura.</LI>
|
47 |
* <LI>A partir de una fuente de datos (cargados). Datasource se usa como buffer de datos cargados y se selecciona si queremos el reader interpolado.</LI>
|
48 |
* <LI>A partir de una fuente de datos (cargada en el constructor). Se har? una petici?n del extent completo de la fuente con las bandas seleccionadas por par?metro.</LI>
|
49 |
* <LI>A partir de una fuente de datos (cargada en el constructor). Se har? una petici?n del extent completo de la fuente con todas las bandas disponibles.</LI>
|
50 |
* </UL>
|
51 |
*
|
52 |
* @author Victor Olaya (volaya@ya.com)
|
53 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
54 |
*/
|
55 |
public class Grid implements IQueryableGrid, IWritableGrid{ |
56 |
|
57 |
//TODO: ARQUITECTURA: Estos tipos de datos no deben ser necesarios. Existiendo IBuffer se tendr?an que usar esos Hay que convertir, antes de eliminarlos, el uso de estos a los de IBuffer
|
58 |
public static final int RASTER_DATA_TYPE_FLOAT = DataBuffer.TYPE_FLOAT; |
59 |
public static final int RASTER_DATA_TYPE_DOUBLE = DataBuffer.TYPE_DOUBLE; |
60 |
public static final int RASTER_DATA_TYPE_INT = DataBuffer.TYPE_INT; |
61 |
public static final int RASTER_DATA_TYPE_SHORT = DataBuffer.TYPE_SHORT; |
62 |
public static final int RASTER_DATA_TYPE_BYTE = DataBuffer.TYPE_BYTE; |
63 |
|
64 |
public final static double DEG_45_IN_RAD = Math.PI / 180. * 45.; |
65 |
public final static double DEG_90_IN_RAD = Math.PI / 180. * 90.; |
66 |
public final static double DEG_180_IN_RAD = Math.PI ; |
67 |
public final static double DEG_270_IN_RAD = Math.PI / 180. * 270.; |
68 |
public final static double DEG_360_IN_RAD = Math.PI * 2.; |
69 |
|
70 |
/* neighbor's address*/ /* N NE E SE S SW W NW */ |
71 |
private final static int m_iOffsetX []= { 0, 1, 1, 1, 0, -1, -1, -1}; |
72 |
private final static int m_iOffsetY []= { 1, 1, 0, -1, -1, -1, 0, 1}; |
73 |
|
74 |
private double m_dDist[]; |
75 |
public double _2DX, _6DX, _DX_2, _4DX_2; |
76 |
|
77 |
private int[] bands = null; |
78 |
private int dataType = IBuffer.TYPE_UNDEFINED; |
79 |
|
80 |
private RasterBuffer rasterBuf = null; |
81 |
private GridReader reader = null; |
82 |
private GridWriter writer = null; |
83 |
private GridExtent windowExtent = null; |
84 |
private GridExtent layerExtent = null; |
85 |
private GridStatistic statistic = null; |
86 |
private GridPalette[] palette = null; |
87 |
private RasterFilterList filterList = null; |
88 |
|
89 |
|
90 |
|
91 |
/**
|
92 |
* Crea un grid a partir de un MultiRasterDataset. Usa el extent de la fuente de datos como
|
93 |
* extent completo y el extent pasado como par?metro como extensi?n de ventana.
|
94 |
*
|
95 |
* Cuando se construye el reader se carga el buffer con la extensi?n definida en windowExtent
|
96 |
* y las bandas especificadas en bands.
|
97 |
*
|
98 |
* @param IRasterDataSource datasets que proporcionan los datos
|
99 |
* @param bands n?mero de bandas requeridas
|
100 |
* @param windowExtent Extensi?n de la ventana. Si este par?metro es null se usar? el
|
101 |
* mismo que el de la capa.
|
102 |
*/
|
103 |
public Grid(IRasterDataSource datasets, int[] bands, GridExtent windowExtent) |
104 |
throws RasterBufferInvalidException{
|
105 |
BufferFactory bufferFactory = new BufferFactory(datasets);
|
106 |
layerExtent = new GridExtent( bufferFactory.getDataSource().getExtent(),
|
107 |
calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth())); |
108 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
109 |
dataType = bufferFactory.getDataSource().getDataType()[0];
|
110 |
this.bands = bands;
|
111 |
|
112 |
if(windowExtent == null) |
113 |
this.windowExtent = layerExtent;
|
114 |
else
|
115 |
this.windowExtent = windowExtent;
|
116 |
|
117 |
rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf(); |
118 |
|
119 |
if (windowExtent.fitsIn(layerExtent))
|
120 |
reader = new GridNotInterpolated(bufferFactory, layerExtent, windowExtent, bands);
|
121 |
else
|
122 |
reader = new GridInterpolated(bufferFactory, layerExtent, windowExtent, bands);
|
123 |
writer = new GridWriter(layerExtent, dataType, rasterBuf);
|
124 |
|
125 |
init(bufferFactory); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Crea un grid vacio a partir de un extent y un tipo de datos. Se crea un buffer vacio en el
|
130 |
* que puede escribirse a trav?s del writer. Los datos escritos pueden ser consultados con el
|
131 |
* reader. No tiene una fuente de datos asociada ya que es un grid vacio basicamente para
|
132 |
* escritura.
|
133 |
* @param layerExtent Tama?o completo de la capa
|
134 |
* @param windowExtent Ventana de datos.
|
135 |
* @param dataType Tipo de datos del buffer
|
136 |
* @param bands n?mero de bandas requeridas y orden de dibujado en el buffer
|
137 |
*/
|
138 |
public Grid(GridExtent layerExtent,
|
139 |
GridExtent windowExtent, |
140 |
int dataType,
|
141 |
int[] bands) throws RasterBufferInvalidException{ |
142 |
this.windowExtent = windowExtent;
|
143 |
this.layerExtent = layerExtent;
|
144 |
this.dataType = dataType;
|
145 |
|
146 |
rasterBuf = RasterBuffer.getBuffer(dataType, layerExtent.getNX(), layerExtent.getNY(), bands.length, true);
|
147 |
|
148 |
if (windowExtent.fitsIn(layerExtent))
|
149 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
150 |
else
|
151 |
reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
152 |
writer = new GridWriter(layerExtent, dataType, rasterBuf);
|
153 |
init(null);
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Crea un grid a partir de un BufferFactory. El buffer debe estar cargado de datos y el extent
|
158 |
* de este viene definido en el par?metro windowExtent.
|
159 |
* @param bufferFactory Fuente de datos
|
160 |
* @param windowExtent Extent de los datos cargados en bufferFactory
|
161 |
* @param notInterp Si es true fuerza a que el reader sea sin interpolaci?n. Si es false decide si
|
162 |
* el reader es interpolado o no a partir de los extents de capa y la ventana seleccionada.
|
163 |
*/
|
164 |
public Grid(BufferFactory bufferFactory, boolean notInterp) { |
165 |
this.layerExtent = new GridExtent( bufferFactory.getDataSource().getExtent(), |
166 |
calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth())); |
167 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
168 |
dataType = bufferFactory.getDataSource().getDataType()[0];
|
169 |
bands = bufferFactory.getDrawableBands(); |
170 |
|
171 |
this.windowExtent = new GridExtent( bufferFactory.getDataExtent(), |
172 |
calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth())); |
173 |
|
174 |
rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf(); |
175 |
|
176 |
if(notInterp) {
|
177 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
178 |
} else {
|
179 |
if (windowExtent.fitsIn(layerExtent))
|
180 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
181 |
else
|
182 |
reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
183 |
} |
184 |
writer = new GridWriter(layerExtent, dataType, rasterBuf);
|
185 |
init(bufferFactory); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Crea un grid a partir de un BufferFactory. Se har? una petici?n del extent completo de la fuente.
|
190 |
* bufferFactory tiene asociada una fuente de datos pero se ignorar? si tiene el buffer lleno. La instanciaci?n
|
191 |
* de GridNotInterpolated har? que se haga la petici?n para cargar raster completo.
|
192 |
* @param bufferFactory Fuente de datos
|
193 |
* @param bands n?mero de bandas requeridas y orden de dibujado en el buffer
|
194 |
*/
|
195 |
public Grid(BufferFactory bufferFactory, int[] bands) |
196 |
throws RasterBufferInvalidException{
|
197 |
//La petici?n es del raster completo
|
198 |
windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(),
|
199 |
calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth())); |
200 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
201 |
dataType = bufferFactory.getDataSource().getDataType()[0];
|
202 |
this.bands = bands;
|
203 |
|
204 |
reader = new GridNotInterpolated(bufferFactory, layerExtent, windowExtent, bands);
|
205 |
rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf(); |
206 |
writer = new GridWriter(windowExtent, dataType, rasterBuf);
|
207 |
|
208 |
init(bufferFactory); |
209 |
} |
210 |
|
211 |
/**
|
212 |
* Crea un grid a partir de un BufferFactory. Se har? una petici?n del extent completo de la fuente.
|
213 |
* bufferFactory tiene asociada una fuente de datos pero se ignorar? si tiene el buffer lleno. La instanciaci?n
|
214 |
* de GridNotInterpolated har? que se haga la petici?n para cargar raster completo. El buffer se cargar?
|
215 |
* con todas las bandas disponibles.
|
216 |
* @param bufferFactory Fuente de datos
|
217 |
*/
|
218 |
public Grid(BufferFactory bufferFactory) throws RasterBufferInvalidException { |
219 |
//La petici?n es del raster completo
|
220 |
windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(),
|
221 |
calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth())); |
222 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
223 |
dataType = bufferFactory.getDataSource().getDataType()[0];
|
224 |
|
225 |
bands = new int[bufferFactory.getBandCount()]; |
226 |
for(int i = 0; i < bufferFactory.getBandCount(); i ++) |
227 |
bands[i] = i; |
228 |
reader = new GridNotInterpolated(bufferFactory, layerExtent, windowExtent, bands);
|
229 |
rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf(); |
230 |
writer = new GridWriter(windowExtent, dataType, rasterBuf);
|
231 |
|
232 |
init(bufferFactory); |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Calcula el tama?o de celda a partir de un dataset y un ancho en pixeles
|
237 |
* @return
|
238 |
*/
|
239 |
private double calcCellSize(IRasterDataSource mDataset, double w) { |
240 |
try {
|
241 |
Extent e = mDataset.getExtent(); |
242 |
double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / w;
|
243 |
return dCellsize;
|
244 |
} catch (NullPointerException e) { |
245 |
return 1; |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Selecciona la forma de obtener datos con o sin interpolaci?n. Si pasamos el par?metro
|
251 |
* false al aplicar un m?todo de consulta de datos este ser? aplicado sin interpolaci?n.
|
252 |
* @param interpolation
|
253 |
*/
|
254 |
public void switchToInterpolationMethod(boolean interpolation){ |
255 |
//GridExtent layer = new GridExtent(0, 0, rasterBuf.getWidth(), rasterBuf.getHeight(), 1);
|
256 |
if(interpolation)
|
257 |
reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
258 |
else
|
259 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
|
260 |
init(null);
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* Inicializaci?n de constantes
|
265 |
*/
|
266 |
private void init(BufferFactory ds) { |
267 |
int i;
|
268 |
GridTransparency transparency = null;
|
269 |
|
270 |
double dCellSize = getCellSize();
|
271 |
|
272 |
statistic = new GridStatistic(this); |
273 |
if (ds == null) |
274 |
transparency = new GridTransparency();
|
275 |
else {
|
276 |
Transparency transp = ds.getDataSource().getTransparencyFilesStatus();
|
277 |
if (transp != null) |
278 |
transparency = new GridTransparency(transp);
|
279 |
this.palette = new GridPalette[ds.getColorTables().length]; |
280 |
for (int iPal = 0; iPal < ds.getColorTables().length; iPal++) { |
281 |
if (ds.getColorTables()[iPal] != null) |
282 |
this.palette[iPal] = new GridPalette(ds.getColorTables()[iPal]); |
283 |
} |
284 |
} |
285 |
filterList = new RasterFilterList();
|
286 |
if (ds != null) { |
287 |
filterList.addEnvParam("IStatistics", ds.getDataSource().getStatistics());
|
288 |
filterList.addEnvParam("MultiRasterDataset", ds.getDataSource());
|
289 |
} |
290 |
filterList.addEnvParam("Transparency", transparency);
|
291 |
filterList.setInitRasterBuf(rasterBuf); |
292 |
|
293 |
m_dDist = new double[8]; |
294 |
|
295 |
for (i = 0; i < 8; i++) { |
296 |
m_dDist[i] = Math.sqrt ( m_iOffsetX[i] * dCellSize * m_iOffsetX[i] * dCellSize
|
297 |
+ m_iOffsetY[i] * dCellSize * m_iOffsetY[i] * dCellSize ); |
298 |
} |
299 |
|
300 |
_2DX = dCellSize * 2.0;
|
301 |
_6DX = dCellSize * 6.0;
|
302 |
_DX_2 = dCellSize * dCellSize; |
303 |
_4DX_2 = 4.0 * _DX_2;
|
304 |
} |
305 |
|
306 |
//************* Write Services *********************
|
307 |
|
308 |
/*
|
309 |
* (non-Javadoc)
|
310 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(byte)
|
311 |
*/
|
312 |
public void assign(byte value)throws GridException { |
313 |
try {
|
314 |
writer.assign(value); |
315 |
} catch (RasterBufferInvalidAccessException e) {
|
316 |
throw new GridException("Error wrinting buffer"); |
317 |
} |
318 |
} |
319 |
|
320 |
/*
|
321 |
* (non-Javadoc)
|
322 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(short)
|
323 |
*/
|
324 |
public void assign(short value)throws GridException { |
325 |
try {
|
326 |
writer.assign(value); |
327 |
} catch (RasterBufferInvalidAccessException e) {
|
328 |
throw new GridException("Error wrinting buffer"); |
329 |
} |
330 |
} |
331 |
|
332 |
/*
|
333 |
* (non-Javadoc)
|
334 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(int)
|
335 |
*/
|
336 |
public void assign(int value)throws GridException { |
337 |
try {
|
338 |
writer.assign(value); |
339 |
} catch (RasterBufferInvalidAccessException e) {
|
340 |
throw new GridException("Error wrinting buffer"); |
341 |
} |
342 |
} |
343 |
|
344 |
/*
|
345 |
* (non-Javadoc)
|
346 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(float)
|
347 |
*/
|
348 |
public void assign(float value)throws GridException { |
349 |
try {
|
350 |
writer.assign(value); |
351 |
} catch (RasterBufferInvalidAccessException e) {
|
352 |
throw new GridException("Error wrinting buffer"); |
353 |
} |
354 |
} |
355 |
|
356 |
/*
|
357 |
* (non-Javadoc)
|
358 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(double)
|
359 |
*/
|
360 |
public void assign(double value)throws GridException { |
361 |
try {
|
362 |
writer.assign(value); |
363 |
} catch (RasterBufferInvalidAccessException e) {
|
364 |
throw new GridException("Error wrinting buffer"); |
365 |
} |
366 |
} |
367 |
|
368 |
/*
|
369 |
* (non-Javadoc)
|
370 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(org.gvsig.fmap.dataaccess.BufferFactory)
|
371 |
*/
|
372 |
public void assign(BufferFactory bufferFactory) throws GridException { |
373 |
Grid window; |
374 |
try {
|
375 |
window = new Grid(bufferFactory.getDataSource(), bands, windowExtent);
|
376 |
write(window); |
377 |
writer.setNoDataValue(window.getNoDataValue()); |
378 |
} catch (RasterBufferInvalidException e) {
|
379 |
throw new GridException("Error writing buffer"); |
380 |
} |
381 |
} |
382 |
|
383 |
/*
|
384 |
* (non-Javadoc)
|
385 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(org.gvsig.fmap.grid.Grid)
|
386 |
*/
|
387 |
public void assign(Grid driver) throws GridException { |
388 |
if (driver.getGridExtent().equals(layerExtent)){
|
389 |
write(driver); |
390 |
writer.setNoDataValue(driver.getNoDataValue()); |
391 |
} |
392 |
} |
393 |
|
394 |
/**
|
395 |
* Sobreescribe los datos del grid actual con los datos del grid pasado por par?metro
|
396 |
* @param g Grid desde donde se obtienen los datos
|
397 |
*/
|
398 |
private void write(Grid g) throws GridException { |
399 |
try{
|
400 |
switch(rasterBuf.getDataType()){
|
401 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) { |
402 |
for (int y = 0; y < g.getNY(); y++) { |
403 |
writer.setCellValue(x, y, g.getCellValueAsByte(x, y)); |
404 |
} |
405 |
} |
406 |
break;
|
407 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) { |
408 |
for (int y = 0; y < g.getNY(); y++) { |
409 |
writer.setCellValue(x, y, g.getCellValueAsShort(x, y)); |
410 |
} |
411 |
} |
412 |
break;
|
413 |
case IBuffer.TYPE_INT: for (int x = 0; x < g.getNX(); x++) { |
414 |
for (int y = 0; y < g.getNY(); y++) { |
415 |
writer.setCellValue(x, y, g.getCellValueAsInt(x, y)); |
416 |
} |
417 |
} |
418 |
break;
|
419 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) { |
420 |
for (int y = 0; y < g.getNY(); y++) { |
421 |
writer.setCellValue(x, y, g.getCellValueAsFloat(x, y)); |
422 |
} |
423 |
} |
424 |
break;
|
425 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) { |
426 |
for (int y = 0; y < g.getNY(); y++) { |
427 |
writer.setCellValue(x, y, g.getCellValueAsDouble(x, y)); |
428 |
} |
429 |
} |
430 |
break;
|
431 |
} |
432 |
} catch (OutOfGridException e) {
|
433 |
throw new GridException(""); |
434 |
} |
435 |
} |
436 |
|
437 |
/*
|
438 |
* (non-Javadoc)
|
439 |
* @see org.gvsig.fmap.grid.IWritableGrid#assignNoData()
|
440 |
*/
|
441 |
public void assignNoData(){ |
442 |
try {
|
443 |
switch(rasterBuf.getDataType()){
|
444 |
case IBuffer.TYPE_BYTE: writer.assign((byte)rasterBuf.getNoDataValue());break; |
445 |
case IBuffer.TYPE_SHORT: writer.assign((short)rasterBuf.getNoDataValue());break; |
446 |
case IBuffer.TYPE_INT: writer.assign((int)rasterBuf.getNoDataValue());break; |
447 |
case IBuffer.TYPE_FLOAT: writer.assign((float)rasterBuf.getNoDataValue());break; |
448 |
case IBuffer.TYPE_DOUBLE: writer.assign((double)rasterBuf.getNoDataValue());break; |
449 |
} |
450 |
} catch (RasterBufferInvalidAccessException e) {
|
451 |
//No hacemos nada. El tipo de dato al que se accede no es controlado por el usuario por lo
|
452 |
//que no le mandamos la excepci?n hacia arriba.
|
453 |
e.printStackTrace(); |
454 |
} |
455 |
} |
456 |
|
457 |
/*
|
458 |
* (non-Javadoc)
|
459 |
* @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, byte)
|
460 |
*/
|
461 |
public void setCellValue(int x, int y, byte value)throws OutOfGridException{ |
462 |
writer.setCellValue(x, y, value); |
463 |
} |
464 |
|
465 |
/*
|
466 |
* (non-Javadoc)
|
467 |
* @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, short)
|
468 |
*/
|
469 |
public void setCellValue(int x, int y, short value)throws OutOfGridException{ |
470 |
writer.setCellValue(x, y, value); |
471 |
} |
472 |
|
473 |
/*
|
474 |
* (non-Javadoc)
|
475 |
* @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, int)
|
476 |
*/
|
477 |
public void setCellValue(int x, int y, int value)throws OutOfGridException{ |
478 |
writer.setCellValue(x, y, value); |
479 |
} |
480 |
|
481 |
/*
|
482 |
* (non-Javadoc)
|
483 |
* @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, float)
|
484 |
*/
|
485 |
public void setCellValue(int x, int y, float value)throws OutOfGridException{ |
486 |
writer.setCellValue(x, y, value); |
487 |
} |
488 |
|
489 |
/*
|
490 |
* (non-Javadoc)
|
491 |
* @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, double)
|
492 |
*/
|
493 |
public void setCellValue(int x, int y, double value)throws OutOfGridException{ |
494 |
writer.setCellValue(x, y, value); |
495 |
} |
496 |
|
497 |
/*
|
498 |
* (non-Javadoc)
|
499 |
* @see org.gvsig.fmap.grid.IWritableGrid#add(org.gvsig.fmap.grid.Grid)
|
500 |
*/
|
501 |
public void add(Grid g) throws GridException { |
502 |
if (g.getGridExtent().equals(getGridExtent())) {
|
503 |
boolean interp = (reader instanceof GridInterpolated); |
504 |
switchToInterpolationMethod(false);
|
505 |
try{
|
506 |
switch(rasterBuf.getDataType()){
|
507 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) { |
508 |
for (int y = 0; y < g.getNY(); y++) { |
509 |
writer.setCellValue(x, y, reader.getCellValueAsByte(x, y) + g.getCellValueAsByte(x,y)); |
510 |
} |
511 |
} |
512 |
break;
|
513 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) { |
514 |
for (int y = 0; y < g.getNY(); y++) { |
515 |
writer.setCellValue(x, y, reader.getCellValueAsShort(x, y) + g.getCellValueAsShort(x,y)); |
516 |
} |
517 |
} |
518 |
break;
|
519 |
case IBuffer.TYPE_INT: for (int x = 0; x < g.getNX(); x++) { |
520 |
for (int y = 0; y < g.getNY(); y++) { |
521 |
writer.setCellValue(x, y, reader.getCellValueAsInt(x, y) + g.getCellValueAsInt(x,y)); |
522 |
} |
523 |
} |
524 |
break;
|
525 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) { |
526 |
for (int y = 0; y < g.getNY(); y++) { |
527 |
writer.setCellValue(x, y, reader.getCellValueAsFloat(x, y) + g.getCellValueAsFloat(x,y)); |
528 |
} |
529 |
} |
530 |
break;
|
531 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) { |
532 |
for (int y = 0; y < g.getNY(); y++) { |
533 |
writer.setCellValue(x, y, reader.getCellValueAsDouble(x, y) + g.getCellValueAsDouble(x,y)); |
534 |
} |
535 |
} |
536 |
break;
|
537 |
} |
538 |
} catch (OutOfGridException e) {
|
539 |
throw new GridException(""); |
540 |
} catch (RasterBufferInvalidAccessException e1) {
|
541 |
throw new GridException(""); |
542 |
} catch (RasterBufferInvalidException e) {
|
543 |
throw new GridException(""); |
544 |
} |
545 |
switchToInterpolationMethod(interp); |
546 |
} |
547 |
} |
548 |
|
549 |
/*
|
550 |
* (non-Javadoc)
|
551 |
* @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, byte)
|
552 |
*/
|
553 |
public void addToCellValue(int x, int y, byte value) |
554 |
throws GridException {
|
555 |
try {
|
556 |
writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y) + value));
|
557 |
} catch (OutOfGridException e) {
|
558 |
throw new GridException(""); |
559 |
} catch (RasterBufferInvalidAccessException e) {
|
560 |
throw new GridException(""); |
561 |
} catch (RasterBufferInvalidException e) {
|
562 |
throw new GridException(""); |
563 |
} |
564 |
} |
565 |
|
566 |
/*
|
567 |
* (non-Javadoc)
|
568 |
* @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, short)
|
569 |
*/
|
570 |
public void addToCellValue(int x, int y, short value) |
571 |
throws GridException {
|
572 |
try {
|
573 |
writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y) + value));
|
574 |
} catch (OutOfGridException e) {
|
575 |
throw new GridException(""); |
576 |
} catch (RasterBufferInvalidAccessException e) {
|
577 |
throw new GridException(""); |
578 |
} catch (RasterBufferInvalidException e) {
|
579 |
throw new GridException(""); |
580 |
} |
581 |
} |
582 |
|
583 |
/*
|
584 |
* (non-Javadoc)
|
585 |
* @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, int)
|
586 |
*/
|
587 |
public void addToCellValue(int x, int y, int value) |
588 |
throws GridException {
|
589 |
try {
|
590 |
writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) + value));
|
591 |
} catch (OutOfGridException e) {
|
592 |
throw new GridException(""); |
593 |
} catch (RasterBufferInvalidAccessException e) {
|
594 |
throw new GridException(""); |
595 |
} catch (RasterBufferInvalidException e) {
|
596 |
throw new GridException(""); |
597 |
} |
598 |
} |
599 |
|
600 |
/*
|
601 |
* (non-Javadoc)
|
602 |
* @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, float)
|
603 |
*/
|
604 |
public void addToCellValue(int x, int y, float value) |
605 |
throws GridException {
|
606 |
try {
|
607 |
writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) + value));
|
608 |
} catch (OutOfGridException e) {
|
609 |
throw new GridException(""); |
610 |
} catch (RasterBufferInvalidAccessException e) {
|
611 |
throw new GridException(""); |
612 |
} catch (RasterBufferInvalidException e) {
|
613 |
throw new GridException(""); |
614 |
} |
615 |
} |
616 |
|
617 |
/*
|
618 |
* (non-Javadoc)
|
619 |
* @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, double)
|
620 |
*/
|
621 |
public void addToCellValue(int x, int y, double value) |
622 |
throws GridException {
|
623 |
try {
|
624 |
writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y) + value));
|
625 |
} catch (OutOfGridException e) {
|
626 |
throw new GridException(""); |
627 |
} catch (RasterBufferInvalidAccessException e) {
|
628 |
throw new GridException(""); |
629 |
} catch (RasterBufferInvalidException e) {
|
630 |
throw new GridException(""); |
631 |
} |
632 |
} |
633 |
|
634 |
/*
|
635 |
* (non-Javadoc)
|
636 |
* @see org.gvsig.fmap.grid.IWritableGrid#multiply(double)
|
637 |
*/
|
638 |
public void multiply(double value) throws GridException { |
639 |
boolean interp = (reader instanceof GridInterpolated); |
640 |
switchToInterpolationMethod(false);
|
641 |
try{
|
642 |
switch(rasterBuf.getDataType()){
|
643 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < getNX(); x++){ |
644 |
for (int y = 0; y < getNY(); y++) |
645 |
writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y) * value));
|
646 |
} |
647 |
break;
|
648 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < getNX(); x++){ |
649 |
for (int y = 0; y < getNY(); y++) |
650 |
writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y) * value));
|
651 |
} |
652 |
break;
|
653 |
case IBuffer.TYPE_INT: for (int x = 0; x < getNX(); x++){ |
654 |
for (int y = 0; y < getNY(); y++) |
655 |
writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) * value));
|
656 |
} |
657 |
break;
|
658 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < getNX(); x++){ |
659 |
for (int y = 0; y < getNY(); y++) |
660 |
writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) * value));
|
661 |
} |
662 |
break;
|
663 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < getNX(); x++){ |
664 |
for (int y = 0; y < getNY(); y++) |
665 |
writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y) * value));
|
666 |
} |
667 |
break;
|
668 |
} |
669 |
} catch (RasterBufferInvalidException e) {
|
670 |
throw new GridException(""); |
671 |
} catch (OutOfGridException e1) {
|
672 |
throw new GridException(""); |
673 |
} catch (RasterBufferInvalidAccessException e) {
|
674 |
throw new GridException(""); |
675 |
} |
676 |
//Restauramos el reader que hab?a
|
677 |
switchToInterpolationMethod(interp); |
678 |
} |
679 |
|
680 |
/*
|
681 |
* (non-Javadoc)
|
682 |
* @see org.gvsig.fmap.grid.IWritableGrid#setNoDataValue(double)
|
683 |
*/
|
684 |
public void setNoDataValue(double dNoDataValue){ |
685 |
writer.setNoDataValue((float) dNoDataValue);
|
686 |
} |
687 |
|
688 |
/*
|
689 |
* (non-Javadoc)
|
690 |
* @see org.gvsig.fmap.grid.IWritableGrid#setNoData(int, int)
|
691 |
*/
|
692 |
public void setNoData(int x, int y){ |
693 |
writer.setNoData(x,y); |
694 |
} |
695 |
|
696 |
public void ExportToArcViewASCIIFile(String sFilename){ |
697 |
try {
|
698 |
writer.ExportToArcViewASCIIFile(sFilename); |
699 |
} catch (NumberFormatException e) { |
700 |
e.printStackTrace(); |
701 |
} catch (IOException e) { |
702 |
e.printStackTrace(); |
703 |
} |
704 |
} |
705 |
|
706 |
//************* Query Services *********************
|
707 |
|
708 |
/*
|
709 |
* (non-Javadoc)
|
710 |
* @see org.gvsig.fmap.grid.IQueryableGrid#isNoDataValue(double)
|
711 |
*/
|
712 |
public boolean isNoDataValue(double noDataValue){ |
713 |
return (reader.getNoDataValue() == noDataValue);
|
714 |
} |
715 |
|
716 |
/*
|
717 |
* (non-Javadoc)
|
718 |
* @see org.gvsig.fmap.grid.IQueryableGrid#isInGrid(int, int)
|
719 |
*/
|
720 |
public boolean isInGrid(int x, int y){ |
721 |
return reader.isCellInGrid(x, y);
|
722 |
} |
723 |
|
724 |
/*
|
725 |
* (non-Javadoc)
|
726 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellSize()
|
727 |
*/
|
728 |
public double getCellSize() { |
729 |
return reader.getCellSize();
|
730 |
} |
731 |
|
732 |
/*
|
733 |
* (non-Javadoc)
|
734 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsByte(int, int)
|
735 |
*/
|
736 |
public byte getCellValueAsByte(int x, int y)throws GridException { |
737 |
try {
|
738 |
return reader.getCellValueAsByte(x, y);
|
739 |
} catch (RasterBufferInvalidAccessException e) {
|
740 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
741 |
} catch (RasterBufferInvalidException e) {
|
742 |
throw new GridException("Buffer not valid"); |
743 |
} |
744 |
} |
745 |
|
746 |
/*
|
747 |
* (non-Javadoc)
|
748 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsShort(int, int)
|
749 |
*/
|
750 |
public short getCellValueAsShort(int x, int y)throws GridException { |
751 |
try {
|
752 |
return (short) reader.getCellValueAsShort(x, y); |
753 |
} catch (RasterBufferInvalidAccessException e) {
|
754 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
755 |
} catch (RasterBufferInvalidException e) {
|
756 |
throw new GridException("Buffer not valid"); |
757 |
} |
758 |
} |
759 |
|
760 |
/*
|
761 |
* (non-Javadoc)
|
762 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsInt(int, int)
|
763 |
*/
|
764 |
public int getCellValueAsInt(int x, int y)throws GridException { |
765 |
try {
|
766 |
return (int) reader.getCellValueAsInt(x, y); |
767 |
} catch (RasterBufferInvalidAccessException e) {
|
768 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
769 |
} catch (RasterBufferInvalidException e) {
|
770 |
throw new GridException("Buffer not valid"); |
771 |
} |
772 |
} |
773 |
|
774 |
/*
|
775 |
* (non-Javadoc)
|
776 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsFloat(int, int)
|
777 |
*/
|
778 |
public float getCellValueAsFloat(int x, int y)throws GridException { |
779 |
try {
|
780 |
return reader.getCellValueAsFloat(x, y);
|
781 |
} catch (RasterBufferInvalidAccessException e) {
|
782 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
783 |
} catch (RasterBufferInvalidException e) {
|
784 |
throw new GridException("Buffer not valid"); |
785 |
} |
786 |
} |
787 |
|
788 |
/*
|
789 |
* (non-Javadoc)
|
790 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsDouble(int, int)
|
791 |
*/
|
792 |
public double getCellValueAsDouble(int x, int y)throws GridException { |
793 |
try {
|
794 |
return (double) reader.getCellValueAsDouble(x, y); |
795 |
} catch (RasterBufferInvalidAccessException e) {
|
796 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
797 |
} catch (RasterBufferInvalidException e) {
|
798 |
throw new GridException("Buffer not valid"); |
799 |
} |
800 |
} |
801 |
|
802 |
/*
|
803 |
* (non-Javadoc)
|
804 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getNoDataValue()
|
805 |
*/
|
806 |
public double getNoDataValue() { |
807 |
return (double) rasterBuf.getNoDataValue(); |
808 |
} |
809 |
|
810 |
/*
|
811 |
* (non-Javadoc)
|
812 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getMinValue()
|
813 |
*/
|
814 |
public double getMinValue() throws GridException { |
815 |
if (!statistic.isStatisticsCalculated())
|
816 |
statistic.calculateStatistics(); |
817 |
return statistic.getMin();
|
818 |
} |
819 |
|
820 |
/*
|
821 |
* (non-Javadoc)
|
822 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getMaxValue()
|
823 |
*/
|
824 |
public double getMaxValue() throws GridException { |
825 |
if (!statistic.isStatisticsCalculated())
|
826 |
statistic.calculateStatistics(); |
827 |
return statistic.getMax();
|
828 |
} |
829 |
|
830 |
/*
|
831 |
* (non-Javadoc)
|
832 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getMeanValue()
|
833 |
*/
|
834 |
public double getMeanValue() throws GridException { |
835 |
if (!statistic.isStatisticsCalculated())
|
836 |
statistic.calculateStatistics(); |
837 |
return statistic.getMean();
|
838 |
} |
839 |
|
840 |
/*
|
841 |
* (non-Javadoc)
|
842 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getVariance()
|
843 |
*/
|
844 |
public double getVariance() throws GridException { |
845 |
if (!statistic.isStatisticsCalculated())
|
846 |
statistic.calculateStatistics(); |
847 |
return statistic.getVariance();
|
848 |
} |
849 |
|
850 |
/*
|
851 |
* (non-Javadoc)
|
852 |
* @see org.gvsig.fmap.grid.IQueryableGrid#setInterpolationMethod(int)
|
853 |
*/
|
854 |
public void setInterpolationMethod(int iMethod){ |
855 |
if (reader instanceof GridInterpolated) |
856 |
((GridInterpolated) reader).setInterpolationMethod(iMethod); |
857 |
else{
|
858 |
this.switchToInterpolationMethod(true); |
859 |
((GridInterpolated) reader).setInterpolationMethod(iMethod); |
860 |
} |
861 |
} |
862 |
|
863 |
/*
|
864 |
* (non-Javadoc)
|
865 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getNX()
|
866 |
*/
|
867 |
public int getNX(){ |
868 |
return reader.getNX();
|
869 |
} |
870 |
|
871 |
/*
|
872 |
* (non-Javadoc)
|
873 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getNY()
|
874 |
*/
|
875 |
public int getNY(){ |
876 |
return reader.getNY();
|
877 |
} |
878 |
|
879 |
/*
|
880 |
* (non-Javadoc)
|
881 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getLayerNX()
|
882 |
*/
|
883 |
public int getLayerNX(){ |
884 |
return layerExtent.getNX();
|
885 |
} |
886 |
|
887 |
/*
|
888 |
* (non-Javadoc)
|
889 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getLayerNY()
|
890 |
*/
|
891 |
public int getLayerNY(){ |
892 |
return layerExtent.getNY();
|
893 |
} |
894 |
|
895 |
/*
|
896 |
* (non-Javadoc)
|
897 |
* @see org.gvsig.fmap.grid.IWritableGrid#getGridExtent()
|
898 |
*/
|
899 |
/*public GridExtent getGridExtent(){
|
900 |
return windowExtent;
|
901 |
}*/
|
902 |
|
903 |
public int getDataType(){ |
904 |
return dataType;
|
905 |
} |
906 |
|
907 |
private boolean getSubMatrix3x3(int x, int y, double SubMatrix[]) |
908 |
throws GridException {
|
909 |
int i;
|
910 |
int iDir;
|
911 |
double z, z2;
|
912 |
|
913 |
z = getCellValueAsDouble(x, y); |
914 |
|
915 |
if(isNoDataValue(z)){
|
916 |
return false; |
917 |
} |
918 |
else{
|
919 |
//SubMatrix[4] = 0.0;
|
920 |
for(i=0; i<4; i++){ |
921 |
|
922 |
iDir = 2 * i;
|
923 |
z2 = getCellValueAsDouble(x + m_iOffsetX[iDir], y + m_iOffsetY[iDir]); |
924 |
if( !isNoDataValue(z2)){
|
925 |
SubMatrix[i] = z2 - z; |
926 |
} |
927 |
else{
|
928 |
z2 = getCellValueAsDouble(x + m_iOffsetX[(iDir + 4) % 8], y + m_iOffsetY[(iDir + 4) % 8]); |
929 |
if( !isNoDataValue(z2)){
|
930 |
SubMatrix[i] = z - z2; |
931 |
} |
932 |
else{
|
933 |
SubMatrix[i] = 0.0;
|
934 |
} |
935 |
} |
936 |
} |
937 |
|
938 |
return true; |
939 |
} |
940 |
} |
941 |
|
942 |
public double getSlope(int x, int y)throws GridException { |
943 |
double zm[], G, H; |
944 |
|
945 |
zm = new double[4]; |
946 |
|
947 |
try {
|
948 |
if( getSubMatrix3x3(x, y, zm) ){
|
949 |
G = (zm[0] - zm[2]) / _2DX; |
950 |
H = (zm[1] - zm[3]) / _2DX; |
951 |
return Math.atan(Math.sqrt(G*G + H*H)); |
952 |
} |
953 |
else{
|
954 |
return rasterBuf.getNoDataValue();
|
955 |
} |
956 |
} catch (GridException e) {
|
957 |
throw new GridException("Problems accesing 3x3 submatrix"); |
958 |
} |
959 |
} |
960 |
|
961 |
public double getAspect(int x, int y)throws GridException { |
962 |
double zm[], G, H, dAspect; |
963 |
|
964 |
zm = new double[4]; |
965 |
|
966 |
try {
|
967 |
if( getSubMatrix3x3(x, y, zm) ){
|
968 |
G = (zm[0] - zm[2]) / _2DX; |
969 |
H = (zm[1] - zm[3]) / _2DX; |
970 |
if( G != 0.0 ) |
971 |
dAspect = DEG_180_IN_RAD + Math.atan2(H, G);
|
972 |
else
|
973 |
dAspect = H > 0.0 ? DEG_270_IN_RAD : (H < 0.0 ? DEG_90_IN_RAD : -1.0); |
974 |
return dAspect;
|
975 |
} |
976 |
else
|
977 |
return rasterBuf.getNoDataValue();
|
978 |
} catch (GridException e) {
|
979 |
throw new GridException("Problems accesing 3x3 submatrix"); |
980 |
} |
981 |
} |
982 |
|
983 |
public static int getXOffsetInDir(int iDir){ |
984 |
return m_iOffsetX[iDir];
|
985 |
} |
986 |
|
987 |
public static int getYOffsetInDir(int iDir){ |
988 |
return m_iOffsetY[iDir];
|
989 |
} |
990 |
|
991 |
public double getDistToNeighborInDir(int iDir){ |
992 |
return m_dDist[iDir];
|
993 |
} |
994 |
|
995 |
public static double getUnitDistToNeighborInDir(int iDir){ |
996 |
return( (iDir % 2 != 0) ? Math.sqrt(2.0) : 1.0 ); |
997 |
} |
998 |
|
999 |
/*
|
1000 |
* (non-Javadoc)
|
1001 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getDirToNextDownslopeCell(int, int)
|
1002 |
*/
|
1003 |
public int getDirToNextDownslopeCell(int x, int y)throws GridException{ |
1004 |
return getDirToNextDownslopeCell(x, y, true); |
1005 |
} |
1006 |
|
1007 |
/*
|
1008 |
* (non-Javadoc)
|
1009 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getDirToNextDownslopeCell(int, int, boolean)
|
1010 |
*/
|
1011 |
public int getDirToNextDownslopeCell(int x, int y, boolean bForceDirToNoDataCell) |
1012 |
throws GridException{
|
1013 |
|
1014 |
int i, iDir;
|
1015 |
double z, z2, dSlope, dMaxSlope;
|
1016 |
|
1017 |
z = getCellValueAsDouble(x, y); |
1018 |
|
1019 |
if(isNoDataValue(z)){
|
1020 |
return -1; |
1021 |
} |
1022 |
|
1023 |
dMaxSlope = 0.0;
|
1024 |
for(iDir=-1, i=0; i<8; i++) { |
1025 |
z2 = getCellValueAsDouble(x + m_iOffsetX[i], y + m_iOffsetY[i]); |
1026 |
if(isNoDataValue(z2)) {
|
1027 |
if (bForceDirToNoDataCell) {
|
1028 |
return i;
|
1029 |
} |
1030 |
else {
|
1031 |
return -1; |
1032 |
} |
1033 |
} |
1034 |
else {
|
1035 |
dSlope = (z - z2) / getDistToNeighborInDir(i); |
1036 |
if( dSlope > dMaxSlope ) {
|
1037 |
iDir = i; |
1038 |
dMaxSlope = dSlope; |
1039 |
} |
1040 |
} |
1041 |
} |
1042 |
return iDir;
|
1043 |
} |
1044 |
|
1045 |
public GridCell[] getSortedArrayOfCells()throws GridException{ |
1046 |
int i;
|
1047 |
int iX,iY;
|
1048 |
int iNX = getNX();
|
1049 |
int iCells = getNX() * getNY();
|
1050 |
GridCell [] cells = null; |
1051 |
GridCell cell = null;
|
1052 |
|
1053 |
cells = new GridCell[iCells];
|
1054 |
|
1055 |
for (i = 0; i < iCells; i++) { |
1056 |
iX = i % iNX; |
1057 |
iY = i / iNX; |
1058 |
switch(getDataType()){
|
1059 |
case IBuffer.TYPE_BYTE: cell = new GridCell(iX, iY, getCellValueAsByte(iX, iY)); break; |
1060 |
case IBuffer.TYPE_SHORT: cell = new GridCell(iX, iY, getCellValueAsShort(iX, iY)); break; |
1061 |
case IBuffer.TYPE_INT: cell = new GridCell(iX, iY, getCellValueAsInt(iX, iY)); break; |
1062 |
case IBuffer.TYPE_FLOAT: cell = new GridCell(iX, iY, getCellValueAsFloat(iX, iY)); break; |
1063 |
case IBuffer.TYPE_DOUBLE: cell = new GridCell(iX, iY, getCellValueAsDouble(iX, iY)); break; |
1064 |
} |
1065 |
|
1066 |
cells[i] = cell; |
1067 |
} |
1068 |
|
1069 |
Arrays.sort(cells);
|
1070 |
|
1071 |
return cells;
|
1072 |
} |
1073 |
|
1074 |
/**
|
1075 |
* Obtiene la paleta para el caso de un MDT. Esta funci?n evita el tener que obtener
|
1076 |
* un array de paletas y buscar en el cuando se trata de un caso simple de MDT de una
|
1077 |
* sola banda. Comprueba que se trata de un raster monobanda con paleta asociada antes
|
1078 |
* de devolverla.
|
1079 |
* @return GridPalette asociada al Grid
|
1080 |
*/
|
1081 |
public GridPalette getMDTPalette() {
|
1082 |
if( rasterBuf != null && |
1083 |
rasterBuf.getBandCount() == 1 &&
|
1084 |
palette != null)
|
1085 |
return palette[0]; |
1086 |
return null; |
1087 |
} |
1088 |
|
1089 |
/**
|
1090 |
* Obtiene la lista de paletas asociadas al grid
|
1091 |
* @return Lista de objetos GridPalette
|
1092 |
*/
|
1093 |
public GridPalette[] getPalettes() { |
1094 |
return palette;
|
1095 |
} |
1096 |
|
1097 |
/**
|
1098 |
* Obtiene el n?mero de bandas del grid o 0 si no tiene buffer de
|
1099 |
* datos asociado.
|
1100 |
* @return N?mero de bandas
|
1101 |
*/
|
1102 |
public int getBandCount() { |
1103 |
if(rasterBuf != null) |
1104 |
return rasterBuf.getBandCount();
|
1105 |
return 0; |
1106 |
} |
1107 |
|
1108 |
/**
|
1109 |
* Asigna la lista de paletas asociadas al grid
|
1110 |
* @param palette Lista de objetos GridPalette
|
1111 |
*/
|
1112 |
public void setPalettes(GridPalette[] palette) { |
1113 |
this.palette = palette;
|
1114 |
} |
1115 |
|
1116 |
/**
|
1117 |
* Obtiene la lista de filtros.
|
1118 |
* @return Lista de filtros.
|
1119 |
*/
|
1120 |
public RasterFilterList getFilterList(){
|
1121 |
return filterList;
|
1122 |
} |
1123 |
|
1124 |
/**
|
1125 |
* Asigna la lista de filtros
|
1126 |
* @param filterList
|
1127 |
*/
|
1128 |
public void setFilterList(RasterFilterList filterList) { |
1129 |
this.filterList = filterList;
|
1130 |
} |
1131 |
|
1132 |
/**
|
1133 |
*Aplica la lista de filtros sobre el buffer
|
1134 |
* @throws InterruptedException
|
1135 |
*/
|
1136 |
public void applyFilters() throws InterruptedException { |
1137 |
if (filterList == null) |
1138 |
return;
|
1139 |
|
1140 |
filterList.setInitRasterBuf(rasterBuf); |
1141 |
filterList.execute(); |
1142 |
rasterBuf = (RasterBuffer) filterList.getResult(); |
1143 |
dataType = rasterBuf.getDataType(); |
1144 |
} |
1145 |
|
1146 |
/**
|
1147 |
* Obtiene el buffer de datos del grid
|
1148 |
* @return RasterBuf
|
1149 |
*/
|
1150 |
public IBuffer getRasterBuf() {
|
1151 |
return rasterBuf;
|
1152 |
} |
1153 |
|
1154 |
/**
|
1155 |
* Asigna la banda sobre la que se realizan las operaciones. Por defecto es la banda 0
|
1156 |
* con lo que para el uso de MDTs no habr? que modificar este valor.
|
1157 |
* @param band Banda sobre la que se realizan las operaciones.
|
1158 |
*/
|
1159 |
public void setBandToOperate(int band) { |
1160 |
if(writer != null) |
1161 |
writer.setBandToOperate(band); |
1162 |
if(reader != null) |
1163 |
reader.setBandToOperate(band); |
1164 |
if(statistic != null) |
1165 |
statistic.setBandToOperate(band); |
1166 |
} |
1167 |
|
1168 |
/**
|
1169 |
* Obtiene el extent de la ventana seleccionada para petici?n de datos
|
1170 |
* @return GridExtent
|
1171 |
*/
|
1172 |
public GridExtent getWindowExtent() {
|
1173 |
return windowExtent;
|
1174 |
} |
1175 |
|
1176 |
/**
|
1177 |
* Obtiene el extent del grid para petici?n de datos
|
1178 |
* @return GridExtent
|
1179 |
*/
|
1180 |
public GridExtent getGridExtent() {
|
1181 |
return layerExtent;
|
1182 |
} |
1183 |
} |