Revision 11207
trunk/libraries/libRaster/src/org/gvsig/raster/RasterLibrary.java | ||
---|---|---|
22 | 22 |
* clases en las que se hace la divisi?n. |
23 | 23 |
*/ |
24 | 24 |
public static int defaultNumberOfClasses = 64; |
25 |
/** |
|
26 |
* Tama?o de bloque en los procesos que recorren un raster completo a base de ventanas con recorrido |
|
27 |
* descendente. Esta variable indica la altura de dicho bloque. Por lo tanto cada bloque ser? de |
|
28 |
* raster.width X blockHeight. Tipicamente recorridos de este tipo se usan para el calculo de estad?sticas, |
|
29 |
* histogramas, etc... |
|
30 |
*/ |
|
31 |
public static int blockHeight = 512; |
|
25 | 32 |
|
26 | 33 |
//*************CACHE******************* |
27 | 34 |
/** |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetStatistics.java | ||
---|---|---|
22 | 22 |
import java.util.Date; |
23 | 23 |
import java.util.Hashtable; |
24 | 24 |
|
25 |
import org.gvsig.raster.RasterLibrary; |
|
25 | 26 |
import org.gvsig.raster.dataset.FileNotOpenException; |
26 | 27 |
import org.gvsig.raster.dataset.IBuffer; |
27 | 28 |
import org.gvsig.raster.dataset.IStatistics; |
... | ... | |
202 | 203 |
secondMin = new double[grf.getBandCount()]; |
203 | 204 |
mean = new double[grf.getBandCount()]; |
204 | 205 |
variance = new double[grf.getBandCount()]; |
205 |
int iValues = 0; |
|
206 |
long[] iValues = new long[grf.getBandCount()]; |
|
207 |
boolean[] init = new boolean[grf.getBandCount()]; |
|
206 | 208 |
|
207 |
byte[] b = null;short[] s = null;int[] i = null;float[] f = null;double[] d = null; |
|
209 |
byte[][][] b = null; |
|
210 |
short[][][] s = null; |
|
211 |
int[][][] i = null; |
|
212 |
float[][][] f = null; |
|
213 |
double[][][] d = null; |
|
208 | 214 |
|
209 |
for (int iBand = 0; iBand < grf.getBandCount(); iBand ++){ |
|
210 |
iValues = 0; |
|
215 |
for (int iBand = 0; iBand < grf.getBandCount(); iBand ++) { |
|
211 | 216 |
max[iBand] = Double.MIN_VALUE; |
212 | 217 |
min[iBand] = Double.MAX_VALUE; |
213 | 218 |
secondMax[iBand] = Double.MIN_VALUE; |
214 | 219 |
secondMin[iBand] = Double.MAX_VALUE; |
215 |
mean[iBand] = variance[iBand] = 0; |
|
216 |
for (int line = 0; line < grf.getHeight(); line ++) { |
|
217 |
Object buf = null; |
|
218 |
try { |
|
219 |
buf = grf.readCompleteLine(line, iBand); |
|
220 |
} catch (InvalidSetViewException e) { |
|
221 |
//La vista se asigna autom?ticamente |
|
222 |
} |
|
223 |
switch(type){ |
|
224 |
case IBuffer.TYPE_BYTE: b = (byte[])buf;break; |
|
225 |
case IBuffer.TYPE_SHORT: s = (short[])buf;break; |
|
226 |
case IBuffer.TYPE_INT: i = (int[])buf;break; |
|
227 |
case IBuffer.TYPE_FLOAT: f = (float[])buf;break; |
|
228 |
case IBuffer.TYPE_DOUBLE: d = (double[])buf;break; |
|
229 |
} |
|
230 |
|
|
231 |
for (int col = 0; col < grf.getWidth(); col ++){ |
|
232 |
double z = (b != null) ? (b[col] & 0xff) : ((s != null) ? (s[col] & 0xffff) : ((i != null) ? (i[col] & 0xffffff) : (f != null) ? f[col] : d[col])); |
|
233 |
if (line == 0 && col == 0){ |
|
234 |
min[iBand] = z; |
|
235 |
secondMin[iBand] = z; |
|
236 |
max[iBand] = z; |
|
237 |
secondMax[iBand] = z; |
|
238 |
continue; |
|
220 |
init[iBand] = true; |
|
221 |
} |
|
222 |
|
|
223 |
int h = RasterLibrary.blockHeight; |
|
224 |
for (int block = 0; block < grf.getHeight(); block += h) { |
|
225 |
Object buf = null; |
|
226 |
try { |
|
227 |
buf = grf.readBlock(block, RasterLibrary.blockHeight); |
|
228 |
} catch (InvalidSetViewException e) { |
|
229 |
//La vista se asigna autom?ticamente |
|
230 |
} |
|
231 |
switch(type){ |
|
232 |
case IBuffer.TYPE_BYTE: b = (byte[][][])buf;break; |
|
233 |
case IBuffer.TYPE_SHORT: s = (short[][][])buf;break; |
|
234 |
case IBuffer.TYPE_INT: i = (int[][][])buf;break; |
|
235 |
case IBuffer.TYPE_FLOAT: f = (float[][][])buf;break; |
|
236 |
case IBuffer.TYPE_DOUBLE: d = (double[][][])buf;break; |
|
237 |
} |
|
238 |
|
|
239 |
int hB = RasterLibrary.blockHeight; |
|
240 |
if((block + hB) > grf.getHeight()) |
|
241 |
hB = Math.abs(grf.getHeight() - block); |
|
242 |
for (int iBand = 0; iBand < grf.getBandCount(); iBand ++) { |
|
243 |
for (int row = 0; row < hB; row++) { |
|
244 |
for (int col = 0; col < grf.getWidth(); col ++) { |
|
245 |
double z = (b != null) ? (b[iBand][row][col] & 0xff) : ((s != null) ? (s[iBand][row][col] & 0xffff) : ((i != null) ? (i[iBand][row][col] & 0xffffff) : (f != null) ? f[iBand][row][col] : d[iBand][row][col])); |
|
246 |
if (init[iBand]){ |
|
247 |
min[iBand] = z; |
|
248 |
secondMin[iBand] = z; |
|
249 |
max[iBand] = z; |
|
250 |
secondMax[iBand] = z; |
|
251 |
init[iBand] = false; |
|
252 |
continue; |
|
253 |
} |
|
254 |
if ( min[iBand] > z ){ |
|
255 |
secondMin[iBand] = min[iBand]; |
|
256 |
min[iBand] = z; |
|
257 |
} |
|
258 |
|
|
259 |
if ( secondMin[iBand] == min[iBand] && min[iBand] < z) |
|
260 |
secondMin[iBand] = z; |
|
261 |
|
|
262 |
if ( max[iBand] < z ){ |
|
263 |
secondMax[iBand] = max[iBand]; |
|
264 |
max[iBand] = z; |
|
265 |
} |
|
266 |
|
|
267 |
if ( secondMax[iBand] == max[iBand] && max[iBand] > z) |
|
268 |
secondMax[iBand] = z; |
|
269 |
|
|
270 |
mean[iBand] += z; |
|
271 |
variance[iBand] += z * z; |
|
272 |
iValues[iBand]++; |
|
239 | 273 |
} |
240 |
if ( min[iBand] > z ){ |
|
241 |
secondMin[iBand] = min[iBand]; |
|
242 |
min[iBand] = z; |
|
243 |
} |
|
244 | 274 |
|
245 |
if ( secondMin[iBand] == min[iBand] && min[iBand] < z) |
|
246 |
secondMin[iBand] = z; |
|
247 |
|
|
248 |
if ( max[iBand] < z ){ |
|
249 |
secondMax[iBand] = max[iBand]; |
|
250 |
max[iBand] = z; |
|
251 |
} |
|
252 |
|
|
253 |
if ( secondMax[iBand] == max[iBand] && max[iBand] > z) |
|
254 |
secondMax[iBand] = z; |
|
255 |
|
|
256 |
mean[iBand] += z; |
|
257 |
variance[iBand] += z * z; |
|
258 |
iValues++; |
|
275 |
if (isCanceled()) |
|
276 |
return; |
|
259 | 277 |
} |
260 |
|
|
261 |
if (isCanceled()) |
|
262 |
return; |
|
263 | 278 |
} |
264 |
if( iValues > 0 ){ |
|
265 |
mean[iBand] /= (double) iValues; |
|
266 |
variance[iBand] = variance[iBand] / (double) iValues - mean[iBand] * mean[iBand]; |
|
279 |
} |
|
280 |
|
|
281 |
for (int iBand = 0; iBand < grf.getBandCount(); iBand ++) { |
|
282 |
if( iValues[iBand] > 0 ) { |
|
283 |
mean[iBand] /= (double) iValues[iBand]; |
|
284 |
variance[iBand] = variance[iBand] / (double) iValues[iBand] - mean[iBand] * mean[iBand]; |
|
267 | 285 |
} |
268 | 286 |
} |
269 | 287 |
|
270 |
|
|
271 | 288 |
calculated = true; |
272 | 289 |
t2 = new Date().getTime(); |
273 | 290 |
System.out.println("Estadisticas " + grf.getFName() + ": " + ((t2 - t1) / 1000D) + ", secs."); |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/GdalNative.java | ||
---|---|---|
552 | 552 |
return null; |
553 | 553 |
} |
554 | 554 |
|
555 |
/** |
|
556 |
* Lee una bloque completo del raster y devuelve un array tridimensional del tipo correcto. Esta funci?n es util |
|
557 |
* para una lectura rapida de todo el fichero sin necesidad de asignar vista. |
|
558 |
* @param nLine N?mero de l?nea a leer |
|
559 |
* @param band Banda requerida |
|
560 |
* @return Object que es un array unidimendional del tipo de datos del raster |
|
561 |
* @throws GdalException |
|
562 |
*/ |
|
563 |
public Object readBlock(int pos, int blockHeight) throws GdalException { |
|
564 |
bBandNr = super.getRasterCount(); |
|
565 |
int nX = getRasterXSize(); |
|
566 |
|
|
567 |
GdalRasterBand[] gdalBand = new GdalRasterBand[bBandNr]; |
|
568 |
for (int iBand = 0; iBand < gdalBand.length; iBand++) { |
|
569 |
gdalBand[iBand] = super.getRasterBand(iBand + 1); |
|
570 |
} |
|
571 |
|
|
572 |
GdalBuffer[] gdalBuf = new GdalBuffer[bBandNr]; |
|
573 |
|
|
574 |
if (dataType == GDT_Byte) { |
|
575 |
byte[][][] buf = new byte[bBandNr][blockHeight][getRasterXSize()]; |
|
576 |
for (int iBand = 0; iBand < gdalBuf.length; iBand++) { |
|
577 |
gdalBuf[iBand] = gdalBand[iBand].readRaster(0, pos, nX, blockHeight, nX, blockHeight, dataType); |
|
578 |
for (int iRow = 0; iRow < blockHeight; iRow++) |
|
579 |
for (int iCol = 0; iCol < nX; iCol++) |
|
580 |
buf[iBand][iRow][iCol] = gdalBuf[iBand].buffByte[iRow * nX + iCol]; |
|
581 |
} |
|
582 |
return buf; |
|
583 |
} else if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16) { |
|
584 |
short[][][] buf = new short[bBandNr][blockHeight][getRasterXSize()]; |
|
585 |
for (int iBand = 0; iBand < gdalBuf.length; iBand++) { |
|
586 |
gdalBuf[iBand] = gdalBand[iBand].readRaster(0, pos, nX, blockHeight, nX, blockHeight, dataType); |
|
587 |
for (int iRow = 0; iRow < blockHeight; iRow++) |
|
588 |
for (int iCol = 0; iCol < nX; iCol++) |
|
589 |
buf[iBand][iRow][iCol] = gdalBuf[iBand].buffShort[iRow * nX + iCol]; |
|
590 |
} |
|
591 |
return buf; |
|
592 |
} else if (dataType == GDT_CInt32 || dataType == GDT_Int32 || dataType == GDT_UInt32) { |
|
593 |
int[][][] buf = new int[bBandNr][blockHeight][getRasterXSize()]; |
|
594 |
for (int iBand = 0; iBand < gdalBuf.length; iBand++) { |
|
595 |
gdalBuf[iBand] = gdalBand[iBand].readRaster(0, pos, nX, blockHeight, nX, blockHeight, dataType); |
|
596 |
for (int iRow = 0; iRow < blockHeight; iRow++) |
|
597 |
for (int iCol = 0; iCol < nX; iCol++) |
|
598 |
buf[iBand][iRow][iCol] = gdalBuf[iBand].buffInt[iRow * nX + iCol];; |
|
599 |
} |
|
600 |
return buf; |
|
601 |
} else if(dataType == GDT_Float32 || dataType == GDT_CFloat32) { |
|
602 |
float[][][] buf = new float[bBandNr][blockHeight][getRasterXSize()]; |
|
603 |
for (int iBand = 0; iBand < gdalBuf.length; iBand++) { |
|
604 |
gdalBuf[iBand] = gdalBand[iBand].readRaster(0, pos, nX, blockHeight, nX, blockHeight, dataType); |
|
605 |
for (int iRow = 0; iRow < blockHeight; iRow++) |
|
606 |
for (int iCol = 0; iCol < nX; iCol++) |
|
607 |
buf[iBand][iRow][iCol] = gdalBuf[iBand].buffFloat[iRow * nX + iCol];; |
|
608 |
} |
|
609 |
return buf; |
|
610 |
} else if(dataType == GDT_Float64 || dataType == GDT_CFloat64) { |
|
611 |
double[][][] buf = new double[bBandNr][blockHeight][getRasterXSize()]; |
|
612 |
for (int iBand = 0; iBand < gdalBuf.length; iBand++) { |
|
613 |
gdalBuf[iBand] = gdalBand[iBand].readRaster(0, pos, nX, blockHeight, nX, blockHeight, dataType); |
|
614 |
for (int iRow = 0; iRow < blockHeight; iRow++) |
|
615 |
for (int iCol = 0; iCol < nX; iCol++) |
|
616 |
buf[iBand][iRow][iCol] = gdalBuf[iBand].buffDouble[iRow * nX + iCol];; |
|
617 |
} |
|
618 |
return buf; |
|
619 |
} |
|
620 |
|
|
621 |
return null; |
|
622 |
} |
|
623 |
|
|
555 | 624 |
public void readLine(Object line) throws GdalException { |
556 | 625 |
int w = (int) (Math.ceil(((double)currentViewWidth)*stepX) + 1); |
557 | 626 |
int x = (int) (currentViewX); |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/GdalDriver.java | ||
---|---|---|
238 | 238 |
} |
239 | 239 |
} |
240 | 240 |
|
241 |
/* |
|
242 |
* (non-Javadoc) |
|
243 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int) |
|
244 |
*/ |
|
245 |
public Object readBlock(int pos, int blockHeight) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
246 |
if(pos < 0) |
|
247 |
throw new InvalidSetViewException("Request out of grid"); |
|
248 |
|
|
249 |
if((pos + blockHeight) > getHeight()) |
|
250 |
blockHeight = Math.abs(getHeight() - pos); |
|
251 |
try{ |
|
252 |
return file.readBlock(pos, blockHeight); |
|
253 |
}catch(GdalException e){ |
|
254 |
throw new RasterDriverException("Error reading data from Gdal library"); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
241 | 258 |
/*private IBuffer getRaster(int width, int height, ICoordTrans rp) { |
242 | 259 |
int line; |
243 | 260 |
IBuffer raster = null; |
... | ... | |
550 | 567 |
// TODO Auto-generated method stub |
551 | 568 |
|
552 | 569 |
} |
570 |
|
|
571 |
|
|
553 | 572 |
} |
554 | 573 |
|
555 | 574 |
|
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/MemoryRasterDriver.java | ||
---|---|---|
599 | 599 |
} |
600 | 600 |
return null; |
601 | 601 |
} |
602 |
|
|
603 |
/* |
|
604 |
* (non-Javadoc) |
|
605 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int) |
|
606 |
*/ |
|
607 |
public Object readBlock(int pos, int blockHeight) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
608 |
if(pos < 0) |
|
609 |
throw new InvalidSetViewException("Request out of grid"); |
|
610 |
|
|
611 |
if((pos + blockHeight) > buffer.getHeight()) |
|
612 |
blockHeight = Math.abs(buffer.getHeight() - pos); |
|
613 |
|
|
614 |
switch(buffer.getDataType()){ |
|
615 |
case IBuffer.TYPE_BYTE: |
|
616 |
byte[][][] bufb = new byte[getBandCount()][][]; |
|
617 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
618 |
for (int row = 0; row < blockHeight; row++) { |
|
619 |
bufb[iBand][row] = buffer.getLineFromBandByte(row, iBand); |
|
620 |
} |
|
621 |
} |
|
622 |
return bufb; |
|
623 |
case IBuffer.TYPE_SHORT: |
|
624 |
short[][][] bufs = new short[getBandCount()][][]; |
|
625 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
626 |
for (int row = 0; row < blockHeight; row++) { |
|
627 |
bufs[iBand][row] = buffer.getLineFromBandShort(row, iBand); |
|
628 |
} |
|
629 |
} |
|
630 |
return bufs; |
|
631 |
case IBuffer.TYPE_INT: |
|
632 |
int[][][] bufi = new int[getBandCount()][][]; |
|
633 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
634 |
for (int row = 0; row < blockHeight; row++) { |
|
635 |
bufi[iBand][row] = buffer.getLineFromBandInt(row, iBand); |
|
636 |
} |
|
637 |
} |
|
638 |
return bufi; |
|
639 |
case IBuffer.TYPE_FLOAT: |
|
640 |
float[][][] buff = new float[getBandCount()][][]; |
|
641 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
642 |
for (int row = 0; row < blockHeight; row++) { |
|
643 |
buff[iBand][row] = buffer.getLineFromBandFloat(row, iBand); |
|
644 |
} |
|
645 |
} |
|
646 |
return buff; |
|
647 |
case IBuffer.TYPE_DOUBLE: |
|
648 |
double[][][] bufd = new double[getBandCount()][][]; |
|
649 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
|
650 |
for (int row = 0; row < blockHeight; row++) { |
|
651 |
bufd[iBand][row] = buffer.getLineFromBandDouble(row, iBand); |
|
652 |
} |
|
653 |
} |
|
654 |
return bufd; |
|
655 |
} |
|
656 |
return null; |
|
657 |
} |
|
602 | 658 |
|
603 | 659 |
} |
604 | 660 |
|
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/EcwDriver.java | ||
---|---|---|
573 | 573 |
} |
574 | 574 |
|
575 | 575 |
/* |
576 |
* (non-Javadoc) |
|
577 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int, int) |
|
578 |
*/ |
|
579 |
public Object readBlock(int pos, int blockHeight) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
580 |
if(pos < 0) |
|
581 |
throw new InvalidSetViewException("Request out of grid"); |
|
582 |
|
|
583 |
if((pos + blockHeight) > file.height) |
|
584 |
blockHeight = Math.abs(file.height - pos); |
|
585 |
|
|
586 |
Point2D begin = rasterToWorld(new Point2D.Double(0, pos)); |
|
587 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, pos + blockHeight)); |
|
588 |
int[] readBandsFromECW = new int[file.numBands]; |
|
589 |
|
|
590 |
for(int i = 0; i < file.numBands; i++) |
|
591 |
readBandsFromECW[i] = i; |
|
592 |
|
|
593 |
byte[][][] buf = new byte[file.numBands][blockHeight][file.width]; |
|
594 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY()); |
|
595 |
|
|
596 |
try { |
|
597 |
int[] value = new int[file.width]; |
|
598 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), file.width, 1); |
|
599 |
|
|
600 |
if(file.numBands <= 3) { |
|
601 |
for (int row = 0; row < blockHeight; row++) { |
|
602 |
file.readLineRGBA(value); |
|
603 |
switch(getDataType()) { |
|
604 |
case IBuffer.TYPE_BYTE: |
|
605 |
for(int col = 0; col < file.width; col ++) { |
|
606 |
buf[0][row][col] = (byte)(((value[col] & 0x00ff0000) >> 16) & 0xff); |
|
607 |
buf[1][row][col] = (byte)(((value[col] & 0x0000ff00) >> 8) & 0xff); |
|
608 |
buf[2][row][col] = (byte)((value[col] & 0x000000ff) & 0xff); |
|
609 |
} |
|
610 |
break; |
|
611 |
} |
|
612 |
} |
|
613 |
} else { |
|
614 |
//TODO: FUNCIONALIDAD: file.numBands > 3 |
|
615 |
} |
|
616 |
|
|
617 |
//TODO: FUNCIONALIDAD: Ecw con otro tipo de dato != Byte |
|
618 |
} catch (JNCSFileNotOpenException e1) { |
|
619 |
throw new FileNotOpenException("Error en jecw: JNCSFileNotOpenException"); |
|
620 |
} catch (JNCSInvalidSetViewException e1) { |
|
621 |
throw new FileNotOpenException("Error en jecw: JNCSInvalidSetViewException"); |
|
622 |
} catch (JNCSException e1) { |
|
623 |
throw new RasterDriverException("Error la lectura de datos ecw"); |
|
624 |
} |
|
625 |
|
|
626 |
return buf; |
|
627 |
} |
|
628 |
|
|
629 |
/* |
|
576 | 630 |
* (non-Javadoc) |
577 | 631 |
* @see org.gvsig.raster.driver.RasterDataset#getData(int, int, int) |
578 | 632 |
*/ |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/RasterDataset.java | ||
---|---|---|
792 | 792 |
* @param nLine N?mero de l?nea a leer |
793 | 793 |
* @param band Banda requerida |
794 | 794 |
* @return Object que es un array unidimendional del tipo de datos del raster |
795 |
* @throws GdalException |
|
795 |
* @throws InvalidSetViewException |
|
796 |
* @throws FileNotOpenException |
|
797 |
* @throws RasterDriverException |
|
796 | 798 |
*/ |
797 | 799 |
abstract public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
798 | 800 |
|
799 | 801 |
/** |
802 |
* Lee un bloque completo de datos del raster y devuelve un array tridimensional del tipo correcto. Esta funci?n es util |
|
803 |
* para una lectura rapida de todo el fichero sin necesidad de asignar vista. |
|
804 |
* @param pos Posici?n donde se empieza a leer |
|
805 |
* @param blockHeight Altura m?xima del bloque leido |
|
806 |
* @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas) |
|
807 |
* @throws InvalidSetViewException |
|
808 |
* @throws FileNotOpenException |
|
809 |
* @throws RasterDriverException |
|
810 |
*/ |
|
811 |
abstract public Object readBlock(int pos, int blockHeight)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
|
812 |
|
|
813 |
/** |
|
800 | 814 |
* Convierte un punto desde coordenadas pixel a coordenadas del mundo. |
801 | 815 |
* @param pt Punto a transformar |
802 | 816 |
* @return punto transformado en coordenadas del mundo |
Also available in: Unified diff