Revision 10938
branches/v10/libraries/libCq_CMS_praster/src-test/org/cresques/io/data/TestDataSourceWithNoDataAndSizeBuffer.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 19-jul-2006 |
|
3 |
* |
|
4 |
* To change the template for this generated file go to |
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
6 |
*/ |
|
7 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
*/ |
|
25 |
package org.cresques.io.data; |
|
26 |
|
|
27 |
import junit.framework.TestCase; |
|
28 |
|
|
29 |
import org.cresques.io.GeoRasterFile; |
|
30 |
|
|
31 |
/** |
|
32 |
* Este test prueba la gesti?n de multifichero de la clase GeoRasterMultiFile |
|
33 |
* y que incorpora un Grid, as? como la gesti?n de bandas que tiene BandList |
|
34 |
* y que incorpora GeoRasterMultiFile. |
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
36 |
* |
|
37 |
*/ |
|
38 |
public class TestDataSourceWithNoDataAndSizeBuffer extends TestCase{ |
|
39 |
|
|
40 |
private String baseDir = "/home/nacho/images/"; |
|
41 |
private String path1 = baseDir + "miniRaster25x24.tif"; |
|
42 |
|
|
43 |
private GeoRasterFile f1 = null; |
|
44 |
|
|
45 |
private Grid g = null; |
|
46 |
|
|
47 |
public void setUp() { |
|
48 |
System.out.println("TestDataSourceWithNoDataAndSizeBuffer running..."); |
|
49 |
f1 = GeoRasterFile.openFile(null, path1); |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
public void testStack(){ |
|
54 |
int[] drawableBands = {0, 1, 2}; |
|
55 |
g = new Grid(f1); |
|
56 |
g.addDrawableBands(drawableBands); |
|
57 |
//El par?metro false indica que no se ajuste el extent al raster sino que se rellene con NoData los huecos |
|
58 |
|
|
59 |
//TODO: Hacer las llamadas para probar setAreaOfInterest con tama?o de buffer |
|
60 |
g.setAreaOfInterest(645819.2583, 4923849.7, 25.584, 25.2); //ZOOM |
|
61 |
//g.setAreaOfInterest(645818.2583, 4923850.7, 34.584, 33.2); |
|
62 |
//g.setAreaOfInterest(645808.2583, 4923850.7, 44.584, 33.2); //NODATA IZDA |
|
63 |
//g.setAreaOfInterest(645818.2583, 4923860.7, 34.584, 43.2); //NODATA ARRIBA |
|
64 |
//g.setAreaOfInterest(645818.2583, 4923850.7, 34.584, 43.2); //NODATA ABAJO |
|
65 |
//g.setAreaOfInterest(645818.2583, 4923850.7, 44.584, 33.2); //NODATA DCHA |
|
66 |
//g.setAreaOfInterest(645808.2583, 4923860.7, 54.584, 53.2); //NODATA 4 LADOS |
|
67 |
|
|
68 |
RasterBuf raster = g.getRasterBuf(); |
|
69 |
for(int line = 0; line < raster.getHeight(); line++){ |
|
70 |
for(int col = 0; col < raster.getWidth(); col++) |
|
71 |
System.out.print("("+raster.getElemByte(line, col, 0)+" "+raster.getElemByte(line, col, 1)+" "+raster.getElemByte(line, col, 2)+")"); |
|
72 |
System.out.println(); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
0 | 77 |
branches/v10/libraries/libCq_CMS_praster/src/org/cresques/io/data/Grid.java | ||
---|---|---|
202 | 202 |
public int[] setAreaOfInterest(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight) throws ArrayIndexOutOfBoundsException{ |
203 | 203 |
//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada |
204 | 204 |
dataExtent = new Extent(minX, minY, maxX, maxY); |
205 |
dataExtent = Utilities.calculateAdjustedView(dataExtent, grmf.getExtent());
|
|
205 |
Extent fitExtent = Utilities.calculateAdjustedView(dataExtent, grmf.getExtent());
|
|
206 | 206 |
|
207 |
rasterBuf = grmf.getWindowRaster(minX, minY, maxX, maxY, bufWidth, bufHeight); |
|
207 |
//Caso en que la extensi?n pedida SI se sale fuera del ?rea del raster |
|
208 |
//El pixel a medias entre NoData y datos se pone NoData |
|
209 |
if(!Utilities.isInside(dataExtent, fitExtent)){ |
|
210 |
//Upper Left |
|
211 |
double distWcX = Math.abs(fitExtent.getMin().getX() - dataExtent.getMin().getX()); |
|
212 |
double distWcY = Math.abs(fitExtent.getMax().getY() - dataExtent.getMax().getY()); |
|
213 |
//Pixel inicial del buffer donde se empieza a dibujar. Redondeamos por arriba pq lo que sobra se pone NoData |
|
214 |
double initPxX = Math.ceil((distWcX * bufWidth) / (Math.abs(maxX - minX))); |
|
215 |
double initPxY = Math.ceil((distWcY * bufHeight) / (Math.abs(maxY - minY))); |
|
216 |
//Obtenemos la coordenada real para el pixel inicial |
|
217 |
double wcXInit = (initPxX * (Math.abs(maxX - minX))) / bufWidth; |
|
218 |
double wcYInit = (initPxY * (Math.abs(maxY - minY))) / bufHeight; |
|
219 |
|
|
220 |
//Lower Right |
|
221 |
distWcX = Math.abs(fitExtent.getMax().getX() - dataExtent.getMin().getX()); |
|
222 |
distWcY = Math.abs(fitExtent.getMin().getY() - dataExtent.getMax().getY()); |
|
223 |
//Pixel final del buffer donde se dibuja. Redondeamos por abajo pq lo que sobra se pone NoData |
|
224 |
double endPxX = Math.floor((distWcX * bufWidth) / (Math.abs(maxX - minX))); |
|
225 |
double endPxY = Math.floor((distWcY * bufHeight) / (Math.abs(maxY - minY))); |
|
226 |
//Obtenemos la coordenada real para el pixel |
|
227 |
double wcXEnd = (endPxX * (Math.abs(maxX - minX))) / bufWidth; |
|
228 |
double wcYEnd = (endPxY * (Math.abs(maxY - minY))) / bufHeight; |
|
229 |
|
|
230 |
rasterBuf = grmf.getWindowRaster(wcXInit, wcYInit, wcXEnd, wcYEnd, (int)Math.abs(endPxX - initPxX), (int)Math.abs(endPxY - initPxY)); |
|
231 |
|
|
232 |
RasterBuf buf = new RasterBuf(rasterBuf.getDataType(), bufWidth, bufHeight, rasterBuf.getBandCount(), true); |
|
233 |
buf.setToNoData(); |
|
234 |
for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) |
|
235 |
for (int row = 0; row < rasterBuf.getHeight(); row++) |
|
236 |
for (int col = 0; col < rasterBuf.getWidth(); col++) |
|
237 |
buf.setElemByte((int)(row + initPxY), (int)(col + initPxX), |
|
238 |
iBand, |
|
239 |
rasterBuf.getElemByte(row, col, iBand)); |
|
240 |
rasterBuf = buf; |
|
241 |
return null; |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
//Caso en que la extensi?n pedida NO se sale fuera del ?rea del raster |
|
246 |
rasterBuf = grmf.getWindowRaster(fitExtent.minX(), fitExtent.maxY(), fitExtent.width(), fitExtent.height(), bufWidth, bufHeight); |
|
208 | 247 |
return null; |
209 | 248 |
} |
210 | 249 |
|
Also available in: Unified diff