root / branches / v10 / libraries / libjni-gdal / src / es / gva / cit / jgdal / GdalRasterBand.java @ 10988
History | View | Annotate | Download (9.94 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: GdalRasterBand.java 10988 2007-03-30 11:54:34Z nacho $
|
3 |
*
|
4 |
* Name: GdalRasterBand.java
|
5 |
* Project: JGDAL. Interface java to gdal (Frank Warmerdam).
|
6 |
* Purpose: Basic Funcions about raster bands.
|
7 |
* Author: Nacho Brodin, brodin_ign@gva.es
|
8 |
*
|
9 |
**********************************************************************/
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 |
*
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
13 |
*
|
14 |
* This program is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU General Public License
|
16 |
* as published by the Free Software Foundation; either version 2
|
17 |
* of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This program is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* GNU General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU General Public License
|
25 |
* along with this program; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
27 |
*
|
28 |
* For more information, contact:
|
29 |
*
|
30 |
* Generalitat Valenciana
|
31 |
* Conselleria d'Infraestructures i Transport
|
32 |
* Av. Blasco Ib??ez, 50
|
33 |
* 46010 VALENCIA
|
34 |
* SPAIN
|
35 |
*
|
36 |
* +34 963862235
|
37 |
* gvsig@gva.es
|
38 |
* www.gvsig.gva.es
|
39 |
*
|
40 |
* or
|
41 |
*
|
42 |
* IVER T.I. S.A
|
43 |
* Salamanca 50
|
44 |
* 46005 Valencia
|
45 |
* Spain
|
46 |
*
|
47 |
* +34 963163400
|
48 |
* dac@iver.es
|
49 |
*/
|
50 |
|
51 |
package es.gva.cit.jgdal; |
52 |
|
53 |
/**
|
54 |
* Representa a una banda simple de la im?gen o canal.
|
55 |
*
|
56 |
* @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
|
57 |
* @version 0.0
|
58 |
* @link http://www.gvsig.gva.es
|
59 |
*/
|
60 |
|
61 |
public class GdalRasterBand extends JNIBase{ |
62 |
|
63 |
|
64 |
private native long getOverviewNat(long cPtr,int i); |
65 |
private native long getRasterColorTableNat(long cPtr); |
66 |
private native GdalBuffer readRasterNat(long cPtr, |
67 |
int nXOff, int nYOff, int nXSize, int nYSize, |
68 |
int BufXSize, int BufYSize, |
69 |
int eBufType);
|
70 |
private native GdalBuffer readRasterWithPaletteNat(long cPtr, |
71 |
int nXOff, int nYOff, int nXSize, int nYSize, |
72 |
int BufXSize, int BufYSize, |
73 |
int eBufType);
|
74 |
private native void writeRasterNat( long cPtr, |
75 |
int nXOff, int nYOff, int nXSize, int nYSize, |
76 |
GdalBuffer buffer, |
77 |
int eBufType);
|
78 |
private native double getRasterNoDataValueNat(long cPtr); |
79 |
private native String[] getMetadataNat(long cPtr,String pszDomain); |
80 |
private native int getRasterColorInterpretationNat(long cPtr); |
81 |
|
82 |
|
83 |
/**
|
84 |
* Asigna el identificador de la banda
|
85 |
*/
|
86 |
|
87 |
public GdalRasterBand(long cPtr) { |
88 |
this.cPtr=cPtr;
|
89 |
} |
90 |
|
91 |
|
92 |
/**
|
93 |
* Lee datos de la banda de la im?gen
|
94 |
*
|
95 |
* @return Devuelve un vector de bytes con el trozo de raster le?do.
|
96 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha
|
97 |
* de la banda accedida.
|
98 |
* @param nYOff El desplazamiento de l?nea desde la esquina superior derecha
|
99 |
* de la banda accedida.
|
100 |
* @param nXSize Ancho de la regi?n en pixels de la banda que ser? accedida
|
101 |
* @param nYSize Altura de la regi?n en l?neas de la banda que ser? accedida
|
102 |
* @param BufXSize Ancho del buffer donde la regi?n de la im?gen ser? guardada
|
103 |
* @param BufYSize Altura del buffer donde la regi?n de la im?gen ser? guardada
|
104 |
* @param eBufType
|
105 |
*/
|
106 |
|
107 |
public GdalBuffer readRaster(int nXOff, int nYOff, int nXSize, int nYSize, |
108 |
int BufXSize, int BufYSize, |
109 |
int eBufType)throws GdalException { |
110 |
GdalBuffer buffer = readRasterNat(cPtr, nXOff, nYOff, nXSize, nYSize, BufXSize, BufYSize, eBufType); |
111 |
|
112 |
if(buffer!=null) |
113 |
return buffer;
|
114 |
else
|
115 |
return null; |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Escribe datos en la banda de la im?gen
|
120 |
*
|
121 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha
|
122 |
* de la banda accedida.
|
123 |
* @param nYOff El desplazamiento de l?nea desde la esquina superior derecha
|
124 |
* de la banda accedida.
|
125 |
* @param nXSize Ancho de la regi?n en pixels de la banda que ser? accedida
|
126 |
* @param nYSize Altura de la regi?n en l?neas de la banda que ser? accedida
|
127 |
* @param BufXSize Ancho del buffer donde la regi?n de la im?gen ser? guardada
|
128 |
* @param BufYSize Altura del buffer donde la regi?n de la im?gen ser? guardada
|
129 |
* @param eBufType
|
130 |
*/
|
131 |
|
132 |
public void writeRaster(int nXOff, int nYOff, int nXSize, int nYSize, GdalBuffer buf, int eBufType)throws GdalException{ |
133 |
GdalBuffer buffer=new GdalBuffer();
|
134 |
switch(eBufType){
|
135 |
case 0: |
136 |
return;
|
137 |
case 1: |
138 |
buffer.buffByte=buf.buffByte; |
139 |
break;
|
140 |
case 2: |
141 |
case 3: |
142 |
case 8: |
143 |
buffer.buffShort=buf.buffShort; |
144 |
break;
|
145 |
case 4: |
146 |
case 5: |
147 |
case 9: |
148 |
buffer.buffInt=buf.buffInt; |
149 |
break;
|
150 |
case 6: |
151 |
case 10: |
152 |
buffer.buffFloat=buf.buffFloat; |
153 |
break;
|
154 |
case 7: |
155 |
case 11: |
156 |
buffer.buffDouble=buf.buffDouble; |
157 |
break;
|
158 |
case 12: |
159 |
return;
|
160 |
} |
161 |
|
162 |
writeRasterNat(cPtr, nXOff, nYOff, nXSize, nYSize, buffer, eBufType); |
163 |
} |
164 |
|
165 |
/**
|
166 |
*Obtiene el tama?o en pixeles de la im?gen en el eje de las X
|
167 |
*@return Tama?o en pixeles del eje X
|
168 |
*@throws GdalException
|
169 |
*/
|
170 |
|
171 |
public int getRasterBandXSize()throws GdalException { |
172 |
String msg1="Error en getRasterBandXSize(). La llamada getRasterBand no tuvo exito"; |
173 |
String msg2="Tama?o de banda erroneo devuelto por GetRasterBandXSize"; |
174 |
|
175 |
return baseSimpleFunctions(0,msg1,msg2); |
176 |
} |
177 |
|
178 |
/**
|
179 |
*Obtiene el tama?o en pixeles de la im?gen en el eje de las Y
|
180 |
*@return Tama?o en pixeles del eje Y
|
181 |
*@throws GdalException
|
182 |
*/
|
183 |
|
184 |
public int getRasterBandYSize()throws GdalException { |
185 |
String msg1="Error en getRasterBandYSize(). La llamada getRasterBand no tuvo exito"; |
186 |
String msg2="Tama?o de banda erroneo devuelto por GetRasterBandYSize"; |
187 |
|
188 |
return baseSimpleFunctions(1,msg1,msg2); |
189 |
} |
190 |
|
191 |
|
192 |
/**
|
193 |
* Devuelve el n?mero de overviews que contiene la banda.
|
194 |
* @return N?mero de overviews
|
195 |
* @throws GdalException
|
196 |
*/
|
197 |
|
198 |
public int getOverviewCount()throws GdalException { |
199 |
String msg1="Error en getOverviewCount(). La llamada getRasterBand no tuvo exito"; |
200 |
String msg2="Error al obtener el n?mero de overviews"; |
201 |
|
202 |
return baseSimpleFunctions(2,msg1,msg2); |
203 |
} |
204 |
|
205 |
|
206 |
/**
|
207 |
* Obtiene el overview indicado por el ?ndice "i".
|
208 |
*
|
209 |
* @param i indice del overview que se quiere recuperar.
|
210 |
* @return GdalRasterBand Banda correspondiente al overview selecccionado
|
211 |
* @throws GdalException
|
212 |
*/
|
213 |
|
214 |
public GdalRasterBand getOverview(int i)throws GdalException { |
215 |
long cPtr_ov;
|
216 |
|
217 |
if(i<0 && i>=this.getOverviewCount()) |
218 |
throw new GdalException("El overview seleccionado no existe"); |
219 |
|
220 |
cPtr_ov = getOverviewNat(cPtr,i); |
221 |
|
222 |
return new GdalRasterBand(cPtr_ov); |
223 |
} |
224 |
|
225 |
|
226 |
/**
|
227 |
* Devuelve el tama?o en X del bloque para esa banda
|
228 |
* @return Tama?o en pixeles del bloque en el eje X
|
229 |
* @throws GdalException
|
230 |
*/
|
231 |
|
232 |
public int getBlockXSize()throws GdalException { |
233 |
String msg1="Error en getBlockXSize(). La llamada getRasterBand no tuvo exito"; |
234 |
String msg2="Tama?o de bloque erroneo devuelto por GetBlockXSize"; |
235 |
|
236 |
return baseSimpleFunctions(3,msg1,msg2); |
237 |
} |
238 |
|
239 |
|
240 |
/**
|
241 |
* Devuelve el tama?o en Y del bloque para esa banda
|
242 |
* @return Tama?o en pixeles del bloque en el eje Y
|
243 |
* @throws GdalException
|
244 |
*/
|
245 |
|
246 |
public int getBlockYSize()throws GdalException { |
247 |
String msg1="Error en getBlockXSize(). La llamada getRasterBand no tuvo exito"; |
248 |
String msg2="Tama?o de bloque erroneo devuelto por GetBlockYSize"; |
249 |
|
250 |
return baseSimpleFunctions(4,msg1,msg2); |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Devuelve el tipo de datos de la banda
|
255 |
* @return Tama?o en pixeles del bloque en el eje Y
|
256 |
* @throws GdalException
|
257 |
*/
|
258 |
|
259 |
public int getRasterDataType()throws GdalException { |
260 |
String msg1="Error en getRasterDataType(). La llamada getRasterBand no tuvo exito"; |
261 |
String msg2="Tipo de dato devuelto por GetRasterDataType erroneo"; |
262 |
|
263 |
return baseSimpleFunctions(9,msg1,msg2); |
264 |
} |
265 |
|
266 |
/**
|
267 |
* Obtiene la tabla de color asociada a la imagen
|
268 |
*/
|
269 |
public GdalColorTable getRasterColorTable()throws GdalException { |
270 |
GdalColorTable gct = null;
|
271 |
long l = getRasterColorTableNat(cPtr);
|
272 |
if(l > 0) |
273 |
gct = new GdalColorTable(l);
|
274 |
else
|
275 |
return null; |
276 |
|
277 |
return gct;
|
278 |
} |
279 |
|
280 |
/**
|
281 |
* Lee datos de la banda de la im?gen con una paleta asociada
|
282 |
*
|
283 |
* @return Devuelve un vector de bytes con el trozo de raster le?do.
|
284 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha
|
285 |
* de la banda accedida.
|
286 |
* @param nYOff El desplazamiento de l?nea desde la esquina superior derecha
|
287 |
* de la banda accedida.
|
288 |
* @param nXSize Ancho de la regi?n en pixels de la banda que ser? accedida
|
289 |
* @param nYSize Altura de la regi?n en l?neas de la banda que ser? accedida
|
290 |
* @param BufXSize Ancho del buffer donde la regi?n de la im?gen ser? guardada
|
291 |
* @param BufYSize Altura del buffer donde la regi?n de la im?gen ser? guardada
|
292 |
* @param eBufType
|
293 |
*/
|
294 |
|
295 |
public GdalBuffer readRasterWithPalette(int nXOff, int nYOff, int nXSize, int nYSize, |
296 |
int BufXSize, int BufYSize, |
297 |
int eBufType)throws GdalException { |
298 |
GdalBuffer buffer = readRasterWithPaletteNat(cPtr, nXOff, nYOff, nXSize, nYSize, BufXSize, BufYSize, eBufType); |
299 |
|
300 |
if(buffer!=null) |
301 |
return buffer;
|
302 |
else
|
303 |
return null; |
304 |
} |
305 |
|
306 |
/**
|
307 |
*Devuelve el valor de NoData
|
308 |
*/
|
309 |
|
310 |
public double getRasterNoDataValue()throws GdalException { |
311 |
return getRasterNoDataValueNat(cPtr);
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* Obtiene un array de Strings con los metadatos
|
316 |
*
|
317 |
* @throws GdalException
|
318 |
* @return Array de Strings que corresponden a los metadatos que ofrece la im?gen
|
319 |
*/
|
320 |
|
321 |
public String[] getMetadata()throws GdalException { |
322 |
String[] res = getMetadataNat(cPtr,null); |
323 |
if(res == null) |
324 |
return new String[0]; |
325 |
else return res; |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Obtiene identificador que representa el tipo de banda de color.
|
330 |
* @return identificador del tipo de banda de color
|
331 |
* @throws GdalException
|
332 |
*/
|
333 |
|
334 |
public int getRasterColorInterpretation()throws GdalException { |
335 |
int bandType = getRasterColorInterpretationNat(cPtr);
|
336 |
return bandType;
|
337 |
} |
338 |
} |