Revision 22081 trunk/libraries/libjni-gdal/src/main/java/es/gva/cit/jgdal/Gdal.java
Gdal.java | ||
---|---|---|
1 |
/********************************************************************** |
|
2 |
* $Id: Gdal.java 15691 2007-10-31 10:49:53Z nbrodin $ |
|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 | 2 |
* |
4 |
* Name: Gdal.java |
|
5 |
* Project: JGDAL. Interface java to gdal (Frank Warmerdam). |
|
6 |
* Purpose: Dataset's Basic Funcions. |
|
7 |
* Author: Nacho Brodin, brodin_ign@gva.es |
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
8 | 4 |
* |
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 |
* [01] 01-Oct-2005 nbt New call to JNI function openArrayNat to convert name string to char array. |
|
51 |
*/ |
|
52 |
|
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* Project: JGDAL. Interface java to gdal (Frank Warmerdam). |
|
20 |
*/ |
|
53 | 21 |
package es.gva.cit.jgdal; |
54 | 22 |
|
55 |
|
|
56 |
import java.io.*; |
|
57 |
import java.util.Date; |
|
58 |
import sun.misc.Signal; |
|
59 |
import sun.misc.SignalHandler; |
|
60 |
import java.lang.reflect.*; |
|
61 |
|
|
62 |
//import es.gva.cit.jgdal.GdalException; |
|
63 |
|
|
23 |
import java.io.File; |
|
24 |
import java.io.IOException; |
|
64 | 25 |
/** |
65 |
* Contiene las funcionalidades necesarias para el acceso a los |
|
66 |
* elementos de un dataset de gdal correspondiente a una im�gen
|
|
26 |
* Contiene las funcionalidades necesarias para el acceso a los elementos de un
|
|
27 |
* dataset de gdal correspondiente a una imagen
|
|
67 | 28 |
* |
68 |
* @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es |
|
69 |
* @version 0.0 |
|
70 |
* @link http://www.gvsig.gva.es |
|
29 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
71 | 30 |
*/ |
31 |
public class Gdal extends JNIBase { |
|
32 |
// CONSTANTES |
|
72 | 33 |
|
73 |
public class Gdal extends JNIBase{ |
|
74 |
//CONSTANTES |
|
75 |
|
|
76 |
//GDALAccess |
|
77 |
public static int GA_ReadOnly=0; |
|
78 |
public static int GA_Update=1; |
|
79 |
|
|
80 |
//GDALDataType |
|
81 |
public static int GDT_Unknown = 0; |
|
82 |
public static int GDT_Byte = 1; //Buffer byte (8) |
|
83 |
public static int GDT_UInt16 = 2; //Buffer short (16) |
|
84 |
public static int GDT_Int16 = 3; //Buffer short (16) |
|
85 |
public static int GDT_UInt32 = 4; //Buffer int (32) |
|
86 |
public static int GDT_Int32 = 5; //Buffer int (32) |
|
87 |
public static int GDT_Float32 = 6; //Buffer float (32) |
|
88 |
public static int GDT_Float64 = 7; //Buffer double (64) |
|
89 |
public static int GDT_CInt16 = 8; //Buffer short (16) |
|
90 |
public static int GDT_CInt32 = 9; //Buffer int (32) |
|
91 |
public static int GDT_CFloat32 = 10; //Buffer float (32) |
|
92 |
public static int GDT_CFloat64 = 11; //Buffer double (64) |
|
34 |
// GDALAccess |
|
35 |
public static int GA_ReadOnly = 0; |
|
36 |
public static int GA_Update = 1; |
|
37 |
|
|
38 |
// GDALDataType |
|
39 |
public static int GDT_Unknown = 0; |
|
40 |
public static int GDT_Byte = 1; // Buffer byte (8) |
|
41 |
public static int GDT_UInt16 = 2; // Buffer short (16) |
|
42 |
public static int GDT_Int16 = 3; // Buffer short (16) |
|
43 |
public static int GDT_UInt32 = 4; // Buffer int (32) |
|
44 |
public static int GDT_Int32 = 5; // Buffer int (32) |
|
45 |
public static int GDT_Float32 = 6; // Buffer float (32) |
|
46 |
public static int GDT_Float64 = 7; // Buffer double (64) |
|
47 |
public static int GDT_CInt16 = 8; // Buffer short (16) |
|
48 |
public static int GDT_CInt32 = 9; // Buffer int (32) |
|
49 |
public static int GDT_CFloat32 = 10; // Buffer float (32) |
|
50 |
public static int GDT_CFloat64 = 11; // Buffer double (64) |
|
93 | 51 |
public static int GDT_TypeCount = 12; |
94 |
|
|
95 |
private String pszFilename = "";
|
|
96 |
|
|
52 |
|
|
53 |
private String pszFilename = "";
|
|
54 |
|
|
97 | 55 |
private native long openNat(String pszFilename, int access); |
98 | 56 |
private native long openArrayNat(byte[] pszFilename, int access); |
99 |
private native int getGeoTransformNat(long cPtr,GeoTransform adfgeotransform); |
|
100 |
private native int setGeoTransformNat(long cPtr,GeoTransform adfgeotransform); |
|
101 |
private native String[] getMetadataNat(long cPtr,String pszDomain); |
|
57 |
private native int getGeoTransformNat(long cPtr, GeoTransform adfgeotransform);
|
|
58 |
private native int setGeoTransformNat(long cPtr, GeoTransform adfgeotransform);
|
|
59 |
private native String[] getMetadataNat(long cPtr, String pszDomain);
|
|
102 | 60 |
private native String getProjectionRefNat(long cPtr); |
103 | 61 |
private native void closeNat(long cPtr); |
104 |
private native int getRasterBandNat(long cPtr,int hBand); |
|
62 |
private native int getRasterBandNat(long cPtr, int hBand);
|
|
105 | 63 |
private native int setProjectionNat(long cPtr, String proj); |
106 | 64 |
private native String getDriverShortNameNat(long cPtr); |
107 | 65 |
|
... | ... | |
110 | 68 |
private native String getColorInterpretationNameNat(long cPtr, int colorInterp); |
111 | 69 |
|
112 | 70 |
/** |
113 |
*Constructor a partir de la direcci�n de memoria
|
|
71 |
*Constructor a partir de la direcci?n de memoria
|
|
114 | 72 |
*/ |
115 | 73 |
public Gdal(long cPtr){ |
116 | 74 |
this.cPtr=cPtr; |
... | ... | |
122 | 80 |
public Gdal(){} |
123 | 81 |
|
124 | 82 |
/** |
125 |
* Devuelve la direcci�n de memoria del objeto dataset en C.
|
|
83 |
* Devuelve la direcci?n de memoria del objeto dataset en C.
|
|
126 | 84 |
*/ |
127 | 85 |
public long getPtro(){return cPtr;} |
128 | 86 |
|
129 | 87 |
/** |
130 |
* Abre el fichero de im�gen.
|
|
88 |
* Abre el fichero de imagen.
|
|
131 | 89 |
* |
132 | 90 |
* @param pszFilename Nombre del fichero. |
133 | 91 |
* @param access Apertura en solo lectura o escritura. |
... | ... | |
136 | 94 |
public void open(String pszFilename, int access)throws GdalException, IOException { |
137 | 95 |
File f = new File( pszFilename ); |
138 | 96 |
if(!f.exists()) |
139 |
throw new GdalException("El archivo "+pszFilename+" no existe");
|
|
140 |
|
|
141 |
if(!f.canRead())
|
|
142 |
throw new GdalException("El archivo no puede leerse");
|
|
143 |
|
|
144 |
if ((access < 0) || (access > 1))
|
|
145 |
throw new GdalException("Tipo de acceso al dataset incorrecto");
|
|
97 |
throw new GdalException("El archivo "+pszFilename+" no existe");
|
|
98 |
|
|
99 |
if(!f.canRead())
|
|
100 |
throw new GdalException("El archivo no puede leerse");
|
|
101 |
|
|
102 |
if ((access < 0) || (access > 1))
|
|
103 |
throw new GdalException("Tipo de acceso al dataset incorrecto");
|
|
146 | 104 |
|
147 |
cPtr=openArrayNat(pszFilename.getBytes(), access);
|
|
148 |
|
|
149 |
if (cPtr == 0)
|
|
150 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
105 |
cPtr=openArrayNat(pszFilename.getBytes(), access);
|
|
106 |
|
|
107 |
if (cPtr == 0)
|
|
108 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
151 | 109 |
} |
152 | 110 |
|
153 | 111 |
/** |
154 | 112 |
* Obtiene un array de Strings con los metadatos |
155 | 113 |
* |
156 | 114 |
* @throws GdalException |
157 |
* @return Array de Strings que corresponden a los metadatos que ofrece la im�gen
|
|
115 |
* @return Array de Strings que corresponden a los metadatos que ofrece la imagen
|
|
158 | 116 |
*/ |
159 | 117 |
public String[] getMetadata()throws GdalException { |
160 | 118 |
return getMetadata(null); |
... | ... | |
166 | 124 |
* Obtiene un array de Strings con los metadatos |
167 | 125 |
* |
168 | 126 |
* @throws GdalException |
169 |
* @return Array de Strings que corresponden a los metadatos que ofrece la im�gen
|
|
127 |
* @return Array de Strings que corresponden a los metadatos que ofrece la imagen
|
|
170 | 128 |
*/ |
171 | 129 |
public String[] getMetadata(String domain)throws GdalException { |
172 | 130 |
String[] res = getMetadataNat(cPtr, domain); |
... | ... | |
177 | 135 |
} |
178 | 136 |
|
179 | 137 |
/** |
180 |
* Obtiene el n�mero de bandas de la im�gen
|
|
138 |
* Obtiene el n?mero de bandas de la imagen
|
|
181 | 139 |
* |
182 | 140 |
* @throws GdalException |
183 |
* @param hBand Entero que corresponde al n�mero de banda que se quiere recuperar
|
|
141 |
* @param hBand Entero que corresponde al n?mero de banda que se quiere recuperar
|
|
184 | 142 |
* @return Objeto GdalRasterBand que representa la banda recuperada |
185 | 143 |
*/ |
186 | 144 |
|
... | ... | |
191 | 149 |
throw new GdalException("Banda seleccionada incorrecta"); |
192 | 150 |
|
193 | 151 |
if (cPtr == 0) |
194 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
152 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
195 | 153 |
|
196 | 154 |
cPtr_rb = getRasterBandNat(cPtr,hBand); |
197 | 155 |
|
... | ... | |
201 | 159 |
|
202 | 160 |
|
203 | 161 |
/** |
204 |
* Obtiene la dimensi�n del raster en el eje X.
|
|
162 |
* Obtiene la dimensi?n del raster en el eje X.
|
|
205 | 163 |
* |
206 |
* @return Devuelve un entero con la longitud de la im�gen en el eje X en pixels.
|
|
164 |
* @return Devuelve un entero con la longitud de la imagen en el eje X en pixels.
|
|
207 | 165 |
* @throws GdalException |
208 | 166 |
*/ |
209 | 167 |
public int getRasterXSize()throws GdalException { |
210 |
String msg1="Error en GDALGetRasterXSize. La llamada GDALOpen no tuvo �xito";
|
|
211 |
String msg2="Error en tama�o X";
|
|
168 |
String msg1="Error en GDALGetRasterXSize. La llamada GDALOpen no tuvo ?xito";
|
|
169 |
String msg2="Error en tama?o X";
|
|
212 | 170 |
return baseSimpleFunctions(5,msg1,msg2); |
213 | 171 |
} |
214 | 172 |
|
215 | 173 |
|
216 | 174 |
/** |
217 |
* Obtiene la dimensi�n del raster en el eje Y.
|
|
175 |
* Obtiene la dimensi?n del raster en el eje Y.
|
|
218 | 176 |
* |
219 |
* @return Devuelve un entero con la longitud de la im�gen en el eje Y en pixels.
|
|
177 |
* @return Devuelve un entero con la longitud de la imagen en el eje Y en pixels.
|
|
220 | 178 |
* @throws GdalException |
221 | 179 |
*/ |
222 | 180 |
public int getRasterYSize()throws GdalException { |
223 |
String msg1="Error en GDALGetRasterYSize. La llamada GDALOpen no tuvo �xito";
|
|
224 |
String msg2="Error en tama�o Y";
|
|
181 |
String msg1="Error en GDALGetRasterYSize. La llamada GDALOpen no tuvo ?xito";
|
|
182 |
String msg2="Error en tama?o Y";
|
|
225 | 183 |
return baseSimpleFunctions(6,msg1,msg2); |
226 | 184 |
} |
227 | 185 |
|
228 | 186 |
|
229 | 187 |
/** |
230 |
* Obtiene el n�mero de bandas de la im�gen
|
|
188 |
* Obtiene el n?mero de bandas de la imagen
|
|
231 | 189 |
* |
232 |
* @return Devuelve un entero con el n�mero de bandas que contiene la im�gen.
|
|
190 |
* @return Devuelve un entero con el n?mero de bandas que contiene la imagen.
|
|
233 | 191 |
* @throws GdalException |
234 | 192 |
*/ |
235 | 193 |
public int getRasterCount()throws GdalException { |
236 |
String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo �xito";
|
|
237 |
String msg2="Error en el conteo de n�mero de bandas";
|
|
194 |
String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito";
|
|
195 |
String msg2="Error en el conteo de n?mero de bandas";
|
|
238 | 196 |
return baseSimpleFunctions(7,msg1,msg2); |
239 | 197 |
} |
240 | 198 |
|
241 | 199 |
|
242 | 200 |
/** |
243 |
* Obtiene el vector geoTransform de la im�gen que contiene los valores Origen y pixelSize
|
|
201 |
* Obtiene el vector geoTransform de la imagen que contiene los valores Origen y pixelSize
|
|
244 | 202 |
* |
245 | 203 |
* @return Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize. |
246 | 204 |
* @throws GdalException |
... | ... | |
249 | 207 |
GeoTransform gt=new GeoTransform(); |
250 | 208 |
|
251 | 209 |
if (cPtr == 0) |
252 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
210 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
253 | 211 |
|
254 | 212 |
if(getGeoTransformNat(cPtr,gt) < 0) |
255 | 213 |
throw new GdalException("Error en getGeoTransform(). No se han obtenido valores para geoTransform."); |
... | ... | |
266 | 224 |
*/ |
267 | 225 |
public String getDriverShortName()throws GdalException { |
268 | 226 |
if (cPtr == 0) |
269 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
227 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
270 | 228 |
|
271 | 229 |
String shortName = getDriverShortNameNat(cPtr); |
272 | 230 |
|
... | ... | |
277 | 235 |
} |
278 | 236 |
|
279 | 237 |
/** |
280 |
* A�ade el vector geoTransform a la im�gen que contiene los valores Origen y pixelSize
|
|
238 |
* A?ade el vector geoTransform a la imagen que contiene los valores Origen y pixelSize
|
|
281 | 239 |
* |
282 | 240 |
* @return Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize. |
283 | 241 |
* @throws GdalException |
284 | 242 |
*/ |
285 | 243 |
public void setGeoTransform(GeoTransform gt)throws GdalException { |
286 | 244 |
if (cPtr == 0) |
287 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
245 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
288 | 246 |
if (gt == null) |
289 | 247 |
throw new GdalException("el objeto " + gt.getClass().getName() + " es null"); |
290 | 248 |
|
... | ... | |
292 | 250 |
} |
293 | 251 |
|
294 | 252 |
/** |
295 |
* Obtiene el sistema de coordenadas de referencia de la im�gen.
|
|
253 |
* Obtiene el sistema de coordenadas de referencia de la imagen.
|
|
296 | 254 |
* |
297 | 255 |
* @return Devuelve un String con los datos del sistema de coordenadas de referencia. |
298 | 256 |
* @throws GdalException |
299 | 257 |
*/ |
300 | 258 |
public String getProjectionRef()throws GdalException { |
301 | 259 |
if (cPtr == 0) |
302 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
260 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
303 | 261 |
|
304 | 262 |
String res = getProjectionRefNat(cPtr); |
305 | 263 |
|
... | ... | |
308 | 266 |
} |
309 | 267 |
|
310 | 268 |
/** |
311 |
* Cierra el fichero de im�gen.
|
|
269 |
* Cierra el fichero de imagen.
|
|
312 | 270 |
* |
313 | 271 |
* @throws GdalException |
314 | 272 |
*/ |
315 | 273 |
public void close()throws GdalException { |
316 | 274 |
if (cPtr == 0) |
317 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
275 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
318 | 276 |
|
319 | 277 |
closeNat(cPtr); |
320 | 278 |
} |
321 | 279 |
|
322 | 280 |
/** |
323 |
* Obtiene un driver a trav�s de su nombre
|
|
281 |
* Obtiene un driver a trav?s de su nombre
|
|
324 | 282 |
* |
325 | 283 |
* @param name Nombre del driver |
326 | 284 |
*/ |
... | ... | |
337 | 295 |
|
338 | 296 |
|
339 | 297 |
/** |
340 |
* Obtiene el n�mero de bandas de la im�gen
|
|
298 |
* Obtiene el numero de bandas de la imagen
|
|
341 | 299 |
* |
342 |
* @return Devuelve un entero con el n�mero de bandas que contiene la im�gen.
|
|
300 |
* @return Devuelve un entero con el numero de bandas que contiene la imagen.
|
|
343 | 301 |
* @throws GdalException |
344 | 302 |
*/ |
345 | 303 |
public int getGCPCount()throws GdalException { |
346 |
String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo �xito";
|
|
347 |
String msg2="Error en el conteo de n�mero de bandas";
|
|
304 |
String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito";
|
|
305 |
String msg2="Error en el conteo de n?mero de bandas";
|
|
348 | 306 |
return baseSimpleFunctions(8,msg1,msg2); |
349 | 307 |
} |
350 | 308 |
|
351 | 309 |
/** |
352 |
*Asigna la proyecci�n especificada en la cadena que se le pasa por par�metro.
|
|
353 |
*@param proj proyecci�n
|
|
310 |
*Asigna la proyecci?n especificada en la cadena que se le pasa por par?metro.
|
|
311 |
*@param proj proyecci?n
|
|
354 | 312 |
*@throws GdalException |
355 | 313 |
*/ |
356 | 314 |
public void setProjection(String proj)throws GdalException { |
357 | 315 |
if (cPtr == 0) |
358 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
316 |
throw new GdalException("No se ha podido acceder al archivo.");
|
|
359 | 317 |
if (proj == null) |
360 |
throw new GdalException("La proyeccion es null");
|
|
318 |
throw new GdalException("La proyeccion es null");
|
|
361 | 319 |
|
362 | 320 |
int res = setProjectionNat(cPtr, proj); |
363 | 321 |
|
364 | 322 |
if(res < 0) |
365 |
throw new GdalException("Error en setProjection(). No se ha podido asignar la proyecci�n.");
|
|
323 |
throw new GdalException("Error en setProjection(). No se ha podido asignar la proyecci?n.");
|
|
366 | 324 |
} |
367 | 325 |
|
368 | 326 |
/** |
Also available in: Unified diff