Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-gdal / src / main / java / es / gva / cit / jgdal / GdalRasterBand.java @ 19201

History | View | Annotate | Download (10.2 KB)

1 17679 maquerol
/**********************************************************************
2
 * $Id: GdalRasterBand.java 15691 2007-10-31 10:49:53Z nbrodin $
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 19201 maquerol
/* 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 17679 maquerol
51
package es.gva.cit.jgdal;
52
53
/**
54 19201 maquerol
 * Representa a una banda simple de la im�gen o canal.
55 17679 maquerol
 *
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 19201 maquerol
64 17679 maquerol
        private native long getOverviewNat(long cPtr,int i);
65
        private native long getRasterColorTableNat(long cPtr);
66
        private native GdalBuffer readRasterNat(long cPtr,
67 19201 maquerol
                        int nXOff, int nYOff, int nXSize, int nYSize,
68
                        int BufXSize, int BufYSize,
69
                        int eBufType);
70 17679 maquerol
        private native GdalBuffer readRasterWithPaletteNat(long cPtr,
71 19201 maquerol
                        int nXOff, int nYOff, int nXSize, int nYSize,
72
                        int BufXSize, int BufYSize,
73
                        int eBufType);
74 17679 maquerol
        private native void writeRasterNat(        long cPtr,
75 19201 maquerol
                        int nXOff, int nYOff, int nXSize, int nYSize,
76
                        GdalBuffer buffer,
77
                        int eBufType);
78 17679 maquerol
        private native double getRasterNoDataValueNat(long cPtr);
79
        private native String[] getMetadataNat(long cPtr,String pszDomain);
80
        private native int getRasterColorInterpretationNat(long cPtr);
81 19201 maquerol
82
83 17679 maquerol
        /**
84
         * Asigna el identificador de la banda
85
         */
86 19201 maquerol
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 17679 maquerol
         public GdalBuffer readRaster(int nXOff, int nYOff, int nXSize, int nYSize,
108 19201 maquerol
                         int BufXSize, int BufYSize,
109
                         int eBufType)throws GdalException {
110
                 System.err.println("Leyendo raster...");
111
                 GdalBuffer buffer = readRasterNat(cPtr, nXOff, nYOff, nXSize, nYSize, BufXSize, BufYSize, eBufType);
112
                 System.err.println("Raster leido.");
113
                 if(buffer!=null)
114
                         return buffer;
115
                 else
116
                         return null;
117 17679 maquerol
         }
118 19201 maquerol
119 17679 maquerol
         /**
120 19201 maquerol
          * Escribe datos en la banda de la im�gen
121 17679 maquerol
          *
122
          * @param nXOff        El desplazamiento del pixel desde la esquina superior derecha
123
          * de la banda accedida.
124 19201 maquerol
          * @param nYOff        El desplazamiento de l�nea desde la esquina superior derecha
125 17679 maquerol
          * de la banda accedida.
126 19201 maquerol
          * @param nXSize        Ancho de la regi�n en pixels de la banda que ser� accedida
127
          * @param nYSize        Altura de la regi�n en l�neas de la banda que ser� accedida
128
          * @param BufXSize        Ancho del buffer donde la regi�n de la im�gen ser� guardada
129
          * @param BufYSize        Altura del buffer donde la regi�n de la im�gen ser� guardada
130 17679 maquerol
          * @param eBufType
131
          */
