Revision 30008 branches/v2_0_0_prep/libraries/libRaster/src/org/gvsig/raster/grid/Grid.java
Grid.java | ||
---|---|---|
96 | 96 |
throws RasterBufferInvalidException{ |
97 | 97 |
BufferFactory bufferFactory = new BufferFactory(datasets); |
98 | 98 |
double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(), |
99 |
bufferFactory.getSourceHeight());
|
|
100 |
layerExtent = new GridExtent( bufferFactory.getDataSource().getExtent(),
|
|
99 |
bufferFactory.getSourceHeight()); |
|
100 |
layerExtent = new GridExtent( bufferFactory.getDataSource().getExtent(), |
|
101 | 101 |
cellSize[0], |
102 | 102 |
cellSize[1]); |
103 | 103 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
... | ... | |
111 | 111 |
|
112 | 112 |
if (this.windowExtent.fitsIn(layerExtent)) |
113 | 113 |
reader = new GridNotInterpolated(bufferFactory, layerExtent, this.windowExtent, bands); |
114 |
else {
|
|
114 |
else |
|
115 | 115 |
reader = new GridInterpolated(bufferFactory, layerExtent, this.windowExtent, bands); |
116 |
} |
|
117 | 116 |
rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf(); |
118 | 117 |
writer = new GridWriter(layerExtent, dataType, rasterBuf); |
119 |
|
|
118 |
|
|
120 | 119 |
init(bufferFactory); |
121 | 120 |
} |
122 |
|
|
121 |
|
|
123 | 122 |
/** |
124 | 123 |
* Carga el buffer de datos desde el reader para poder escribir sobre los datos de |
125 | 124 |
* la ventana original. Esto es ?til cuando el GridWriter se crea asociado a un raster |
... | ... | |
134 | 133 |
int x = 0, y = 0; |
135 | 134 |
try{ |
136 | 135 |
switch(rasterBuf.getDataType()) { |
137 |
case IBuffer.TYPE_BYTE: for (x = 0; x < getNX(); x++) { |
|
138 |
for (y = 0; y < getNY(); y++) |
|
139 |
writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y))); |
|
140 |
} |
|
136 |
case IBuffer.TYPE_BYTE: for (x = 0; x < getNX(); x++) |
|
137 |
for (y = 0; y < getNY(); y++) |
|
138 |
writer.setCellValue(x, y, (reader.getCellValueAsByte(x, y))); |
|
141 | 139 |
break; |
142 |
case IBuffer.TYPE_SHORT:for (x = 0; x < getNX(); x++) { |
|
143 |
for (y = 0; y < getNY(); y++) |
|
144 |
writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y))); |
|
145 |
} |
|
140 |
case IBuffer.TYPE_SHORT:for (x = 0; x < getNX(); x++) |
|
141 |
for (y = 0; y < getNY(); y++) |
|
142 |
writer.setCellValue(x, y, (reader.getCellValueAsShort(x, y))); |
|
146 | 143 |
break; |
147 |
case IBuffer.TYPE_INT: for (x = 0; x < getNX(); x++) { |
|
148 |
for (y = 0; y < getNY(); y++) |
|
149 |
writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y))); |
|
150 |
} |
|
144 |
case IBuffer.TYPE_INT: for (x = 0; x < getNX(); x++) |
|
145 |
for (y = 0; y < getNY(); y++) |
|
146 |
writer.setCellValue(x, y, (reader.getCellValueAsInt(x, y))); |
|
151 | 147 |
break; |
152 |
case IBuffer.TYPE_FLOAT:for (x = 0; x < getNX(); x++) { |
|
153 |
for (y = 0; y < getNY(); y++) |
|
154 |
writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y))); |
|
155 |
} |
|
148 |
case IBuffer.TYPE_FLOAT:for (x = 0; x < getNX(); x++) |
|
149 |
for (y = 0; y < getNY(); y++) |
|
150 |
writer.setCellValue(x, y, (reader.getCellValueAsFloat(x, y))); |
|
156 | 151 |
break; |
157 |
case IBuffer.TYPE_DOUBLE:for (x = 0; x < getNX(); x++) { |
|
158 |
for (y = 0; y < getNY(); y++) |
|
159 |
writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y))); |
|
160 |
} |
|
152 |
case IBuffer.TYPE_DOUBLE:for (x = 0; x < getNX(); x++) |
|
153 |
for (y = 0; y < getNY(); y++) |
|
154 |
writer.setCellValue(x, y, (reader.getCellValueAsDouble(x, y))); |
|
161 | 155 |
break; |
162 | 156 |
} |
163 | 157 |
} catch (RasterBufferInvalidException e) { |
... | ... | |
207 | 201 |
*/ |
208 | 202 |
public Grid(BufferFactory bufferFactory, boolean notInterp) { |
209 | 203 |
double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(), |
210 |
bufferFactory.getSourceHeight());
|
|
211 |
this.layerExtent = new GridExtent( bufferFactory.getDataSource().getExtent(),
|
|
204 |
bufferFactory.getSourceHeight()); |
|
205 |
this.layerExtent = new GridExtent( bufferFactory.getDataSource().getExtent(), |
|
212 | 206 |
cellSize[0], |
213 | 207 |
cellSize[1]); |
214 | 208 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
215 | 209 |
dataType = bufferFactory.getDataSource().getDataType()[0]; |
216 | 210 |
bands = bufferFactory.getDrawableBands(); |
217 | 211 |
|
218 |
this.windowExtent = new GridExtent( bufferFactory.getDataExtent(),
|
|
212 |
this.windowExtent = new GridExtent( bufferFactory.getDataExtent(), |
|
219 | 213 |
cellSize[0], |
220 | 214 |
cellSize[1]); |
221 | 215 |
|
222 | 216 |
rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf(); |
223 | 217 |
|
224 |
if(notInterp) {
|
|
218 |
if(notInterp) |
|
225 | 219 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands); |
226 |
} else { |
|
227 |
if (windowExtent.fitsIn(layerExtent)) |
|
228 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands); |
|
229 |
else |
|
230 |
reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands); |
|
231 |
} |
|
220 |
else if (windowExtent.fitsIn(layerExtent)) |
|
221 |
reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands); |
|
222 |
else |
|
223 |
reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands); |
|
232 | 224 |
writer = new GridWriter(layerExtent, dataType, rasterBuf); |
233 | 225 |
init(bufferFactory); |
234 | 226 |
} |
... | ... | |
244 | 236 |
throws RasterBufferInvalidException{ |
245 | 237 |
//La petici?n es del raster completo |
246 | 238 |
double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(), |
247 |
bufferFactory.getSourceHeight());
|
|
248 |
windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(),
|
|
239 |
bufferFactory.getSourceHeight()); |
|
240 |
windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(), |
|
249 | 241 |
cellSize[0], |
250 | 242 |
cellSize[1]); |
251 | 243 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
... | ... | |
269 | 261 |
public Grid(BufferFactory bufferFactory) throws RasterBufferInvalidException { |
270 | 262 |
//La petici?n es del raster completo |
271 | 263 |
double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(), |
272 |
bufferFactory.getSourceHeight());
|
|
273 |
windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(),
|
|
264 |
bufferFactory.getSourceHeight()); |
|
265 |
windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(), |
|
274 | 266 |
cellSize[0], |
275 | 267 |
cellSize[1]); |
276 | 268 |
if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null) |
... | ... | |
285 | 277 |
|
286 | 278 |
init(bufferFactory); |
287 | 279 |
} |
288 |
|
|
280 |
|
|
289 | 281 |
/** |
290 | 282 |
* Calcula el tama?o de celda a partir de un dataset, un ancho y un alto en pixeles |
291 | 283 |
* @return |
... | ... | |
296 | 288 |
Extent e = mDataset.getExtent(); |
297 | 289 |
dCellsize[0] = (e.getLRX() - e.getULX()) / w; |
298 | 290 |
dCellsize[1] = (e.getLRY() - e.getULY()) / h; |
299 |
|
|
291 |
|
|
300 | 292 |
return dCellsize; |
301 | 293 |
} catch (NullPointerException e) { |
302 | 294 |
dCellsize[0] = 1; |
... | ... | |
336 | 328 |
if (transp != null) |
337 | 329 |
transparency = new GridTransparency(transp); |
338 | 330 |
this.palette = new GridPalette[ds.getColorTables().length]; |
339 |
for (int iPal = 0; iPal < ds.getColorTables().length; iPal++) {
|
|
331 |
for (int iPal = 0; iPal < ds.getColorTables().length; iPal++) |
|
340 | 332 |
if (ds.getColorTables()[iPal] != null) |
341 | 333 |
this.palette[iPal] = new GridPalette(ds.getColorTables()[iPal]); |
342 |
} |
|
343 | 334 |
} |
344 | 335 |
filterList = new RasterFilterList(); |
345 | 336 |
if (ds != null) { |
... | ... | |
352 | 343 |
|
353 | 344 |
m_dDist = new double[8]; |
354 | 345 |
|
355 |
for (i = 0; i < 8; i++) {
|
|
346 |
for (i = 0; i < 8; i++) |
|
356 | 347 |
m_dDist[i] = Math.sqrt ( m_iOffsetX[i] * dCellSize * m_iOffsetX[i] * dCellSize |
357 | 348 |
+ m_iOffsetY[i] * dCellSize * m_iOffsetY[i] * dCellSize ); |
358 |
} |
|
359 | 349 |
|
360 | 350 |
_2DX = dCellSize * 2.0; |
361 | 351 |
_6DX = dCellSize * 6.0; |
... | ... | |
392 | 382 |
/* |
393 | 383 |
* (non-Javadoc) |
394 | 384 |
* @see org.gvsig.fmap.grid.IWritableGrid#assign(int) |
395 |
*/
|
|
385 |
*/ |
|
396 | 386 |
public void assign(int value)throws GridException { |
397 | 387 |
try { |
398 | 388 |
writer.assign(value); |
... | ... | |
458 | 448 |
private void write(Grid g) throws GridException { |
459 | 449 |
try{ |
460 | 450 |
switch(rasterBuf.getDataType()){ |
461 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) { |
|
462 |
for (int y = 0; y < g.getNY(); y++) { |
|
463 |
writer.setCellValue(x, y, g.getCellValueAsByte(x, y)); |
|
464 |
} |
|
465 |
} |
|
451 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) |
|
452 |
for (int y = 0; y < g.getNY(); y++) |
|
453 |
writer.setCellValue(x, y, g.getCellValueAsByte(x, y)); |
|
466 | 454 |
break; |
467 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) { |
|
468 |
for (int y = 0; y < g.getNY(); y++) { |
|
469 |
writer.setCellValue(x, y, g.getCellValueAsShort(x, y)); |
|
470 |
} |
|
471 |
} |
|
455 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) |
|
456 |
for (int y = 0; y < g.getNY(); y++) |
|
457 |
writer.setCellValue(x, y, g.getCellValueAsShort(x, y)); |
|
472 | 458 |
break; |
473 |
case IBuffer.TYPE_INT: for (int x = 0; x < g.getNX(); x++) { |
|
474 |
for (int y = 0; y < g.getNY(); y++) { |
|
475 |
writer.setCellValue(x, y, g.getCellValueAsInt(x, y)); |
|
476 |
} |
|
477 |
} |
|
459 |
case IBuffer.TYPE_INT: for (int x = 0; x < g.getNX(); x++) |
|
460 |
for (int y = 0; y < g.getNY(); y++) |
|
461 |
writer.setCellValue(x, y, g.getCellValueAsInt(x, y)); |
|
478 | 462 |
break; |
479 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) { |
|
480 |
for (int y = 0; y < g.getNY(); y++) { |
|
481 |
writer.setCellValue(x, y, g.getCellValueAsFloat(x, y)); |
|
482 |
} |
|
483 |
} |
|
463 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) |
|
464 |
for (int y = 0; y < g.getNY(); y++) |
|
465 |
writer.setCellValue(x, y, g.getCellValueAsFloat(x, y)); |
|
484 | 466 |
break; |
485 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) { |
|
486 |
for (int y = 0; y < g.getNY(); y++) { |
|
487 |
writer.setCellValue(x, y, g.getCellValueAsDouble(x, y)); |
|
488 |
} |
|
489 |
} |
|
467 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) |
|
468 |
for (int y = 0; y < g.getNY(); y++) |
|
469 |
writer.setCellValue(x, y, g.getCellValueAsDouble(x, y)); |
|
490 | 470 |
break; |
491 | 471 |
} |
492 | 472 |
} catch (OutOfGridException e) { |
493 | 473 |
throw new GridException(""); |
494 |
}
|
|
474 |
} |
|
495 | 475 |
} |
496 | 476 |
|
497 | 477 |
/* |
... | ... | |
505 | 485 |
case IBuffer.TYPE_SHORT: writer.assign((short)rasterBuf.getNoDataValue());break; |
506 | 486 |
case IBuffer.TYPE_INT: writer.assign((int)rasterBuf.getNoDataValue());break; |
507 | 487 |
case IBuffer.TYPE_FLOAT: writer.assign((float)rasterBuf.getNoDataValue());break; |
508 |
case IBuffer.TYPE_DOUBLE: writer.assign((double)rasterBuf.getNoDataValue());break;
|
|
488 |
case IBuffer.TYPE_DOUBLE: writer.assign(rasterBuf.getNoDataValue());break; |
|
509 | 489 |
} |
510 | 490 |
} catch (RasterBufferInvalidAccessException e) { |
511 | 491 |
//No hacemos nada. El tipo de dato al que se accede no es controlado por el usuario por lo |
... | ... | |
564 | 544 |
switchToInterpolationMethod(false); |
565 | 545 |
try{ |
566 | 546 |
switch(rasterBuf.getDataType()){ |
567 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) { |
|
568 |
for (int y = 0; y < g.getNY(); y++) { |
|
569 |
writer.setCellValue(x, y, reader.getCellValueAsByte(x, y) + g.getCellValueAsByte(x,y)); |
|
570 |
} |
|
571 |
} |
|
547 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) |
|
548 |
for (int y = 0; y < g.getNY(); y++) |
|
549 |
writer.setCellValue(x, y, reader.getCellValueAsByte(x, y) + g.getCellValueAsByte(x,y)); |
|
572 | 550 |
break; |
573 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) { |
|
574 |
for (int y = 0; y < g.getNY(); y++) { |
|
575 |
writer.setCellValue(x, y, reader.getCellValueAsShort(x, y) + g.getCellValueAsShort(x,y)); |
|
576 |
} |
|
577 |
} |
|
551 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) |
|
552 |
for (int y = 0; y < g.getNY(); y++) |
|
553 |
writer.setCellValue(x, y, reader.getCellValueAsShort(x, y) + g.getCellValueAsShort(x,y)); |
|
578 | 554 |
break; |
579 |
case IBuffer.TYPE_INT: for (int x = 0; x < g.getNX(); x++) { |
|
580 |
for (int y = 0; y < g.getNY(); y++) { |
|
581 |
writer.setCellValue(x, y, reader.getCellValueAsInt(x, y) + g.getCellValueAsInt(x,y)); |
|
582 |
} |
|
583 |
} |
|
555 |
case IBuffer.TYPE_INT: for (int x = 0; x < g.getNX(); x++) |
|
556 |
for (int y = 0; y < g.getNY(); y++) |
|
557 |
writer.setCellValue(x, y, reader.getCellValueAsInt(x, y) + g.getCellValueAsInt(x,y)); |
|
584 | 558 |
break; |
585 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) { |
|
586 |
for (int y = 0; y < g.getNY(); y++) { |
|
587 |
writer.setCellValue(x, y, reader.getCellValueAsFloat(x, y) + g.getCellValueAsFloat(x,y)); |
|
588 |
} |
|
589 |
} |
|
559 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) |
|
560 |
for (int y = 0; y < g.getNY(); y++) |
|
561 |
writer.setCellValue(x, y, reader.getCellValueAsFloat(x, y) + g.getCellValueAsFloat(x,y)); |
|
590 | 562 |
break; |
591 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) { |
|
592 |
for (int y = 0; y < g.getNY(); y++) { |
|
593 |
writer.setCellValue(x, y, reader.getCellValueAsDouble(x, y) + g.getCellValueAsDouble(x,y)); |
|
594 |
} |
|
595 |
} |
|
563 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) |
|
564 |
for (int y = 0; y < g.getNY(); y++) |
|
565 |
writer.setCellValue(x, y, reader.getCellValueAsDouble(x, y) + g.getCellValueAsDouble(x,y)); |
|
596 | 566 |
break; |
597 | 567 |
} |
598 | 568 |
} catch (OutOfGridException e) { |
... | ... | |
647 | 617 |
public void addToCellValue(int x, int y, int value) |
648 | 618 |
throws GridException { |
649 | 619 |
try { |
650 |
writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) + value));
|
|
620 |
writer.setCellValue(x, y, (reader.getCellValueAsInt(x, y) + value)); |
|
651 | 621 |
} catch (OutOfGridException e) { |
652 | 622 |
throw new GridException(""); |
653 | 623 |
} catch (RasterBufferInvalidAccessException e) { |
... | ... | |
664 | 634 |
public void addToCellValue(int x, int y, float value) |
665 | 635 |
throws GridException { |
666 | 636 |
try { |
667 |
writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) + value));
|
|
637 |
writer.setCellValue(x, y, (reader.getCellValueAsFloat(x, y) + value)); |
|
668 | 638 |
} catch (OutOfGridException e) { |
669 | 639 |
throw new GridException(""); |
670 | 640 |
} catch (RasterBufferInvalidAccessException e) { |
... | ... | |
681 | 651 |
public void addToCellValue(int x, int y, double value) |
682 | 652 |
throws GridException { |
683 | 653 |
try { |
684 |
writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y) + value));
|
|
654 |
writer.setCellValue(x, y, (reader.getCellValueAsDouble(x, y) + value)); |
|
685 | 655 |
} catch (OutOfGridException e) { |
686 | 656 |
throw new GridException(""); |
687 | 657 |
} catch (RasterBufferInvalidAccessException e) { |
... | ... | |
700 | 670 |
switchToInterpolationMethod(false); |
701 | 671 |
try{ |
702 | 672 |
switch(rasterBuf.getDataType()){ |
703 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < getNX(); x++){ |
|
704 |
for (int y = 0; y < getNY(); y++) |
|
705 |
writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y) * value)); |
|
706 |
} |
|
673 |
case IBuffer.TYPE_BYTE: for (int x = 0; x < getNX(); x++) |
|
674 |
for (int y = 0; y < getNY(); y++) |
|
675 |
writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y) * value)); |
|
707 | 676 |
break; |
708 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < getNX(); x++){ |
|
709 |
for (int y = 0; y < getNY(); y++) |
|
710 |
writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y) * value)); |
|
711 |
} |
|
677 |
case IBuffer.TYPE_SHORT:for (int x = 0; x < getNX(); x++) |
|
678 |
for (int y = 0; y < getNY(); y++) |
|
679 |
writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y) * value)); |
|
712 | 680 |
break; |
713 |
case IBuffer.TYPE_INT: for (int x = 0; x < getNX(); x++){ |
|
714 |
for (int y = 0; y < getNY(); y++) |
|
715 |
writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) * value)); |
|
716 |
} |
|
681 |
case IBuffer.TYPE_INT: for (int x = 0; x < getNX(); x++) |
|
682 |
for (int y = 0; y < getNY(); y++) |
|
683 |
writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) * value)); |
|
717 | 684 |
break; |
718 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < getNX(); x++){ |
|
719 |
for (int y = 0; y < getNY(); y++) |
|
720 |
writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) * value)); |
|
721 |
} |
|
685 |
case IBuffer.TYPE_FLOAT:for (int x = 0; x < getNX(); x++) |
|
686 |
for (int y = 0; y < getNY(); y++) |
|
687 |
writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) * value)); |
|
722 | 688 |
break; |
723 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < getNX(); x++){ |
|
724 |
for (int y = 0; y < getNY(); y++) |
|
725 |
writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y) * value)); |
|
726 |
} |
|
689 |
case IBuffer.TYPE_DOUBLE:for (int x = 0; x < getNX(); x++) |
|
690 |
for (int y = 0; y < getNY(); y++) |
|
691 |
writer.setCellValue(x, y, (reader.getCellValueAsDouble(x, y) * value)); |
|
727 | 692 |
break; |
728 | 693 |
} |
729 | 694 |
} catch (RasterBufferInvalidException e) { |
... | ... | |
809 | 774 |
*/ |
810 | 775 |
public short getCellValueAsShort(int x, int y)throws GridException { |
811 | 776 |
try { |
812 |
return (short) reader.getCellValueAsShort(x, y);
|
|
777 |
return reader.getCellValueAsShort(x, y); |
|
813 | 778 |
} catch (RasterBufferInvalidAccessException e) { |
814 | 779 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
815 | 780 |
} catch (RasterBufferInvalidException e) { |
... | ... | |
823 | 788 |
*/ |
824 | 789 |
public int getCellValueAsInt(int x, int y)throws GridException { |
825 | 790 |
try { |
826 |
return (int) reader.getCellValueAsInt(x, y);
|
|
791 |
return reader.getCellValueAsInt(x, y); |
|
827 | 792 |
} catch (RasterBufferInvalidAccessException e) { |
828 | 793 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
829 | 794 |
} catch (RasterBufferInvalidException e) { |
... | ... | |
851 | 816 |
*/ |
852 | 817 |
public double getCellValueAsDouble(int x, int y)throws GridException { |
853 | 818 |
try { |
854 |
return (double) reader.getCellValueAsDouble(x, y);
|
|
819 |
return reader.getCellValueAsDouble(x, y); |
|
855 | 820 |
} catch (RasterBufferInvalidAccessException e) { |
856 | 821 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
857 | 822 |
} catch (RasterBufferInvalidException e) { |
858 | 823 |
throw new GridException("Buffer not valid"); |
859 | 824 |
} |
860 | 825 |
} |
861 |
|
|
826 |
|
|
862 | 827 |
/* |
863 | 828 |
* (non-Javadoc) |
864 | 829 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsDouble(int, int) |
865 | 830 |
*/ |
866 | 831 |
public double getCellValue(int x, int y)throws GridException { |
867 | 832 |
try { |
868 |
return (double) reader.getCellValue(x, y);
|
|
833 |
return reader.getCellValue(x, y); |
|
869 | 834 |
} catch (RasterBufferInvalidAccessException e) { |
870 | 835 |
throw new GridException("Position: (" + x + "," + y + ") not valid"); |
871 | 836 |
} catch (RasterBufferInvalidException e) { |
... | ... | |
878 | 843 |
* @see org.gvsig.fmap.grid.IQueryableGrid#getNoDataValue() |
879 | 844 |
*/ |
880 | 845 |
public double getNoDataValue() { |
881 |
return (double) rasterBuf.getNoDataValue();
|
|
846 |
return rasterBuf.getNoDataValue(); |
|
882 | 847 |
} |
883 | 848 |
|
884 | 849 |
/* |
... | ... | |
978 | 943 |
|
979 | 944 |
z = getCellValueAsDouble(x, y); |
980 | 945 |
|
981 |
if(isNoDataValue(z)) {
|
|
946 |
if(isNoDataValue(z)) |
|
982 | 947 |
return false; |
983 |
} else {
|
|
948 |
else { |
|
984 | 949 |
//SubMatrix[4] = 0.0; |
985 | 950 |
for(i = 0; i < 4; i++) { |
986 | 951 |
iDir = 2 * i; |
987 | 952 |
z2 = getCellValueAsDouble(x + m_iOffsetX[iDir], y + m_iOffsetY[iDir]); |
988 |
if( !isNoDataValue(z2)){
|
|
953 |
if( !isNoDataValue(z2)) |
|
989 | 954 |
subMatrix[i] = z2 - z; |
990 |
} else {
|
|
955 |
else { |
|
991 | 956 |
z2 = getCellValueAsDouble(x + m_iOffsetX[(iDir + 4) % 8], y + m_iOffsetY[(iDir + 4) % 8]); |
992 |
if( !isNoDataValue(z2)) {
|
|
957 |
if( !isNoDataValue(z2)) |
|
993 | 958 |
subMatrix[i] = z - z2; |
994 |
} else {
|
|
959 |
else
|
|
995 | 960 |
subMatrix[i] = 0.0; |
996 |
} |
|
997 | 961 |
} |
998 | 962 |
} |
999 | 963 |
|
... | ... | |
1015 | 979 |
G = (zm[0] - zm[2]) / _2DX; |
1016 | 980 |
H = (zm[1] - zm[3]) / _2DX; |
1017 | 981 |
return Math.atan(Math.sqrt(G * G + H * H)); |
1018 |
} |
|
1019 |
else { |
|
982 |
} else |
|
1020 | 983 |
return rasterBuf.getNoDataValue(); |
1021 |
} |
|
1022 | 984 |
} catch (GridException e) { |
1023 | 985 |
throw new GridException("Problems accesing 3x3 submatrix"); |
1024 | 986 |
} |
... | ... | |
1085 | 1047 |
|
1086 | 1048 |
z = getCellValueAsDouble(x, y); |
1087 | 1049 |
|
1088 |
if(isNoDataValue(z)){
|
|
1050 |
if(isNoDataValue(z)) |
|
1089 | 1051 |
return -1; |
1090 |
} |
|
1091 | 1052 |
|
1092 | 1053 |
dMaxSlope = 0.0; |
1093 | 1054 |
for(iDir=-1, i=0; i<8; i++) { |
1094 | 1055 |
z2 = getCellValueAsDouble(x + m_iOffsetX[i], y + m_iOffsetY[i]); |
1095 | 1056 |
if(isNoDataValue(z2)) { |
1096 |
if (bForceDirToNoDataCell) {
|
|
1057 |
if (bForceDirToNoDataCell) |
|
1097 | 1058 |
return i; |
1098 |
} |
|
1099 |
else { |
|
1059 |
else |
|
1100 | 1060 |
return -1; |
1101 |
} |
|
1102 | 1061 |
} |
1103 | 1062 |
else { |
1104 | 1063 |
dSlope = (z - z2) / getDistToNeighborInDir(i); |
... | ... | |
1207 | 1166 |
return; |
1208 | 1167 |
|
1209 | 1168 |
filterList.setInitRasterBuf(rasterBuf); |
1210 |
|
|
1169 |
|
|
1211 | 1170 |
filterList.getEnv().put("GridExtent", getGridExtent()); |
1212 | 1171 |
filterList.getEnv().put("WindowExtent", getWindowExtent()); |
1213 |
|
|
1172 |
|
|
1214 | 1173 |
filterList.execute(); |
1215 | 1174 |
rasterBuf = (RasterBuffer) filterList.getResult(); |
1216 | 1175 |
dataType = rasterBuf.getDataType(); |
... | ... | |
1253 | 1212 |
public GridExtent getGridExtent() { |
1254 | 1213 |
return layerExtent; |
1255 | 1214 |
} |
1215 |
|
|
1216 |
/** |
|
1217 |
* Releases buffer resources |
|
1218 |
*/ |
|
1219 |
public void free() { |
|
1220 |
if (rasterBuf != null) |
|
1221 |
rasterBuf.free(); |
|
1222 |
if (filterList != null) |
|
1223 |
filterList.free(); |
|
1224 |
if (writer != null) |
|
1225 |
writer.free(); |
|
1226 |
} |
|
1256 | 1227 |
} |
Also available in: Unified diff