root / trunk / libraries / libjni-gdal / src / es / gva / cit / jgdal / GdalRasterBand.java @ 823
History | View | Annotate | Download (7.18 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: GdalRasterBand.java 823 2005-01-03 17:02:37Z igbrotru $
|
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 |
/*Copyright (C) 2004 Nacho Brodin <brodin_ign@gva.es>
|
11 |
|
12 |
This program is free software; you can redistribute it and/or
|
13 |
modify it under the terms of the GNU General Public License
|
14 |
as published by the Free Software Foundation; either version 2
|
15 |
of the License, or (at your option) any later version.
|
16 |
|
17 |
This program is distributed in the hope that it will be useful,
|
18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
GNU General Public License for more details.
|
21 |
|
22 |
You should have received a copy of the GNU General Public License
|
23 |
along with this program; if not, write to the Free Software
|
24 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
25 |
*/
|
26 |
|
27 |
package es.gva.cit.jgdal; |
28 |
|
29 |
/**
|
30 |
* Representa a una banda simple de la im?gen o canal.
|
31 |
*
|
32 |
* @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
|
33 |
* @version 0.0
|
34 |
* @link http://www.gvsig.gva.es
|
35 |
*/
|
36 |
|
37 |
public class GdalRasterBand extends JNIBase{ |
38 |
|
39 |
|
40 |
private native long getOverviewNat(long cPtr,int i); |
41 |
private native GdalBuffer readRasterNat(long cPtr, |
42 |
int nXOff, int nYOff, int nXSize, int nYSize, |
43 |
int BufXSize, int BufYSize, |
44 |
int eBufType);
|
45 |
private native void writeRasterNat( long cPtr, |
46 |
int nXOff, int nYOff, int nXSize, int nYSize, |
47 |
GdalBuffer buffer, |
48 |
int eBufType);
|
49 |
|
50 |
|
51 |
/**
|
52 |
* Asigna el identificador de la banda
|
53 |
*/
|
54 |
|
55 |
public GdalRasterBand(long cPtr){ |
56 |
|
57 |
this.cPtr=cPtr;
|
58 |
|
59 |
} |
60 |
|
61 |
|
62 |
/**
|
63 |
* Lee datos de la banda de la im?gen
|
64 |
*
|
65 |
* @return Devuelve un vector de bytes con el trozo de raster le?do.
|
66 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha
|
67 |
* de la banda accedida.
|
68 |
* @param nYOff El desplazamiento de l?nea desde la esquina superior derecha
|
69 |
* de la banda accedida.
|
70 |
* @param nXSize Ancho de la regi?n en pixels de la banda que ser? accedida
|
71 |
* @param nYSize Altura de la regi?n en l?neas de la banda que ser? accedida
|
72 |
* @param BufXSize Ancho del buffer donde la regi?n de la im?gen ser? guardada
|
73 |
* @param BufYSize Altura del buffer donde la regi?n de la im?gen ser? guardada
|
74 |
* @param eBufType
|
75 |
*/
|
76 |
|
77 |
public byte[] readRaster(int nXOff, int nYOff, int nXSize, int nYSize, |
78 |
int BufXSize, int BufYSize, |
79 |
int eBufType)throws GdalException{ |
80 |
|
81 |
if(cPtr <= 0) |
82 |
throw new GdalException("Error en GDALGetRasterBand(). La llamada GDALOpen no tuvo exito"); |
83 |
|
84 |
|
85 |
/*if( nXOff < 0 || nXOff + nXSize > nRasterXSize || nYOff < 0 || nYOff + nYSize > nRasterYSize )
|
86 |
throw new GdalException("Error en GDALReadRaster(). Limites de la ventana incorrectos");*/
|
87 |
|
88 |
GdalBuffer buffer = readRasterNat(cPtr, nXOff, nYOff, nXSize, nYSize, BufXSize, BufYSize, eBufType); |
89 |
return buffer.pabyScanLineBuf;
|
90 |
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Escribe datos en la banda de la im?gen
|
95 |
*
|
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 void writeRaster(int nXOff, int nYOff, int nXSize, int nYSize, byte[] buf, int eBufType)throws GdalException{ |
108 |
|
109 |
if(cPtr <= 0) |
110 |
throw new GdalException("Error en GDALGetRasterBand(). La llamada GDALOpen no tuvo exito"); |
111 |
|
112 |
GdalBuffer buffer=new GdalBuffer();
|
113 |
buffer.pabyScanLineBuf=buf; |
114 |
writeRasterNat(cPtr, nXOff, nYOff, nXSize, nYSize, buffer, eBufType); |
115 |
|
116 |
} |
117 |
|
118 |
/**
|
119 |
*Obtiene el tama?o en pixeles de la im?gen en el eje de las X
|
120 |
*@return Tama?o en pixeles del eje X
|
121 |
*@throws GdalException
|
122 |
*/
|
123 |
|
124 |
public int getRasterBandXSize()throws GdalException{ |
125 |
|
126 |
String msg1="Error en getRasterBandXSize(). La llamada getRasterBand no tuvo exito"; |
127 |
String msg2="Tama?o de banda erroneo devuelto por GetRasterBandXSize"; |
128 |
|
129 |
return baseSimpleFunctions(0,msg1,msg2); |
130 |
} |
131 |
|
132 |
/**
|
133 |
*Obtiene el tama?o en pixeles de la im?gen en el eje de las Y
|
134 |
*@return Tama?o en pixeles del eje Y
|
135 |
*@throws GdalException
|
136 |
*/
|
137 |
|
138 |
public int getRasterBandYSize()throws GdalException{ |
139 |
|
140 |
String msg1="Error en getRasterBandYSize(). La llamada getRasterBand no tuvo exito"; |
141 |
String msg2="Tama?o de banda erroneo devuelto por GetRasterBandYSize"; |
142 |
|
143 |
return baseSimpleFunctions(1,msg1,msg2); |
144 |
} |
145 |
|
146 |
|
147 |
/**
|
148 |
* Devuelve el n?mero de overviews que contiene la banda.
|
149 |
* @return N?mero de overviews
|
150 |
* @throws GdalException
|
151 |
*/
|
152 |
|
153 |
public int getOverviewCount()throws GdalException{ |
154 |
|
155 |
String msg1="Error en getOverviewCount(). La llamada getRasterBand no tuvo exito"; |
156 |
String msg2="Error al obtener el n?mero de overviews"; |
157 |
|
158 |
return baseSimpleFunctions(2,msg1,msg2); |
159 |
} |
160 |
|
161 |
|
162 |
/**
|
163 |
* Obtiene el overview indicado por el ?ndice "i".
|
164 |
*
|
165 |
* @param i indice del overview que se quiere recuperar.
|
166 |
* @return GdalRasterBand Banda correspondiente al overview selecccionado
|
167 |
* @throws GdalException
|
168 |
*/
|
169 |
|
170 |
public GdalRasterBand getOverview(int i)throws GdalException{ |
171 |
|
172 |
long cPtr_ov;
|
173 |
|
174 |
if(cPtr <= 0) |
175 |
throw new GdalException("Error en getOverview(). La llamada GDALOpen no tuvo exito"); |
176 |
|
177 |
if(i<0 && i>=this.getOverviewCount()) |
178 |
throw new GdalException("El overview seleccionado no existe"); |
179 |
|
180 |
cPtr_ov = getOverviewNat(cPtr,i); |
181 |
|
182 |
if(cPtr_ov < 0) |
183 |
throw new GdalException("No ha podido obtenerse el overview seleccionado"); |
184 |
|
185 |
return new GdalRasterBand(cPtr_ov); |
186 |
} |
187 |
|
188 |
|
189 |
/**
|
190 |
* Devuelve el tama?o en X del bloque para esa banda
|
191 |
* @return Tama?o en pixeles del bloque en el eje X
|
192 |
* @throws GdalException
|
193 |
*/
|
194 |
|
195 |
public int getBlockXSize()throws GdalException{ |
196 |
|
197 |
String msg1="Error en getBlockXSize(). La llamada getRasterBand no tuvo exito"; |
198 |
String msg2="Tama?o de bloque erroneo devuelto por GetBlockXSize"; |
199 |
|
200 |
return baseSimpleFunctions(3,msg1,msg2); |
201 |
} |
202 |
|
203 |
|
204 |
/**
|
205 |
* Devuelve el tama?o en Y del bloque para esa banda
|
206 |
* @return Tama?o en pixeles del bloque en el eje Y
|
207 |
* @throws GdalException
|
208 |
*/
|
209 |
|
210 |
public int getBlockYSize()throws GdalException{ |
211 |
|
212 |
String msg1="Error en getBlockXSize(). La llamada getRasterBand no tuvo exito"; |
213 |
String msg2="Tama?o de bloque erroneo devuelto por GetBlockYSize"; |
214 |
|
215 |
return baseSimpleFunctions(4,msg1,msg2); |
216 |
} |
217 |
|
218 |
/**
|
219 |
* Devuelve el tipo de datos de la banda
|
220 |
* @return Tama?o en pixeles del bloque en el eje Y
|
221 |
* @throws GdalException
|
222 |
*/
|
223 |
|
224 |
public int getRasterDataType()throws GdalException{ |
225 |
|
226 |
String msg1="Error en getRasterDataType(). La llamada getRasterBand no tuvo exito"; |
227 |
String msg2="Tipo de dato devuelto por GetRasterDataType erroneo"; |
228 |
|
229 |
return baseSimpleFunctions(9,msg1,msg2); |
230 |
} |
231 |
} |