132 19201 maquerol
133 17679 maquerol
         public void writeRaster(int nXOff, int nYOff, int nXSize, int nYSize, GdalBuffer buf, int eBufType)throws GdalException{
134 19201 maquerol
                 GdalBuffer buffer=new GdalBuffer();
135
                 switch(eBufType){
136
                 case 0:
137
                         return;
138
                 case 1:
139
                         buffer.buffByte=buf.buffByte;
140
                         break;
141
                 case 2:
142
                 case 3:
143
                 case 8:
144
                         buffer.buffShort=buf.buffShort;
145
                         break;
146
                 case 4:
147
                 case 5:
148
                 case 9:
149
                         buffer.buffInt=buf.buffInt;
150
                         break;
151
                 case 6:
152
                 case 10:
153
                         buffer.buffFloat=buf.buffFloat;
154
                         break;
155
                 case 7:
156
                 case 11:
157
                         buffer.buffDouble=buf.buffDouble;
158
                         break;
159
                 case 12:
160
                         return;
161
                 }
162
163
                 writeRasterNat(cPtr, nXOff, nYOff, nXSize, nYSize, buffer, eBufType);
164 17679 maquerol
         }
165 19201 maquerol
166
         /**
167
          *Obtiene el tama�o en pixeles de la im�gen en el eje de las X
168
          *@return Tama�o en pixeles del eje X
169
          *@throws GdalException
170
          */
171
172
         public int getRasterBandXSize()throws GdalException {
173
                 String msg1="Error en getRasterBandXSize(). La llamada getRasterBand no tuvo exito";
174
                 String msg2="Tama�o de banda erroneo devuelto por GetRasterBandXSize";
175
176
                 return baseSimpleFunctions(0,msg1,msg2);
177
         }
178
179
         /**
180
          *Obtiene el tama�o en pixeles de la im�gen en el eje de las Y
181
          *@return Tama�o en pixeles del eje Y
182
          *@throws GdalException
183
          */
184
185
         public int getRasterBandYSize()throws GdalException {
186
                 String msg1="Error en getRasterBandYSize(). La llamada getRasterBand no tuvo exito";
187
                 String msg2="Tama�o de banda erroneo devuelto por GetRasterBandYSize";
188
189
                 return baseSimpleFunctions(1,msg1,msg2);
190
         }
191
192
193
         /**
194
          * Devuelve el n�mero de overviews que contiene la banda.
195
          * @return N�mero de overviews
196
          * @throws GdalException
197
          */
198
199
         public int getOverviewCount()throws GdalException {
200
                 String msg1="Error en getOverviewCount(). La llamada getRasterBand no tuvo exito";
201
                 String msg2="Error al obtener el n�mero de overviews";
202
203
                 return baseSimpleFunctions(2,msg1,msg2);
204
         }
205
206
207
         /**
208
          * Obtiene el overview indicado por el �ndice "i".
209
          *
210
          * @param i        indice del overview que se quiere recuperar.
211
          * @return GdalRasterBand        Banda correspondiente al overview selecccionado
212
          * @throws GdalException
213
          */
214
215
         public GdalRasterBand getOverview(int i)throws GdalException {
216
                 long cPtr_ov;
217
218
                 if(i<0 && i>=this.getOverviewCount())
219
                         throw new GdalException("El overview seleccionado no existe");
220
221
                 cPtr_ov = getOverviewNat(cPtr,i);
222
223
                 return new GdalRasterBand(cPtr_ov);
224
         }
225
226
227
         /**
228
          * Devuelve el tama�o en X del bloque para esa banda
229
          * @return Tama�o en pixeles del bloque en el eje X
230
          * @throws GdalException
231
          */
232
233
         public int getBlockXSize()throws GdalException {
234
                 String msg1="Error en getBlockXSize(). La llamada getRasterBand no tuvo exito";
235
                 String msg2="Tama�o de bloque erroneo devuelto por GetBlockXSize";
236
237
                 return baseSimpleFunctions(3,msg1,msg2);
238
         }
239
240
241
         /**
242
          * Devuelve el tama�o en Y del bloque para esa banda
243
          * @return Tama�o en pixeles del bloque en el eje Y
244
          * @throws GdalException
245
          */
246
247
         public int getBlockYSize()throws GdalException {
248
                 String msg1="Error en getBlockXSize(). La llamada getRasterBand no tuvo exito";
249
                 String msg2="Tama�o de bloque erroneo devuelto por GetBlockYSize";
250
251
                 return baseSimpleFunctions(4,msg1,msg2);
252
         }
253
254
         /**
255
          * Devuelve el tipo de datos de la banda
256
          * @return Tama�o en pixeles del bloque en el eje Y
257
          * @throws GdalException
258
          */
259
260
         public int getRasterDataType()throws GdalException {
261
                 String msg1="Error en getRasterDataType(). La llamada getRasterBand no tuvo exito";
262
                 String msg2="Tipo de dato devuelto por GetRasterDataType erroneo";
263
264
                 return baseSimpleFunctions(9,msg1,msg2);
265
         }
266
267
         /**
268
          * Obtiene la tabla de color asociada a la imagen
269
          */
270
         public GdalColorTable getRasterColorTable()throws GdalException {
271
                 GdalColorTable gct = null;
272
                 long l = getRasterColorTableNat(cPtr);
273
                 if(l > 0)
274
                         gct = new GdalColorTable(l);
275
                 else
276
                         return null;
277
278
                 return gct;
279
         }
280
281
         /**
282
          * Lee datos de la banda de la im�gen con una paleta asociada
283
          *
284
          * @return        Devuelve un vector de bytes con el trozo de raster le�do.
285
          * @param nXOff        El desplazamiento del pixel desde la esquina superior derecha
286
          * de la banda accedida.
287
          * @param nYOff        El desplazamiento de l�nea desde la esquina superior derecha
288
          * de la banda accedida.
289
          * @param nXSize        Ancho de la regi�n en pixels de la banda que ser� accedida
290
          * @param nYSize        Altura de la regi�n en l�neas de la banda que ser� accedida
291
          * @param BufXSize        Ancho del buffer donde la regi�n de la im�gen ser� guardada
292
          * @param BufYSize        Altura del buffer donde la regi�n de la im�gen ser� guardada
293
          * @param eBufType
294
          */
295
296 17679 maquerol
         public GdalBuffer readRasterWithPalette(int nXOff, int nYOff, int nXSize, int nYSize,
297 19201 maquerol
                         int BufXSize, int BufYSize,
298
                         int eBufType)throws GdalException {
299
300
                 GdalBuffer buffer = readRasterWithPaletteNat(cPtr, nXOff, nYOff, nXSize, nYSize, BufXSize, BufYSize, eBufType);
301
302
303
                 if(buffer!=null)
304
                         return buffer;
305
                 else
306
                         return null;
307 17679 maquerol
         }
308 19201 maquerol
309 17679 maquerol
         /**
310
          *Devuelve el valor de NoData
311
          */
312 19201 maquerol
313 17679 maquerol
         public double getRasterNoDataValue()throws GdalException {
314
                 return getRasterNoDataValueNat(cPtr);
315
         }
316 19201 maquerol
317 17679 maquerol
         /**
318
          * Obtiene un array de Strings con los metadatos
319
          *
320
          * @throws GdalException
321 19201 maquerol
          * @return Array de Strings que corresponden a los metadatos que ofrece la im�gen
322 17679 maquerol
          */
323 19201 maquerol
324 17679 maquerol
         public String[] getMetadata()throws GdalException {
325
                 String[] res = getMetadataNat(cPtr,null);
326
                 if(res == null)
327
                         return new String[0];
328
                 else return res;
329
         }
330 19201 maquerol
331 17679 maquerol
         /**
332 19201 maquerol
          * Obtiene identificador que representa el tipo de banda de color.
333
          * @return        identificador del tipo de banda de color
334
          * @throws GdalException
335
          */
336
337 17679 maquerol
         public int getRasterColorInterpretation()throws GdalException {
338 19201 maquerol
                 int bandType = getRasterColorInterpretationNat(cPtr);
339
                 return bandType;
340 17679 maquerol
         }
341
}