Revision 22081
trunk/libraries/libjni-gdal/src/main/java/es/gva/cit/jgdal/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 |
/** |
trunk/libraries/libjni-gdal/src/main/java/es/gva/cit/jgdal/JNIBase.java | ||
---|---|---|
102 | 102 |
case 8: res = getGCPCountNat(cPtr);break; |
103 | 103 |
case 9: res = getRasterDataTypeNat(cPtr);break; |
104 | 104 |
} |
105 |
|
|
106 |
if(res<0) |
|
107 |
throw new GdalException(msg2); |
|
108 |
else return res; |
|
105 |
|
|
106 |
if (res < 0) |
|
107 |
throw new GdalException(msg2); |
|
108 |
else |
|
109 |
return res; |
|
109 | 110 |
} |
110 | 111 |
|
111 |
|
|
112 |
|
|
113 |
static{ |
|
112 |
static { |
|
114 | 113 |
String os = System.getProperty("os.name"); |
115 |
if(os.toLowerCase().startsWith("windows")) |
|
116 |
System.loadLibrary("jgdal080");
|
|
114 |
if (os.toLowerCase().startsWith("windows"))
|
|
115 |
System.loadLibrary("jgdal090");
|
|
117 | 116 |
else |
118 | 117 |
System.loadLibrary("jgdal"); |
119 | 118 |
} |
120 |
|
|
121 |
} |
|
119 |
} |
trunk/libraries/libjni-gdal/src/main/java/es/gva/cit/jgdal/DiagSignalHandler.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
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 |
*/ |
|
1 | 19 |
package es.gva.cit.jgdal; |
2 |
import sun.misc.Signal; |
|
3 |
import sun.misc.SignalHandler; |
|
4 |
import java.lang.reflect.*; |
|
20 |
import java.awt.BorderLayout; |
|
5 | 21 |
import java.awt.event.ActionEvent; |
6 | 22 |
import java.awt.event.ActionListener; |
7 |
import java.io.IOException; |
|
23 |
|
|
24 |
import javax.swing.JButton; |
|
8 | 25 |
import javax.swing.JFrame; |
26 |
import javax.swing.JLabel; |
|
9 | 27 |
import javax.swing.JPanel; |
10 |
import javax.swing.JButton; |
|
11 |
import java.awt.BorderLayout; |
|
12 |
import javax.swing.JLabel; |
|
13 | 28 |
|
29 |
import sun.misc.Signal; |
|
30 |
import sun.misc.SignalHandler; |
|
31 |
|
|
14 | 32 |
class DiagSignalHandler implements SignalHandler { |
15 |
|
|
16 |
private SignalHandler oldHandler;
|
|
17 |
private static boolean active = false;
|
|
33 |
|
|
34 |
private SignalHandler oldHandler;
|
|
35 |
private static boolean active = false;
|
|
18 | 36 |
|
19 |
//Static method to install the signal handler
|
|
20 |
public static DiagSignalHandler install(String signalName) {
|
|
21 |
Signal diagSignal = new Signal(signalName);
|
|
22 |
DiagSignalHandler diagHandler = new DiagSignalHandler();
|
|
23 |
diagHandler.oldHandler = Signal.handle(diagSignal,diagHandler);
|
|
24 |
return diagHandler;
|
|
25 |
}
|
|
26 |
// Signal handler method
|
|
27 |
public void handle(Signal sig) {
|
|
37 |
//Static method to install the signal handler
|
|
38 |
public static DiagSignalHandler install(String signalName) {
|
|
39 |
Signal diagSignal = new Signal(signalName);
|
|
40 |
DiagSignalHandler diagHandler = new DiagSignalHandler();
|
|
41 |
diagHandler.oldHandler = Signal.handle(diagSignal,diagHandler);
|
|
42 |
return diagHandler;
|
|
43 |
}
|
|
44 |
// Signal handler method
|
|
45 |
public void handle(Signal sig) {
|
|
28 | 46 |
if(active) |
29 |
return;
|
|
47 |
return;
|
|
30 | 48 |
active = true; |
31 | 49 |
JFrame frame = new JFrame(); |
32 | 50 |
frame.setSize(400, 150); |
... | ... | |
44 | 62 |
|
45 | 63 |
frame.getContentPane().add(p); |
46 | 64 |
frame.show(); |
47 |
}
|
|
65 |
}
|
|
48 | 66 |
} |
trunk/libraries/libjni-gdal/src/main/java/es/gva/cit/jgdal/GdalGCP.java | ||
---|---|---|
1 |
/********************************************************************** |
|
2 |
* $Id: GdalGCP.java 7765 2006-10-03 07:05:18Z nacho $ |
|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 | 2 |
* |
4 |
* Name: GdalGCP.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 |
|
|
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 |
*/ |
|
51 | 19 |
package es.gva.cit.jgdal; |
52 |
|
|
53 |
|
|
54 |
import java.io.*; |
|
55 |
import java.util.Date; |
|
56 |
|
|
57 |
|
|
58 | 20 |
/** |
59 | 21 |
* Contiene las funcionalidades necesarias para el acceso a los |
60 | 22 |
* elementos de un dataset de gdal correspondiente a una im?gen |
61 | 23 |
* |
62 | 24 |
* @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es |
63 |
* @version 0.0 |
|
64 | 25 |
* @link http://www.gvsig.gva.es |
65 | 26 |
*/ |
66 |
|
|
67 | 27 |
public class GdalGCP extends JNIBase{ |
68 | 28 |
|
69 | 29 |
private native long GdalGCPNat(); |
trunk/libraries/libjni-gdal/src/main/java/es/gva/cit/jgdal/GdalWarp.java | ||
---|---|---|
1 | 1 |
package es.gva.cit.jgdal; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
|
|
3 | 5 |
/** |
6 |
* Clase que recubre la funci?n de reproyecci?n de gdal. |
|
7 |
* |
|
4 | 8 |
* @author Miguel ?ngel Querol Carratal? |
5 |
* Clase que recubre la funci?n de reproyecci?n de gdal. |
|
6 | 9 |
*/ |
7 |
public class GdalWarp extends JNIBase{ |
|
8 |
|
|
9 |
private int porcentaje; |
|
10 |
|
|
11 |
|
|
10 |
public class GdalWarp extends JNIBase { |
|
11 |
private int porcentaje; |
|
12 |
|
|
12 | 13 |
/** |
13 | 14 |
* Par?metros de la operaci?n de reproyecci?n |
14 | 15 |
*/ |
15 |
|
|
16 |
|
|
17 |
private String s_srs = null; |
|
18 |
private String format = "GTiff"; |
|
19 |
|
|
20 |
public static final int GTiff_FORMAT = 1; |
|
21 |
public static final int VRT_FORMAT = 2; |
|
22 |
public static final int NITF_FORMAT = 3; |
|
23 |
public static final int HFA_FORMAT = 4; |
|
24 |
public static final int ELAS_FORMAT = 5; |
|
25 |
public static final int MEM_FORMAT = 6; |
|
26 |
public static final int BMP_FORMAT = 7; |
|
27 |
public static final int PCIDSK_FORMAT = 8; |
|
28 |
public static final int ILWIS_FORMAT = 9; |
|
29 |
public static final int HDF4_FORMAT = 10; |
|
30 |
public static final int PNM_FORMAT = 11; |
|
31 |
public static final int ENVI_FORMAT = 12; |
|
32 |
public static final int EHDR_FORMAT = 13; |
|
33 |
public static final int PAUX_FORMAT = 14; |
|
34 |
public static final int MFF_FORMAT = 15; |
|
35 |
public static final int MFF2_FORMAT = 16; |
|
36 |
public static final int BT_FORMAT = 17; |
|
37 |
public static final int IDA_FORMAT = 18; |
|
38 |
public static final int RMF_FORMAT = 19; |
|
39 |
public static final int RST_FORMAT = 20; |
|
40 |
|
|
41 |
|
|
16 |
private String s_srs = null; |
|
42 | 17 |
|
43 | 18 |
/** |
44 | 19 |
* M?todo nativo para el warp desde gdal. |
45 | 20 |
*/ |
46 |
|
|
47 | 21 |
private native int warpDataset(String s_srs, String t_srs, String source, String dest, String format); |
48 |
|
|
22 |
|
|
49 | 23 |
/** |
50 | 24 |
* Constructor generico. |
51 |
* |
|
52 | 25 |
*/ |
53 |
public GdalWarp(){ |
|
54 |
} |
|
55 |
|
|
26 |
public GdalWarp() {} |
|
27 |
|
|
56 | 28 |
/** |
57 | 29 |
* Reproyecta una imagen raster, creando una imagen de salida |
58 | 30 |
* @param proj EPSG:code o proj4 |
... | ... | |
62 | 34 |
* @return 0 si ha ocurrido algun error o 1 si la ejecuci?n ha sido correcta. |
63 | 35 |
* @throws GdalException |
64 | 36 |
*/ |
65 |
public int warp(String t_srs, String source, String dest) throws GdalException{ |
|
37 |
public int warp(String t_srs, String source, String dest, String format) throws GdalException{
|
|
66 | 38 |
|
67 | 39 |
int stat = warpDataset(s_srs, t_srs, source, dest, format); |
68 | 40 |
|
... | ... | |
71 | 43 |
|
72 | 44 |
return stat; |
73 | 45 |
} |
74 |
|
|
75 |
|
|
76 |
public void setFormat(int frm){ |
|
77 |
switch(frm) { |
|
78 |
case 1: format = "GTiff"; |
|
79 |
break; |
|
80 |
case 2: format = "VRT"; |
|
81 |
break; |
|
82 |
case 3: format = "NITF"; |
|
83 |
break; |
|
84 |
case 4: format = "HFA"; |
|
85 |
break; |
|
86 |
case 5: format = "ELAS"; |
|
87 |
break; |
|
88 |
case 6: format = "MEM"; |
|
89 |
break; |
|
90 |
case 7: format = "BMP"; |
|
91 |
break; |
|
92 |
case 8: format = "PCIDSK"; |
|
93 |
break; |
|
94 |
case 9: format = "ILWIS"; |
|
95 |
break; |
|
96 |
case 10: format = "HDF4Image"; |
|
97 |
break; |
|
98 |
case 11: format = "PNM"; |
|
99 |
break; |
|
100 |
case 12: format = "ENVI"; |
|
101 |
break; |
|
102 |
case 13: format = "EHdr"; |
|
103 |
break; |
|
104 |
case 14: format = "PAux"; |
|
105 |
break; |
|
106 |
case 15: format = "MFF"; |
|
107 |
break; |
|
108 |
case 16: format = "MFF2"; |
|
109 |
break; |
|
110 |
case 17: format = "BT"; |
|
111 |
break; |
|
112 |
case 18: format = "IDA"; |
|
113 |
break; |
|
114 |
case 19: format = "RMF"; |
|
115 |
break; |
|
116 |
case 20: format = "RST"; |
|
117 |
break; |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
|
|
46 |
|
|
122 | 47 |
/** |
123 | 48 |
* Indica la proyecci?n del dataset origen |
124 | 49 |
* @param s_srs |
125 | 50 |
*/ |
126 |
public void setSsrs(String s_srs){ |
|
51 |
public void setSsrs(String s_srs) {
|
|
127 | 52 |
this.s_srs = s_srs; |
128 | 53 |
} |
129 |
|
|
130 |
|
|
54 |
|
|
131 | 55 |
/** |
132 | 56 |
* Obtiene el porcentaje de proceso que se ha completado |
133 | 57 |
*/ |
134 |
public int getPercent(){ |
|
58 |
public int getPercent() {
|
|
135 | 59 |
return porcentaje; |
136 | 60 |
} |
137 | 61 |
|
62 |
/** |
|
63 |
* Devuelve la lista de drivers que usa GdalWarp para reproyectar |
|
64 |
* @return |
|
65 |
*/ |
|
66 |
static public ArrayList getDrivers() { |
|
67 |
ArrayList list = new ArrayList(); |
|
68 |
list.add("GTiff"); |
|
69 |
list.add("VRT"); |
|
70 |
list.add("NITF"); |
|
71 |
list.add("HFA"); |
|
72 |
list.add("ELAS"); |
|
73 |
list.add("MEM"); |
|
74 |
list.add("BMP"); |
|
75 |
list.add("PCIDSK"); |
|
76 |
list.add("ILWIS"); |
|
77 |
String os = System.getProperty("os.name"); |
|
78 |
if (!os.toLowerCase().startsWith("windows")) |
|
79 |
list.add("HDF4Image"); |
|
80 |
list.add("PNM"); |
|
81 |
list.add("ENVI"); |
|
82 |
list.add("EHdr"); |
|
83 |
list.add("PAux"); |
|
84 |
list.add("MFF"); |
|
85 |
list.add("MFF2"); |
|
86 |
list.add("BT"); |
|
87 |
list.add("IDA"); |
|
88 |
list.add("RMF"); |
|
89 |
list.add("RST"); |
|
90 |
list.add("Leveller"); |
|
91 |
list.add("Terragen"); |
|
92 |
list.add("ERS"); |
|
93 |
list.add("INGR"); |
|
94 |
list.add("GSAG"); |
|
95 |
list.add("GSBG"); |
|
96 |
list.add("ADRG"); |
|
97 |
return list; |
|
98 |
} |
|
138 | 99 |
} |
trunk/libraries/libjni-gdal/src/main/java/org/gvsig/jogr/JNIBase.java | ||
---|---|---|
180 | 180 |
case 7:throw new OGRUnsupportedSRSException(mensaje); |
181 | 181 |
default : return; |
182 | 182 |
} |
183 |
|
|
184 | 183 |
} |
185 | 184 |
|
186 | 185 |
/** |
187 | 186 |
* Obtiene el puntero a C del objeto |
188 |
* @param cPtr long con la direcci?n de memoria del objeto
|
|
187 |
* @param cPtr long con la direcci?n de memoria del objeto
|
|
189 | 188 |
*/ |
190 |
|
|
191 |
public long getPtro(){ |
|
189 |
public long getPtro() { |
|
192 | 190 |
return cPtr; |
193 | 191 |
} |
194 |
|
|
195 |
static{ |
|
192 |
|
|
193 |
static {
|
|
196 | 194 |
String os = System.getProperty("os.name"); |
197 |
if(os.toLowerCase().startsWith("windows")) |
|
198 |
System.loadLibrary("jgdal080");
|
|
195 |
if (os.toLowerCase().startsWith("windows"))
|
|
196 |
System.loadLibrary("jgdal090");
|
|
199 | 197 |
else |
200 | 198 |
System.loadLibrary("jgdal"); |
201 | 199 |
} |
202 |
|
|
203 |
} |
|
200 |
} |
trunk/libraries/libjni-gdal/src/test/java/es/gva/cit/jgdal/TestWarpDataset.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
import junit.framework.TestCase; |
7 | 7 |
|
8 |
public class TestWarpDataset extends TestCase{ |
|
8 |
public class TestWarpDataset extends TestCase { |
|
9 |
private GdalWarp warp = null; |
|
10 |
private String baseDir = "./test-images/"; |
|
11 |
private String src = baseDir + "testGdalWarp.tif"; |
|
12 |
private String dst = baseDir + "warpedImage.tif"; |
|
13 |
private String frm = "GTiff"; |
|
14 |
private String t_srs = "EPSG:23030"; |
|
9 | 15 |
|
10 |
private GdalWarp warp = null; |
|
11 |
|
|
12 |
private String baseDir = "./test-images/"; |
|
13 |
|
|
14 |
private String src = baseDir + "testGdalWarp.tif"; |
|
15 |
private String dst = baseDir + "warpedImage.tif"; |
|
16 |
private String frm = "GTiff"; |
|
17 |
private String t_srs = "EPSG:23030"; |
|
18 |
|
|
19 |
|
|
20 |
public void start(){ |
|
16 |
public void start() { |
|
21 | 17 |
setUp(); |
22 | 18 |
testStack(); |
23 | 19 |
} |
24 |
|
|
25 |
public void setUp(){ |
|
20 |
|
|
21 |
public void setUp() {
|
|
26 | 22 |
warp = new GdalWarp(); |
27 | 23 |
File f = new File(src); |
28 | 24 |
Gdal dataset = new Gdal(); |
29 |
|
|
30 |
|
|
25 |
|
|
31 | 26 |
try { |
32 | 27 |
assertTrue("El fichero no existe", f.exists()); |
33 | 28 |
assertTrue("El fichero no se puede leer", f.canRead()); |
... | ... | |
42 | 37 |
} |
43 | 38 |
} |
44 | 39 |
|
45 |
public void testStack(){ |
|
46 |
|
|
40 |
public void testStack() { |
|
47 | 41 |
assertNotNull(t_srs); |
48 |
warp.setFormat(GdalWarp.GTiff_FORMAT); |
|
49 |
|
|
50 | 42 |
try { |
51 |
warp.warp(t_srs, src, dst); |
|
43 |
warp.warp(t_srs, src, dst, frm);
|
|
52 | 44 |
System.err.println("Proceso completado al " + warp.getPercent() + " %"); |
53 | 45 |
} catch (GdalException e) { |
54 | 46 |
new AssertionError("Fallo al repryectar"); |
55 | 47 |
e.printStackTrace(); |
56 | 48 |
} |
57 | 49 |
|
58 |
|
|
59 |
|
|
60 | 50 |
File f = new File(dst); |
61 |
|
|
51 |
|
|
62 | 52 |
assertTrue("El fichero destino no existe", f.exists()); |
63 | 53 |
assertTrue("El fichero destino no se puede leer", f.canRead()); |
64 | 54 |
} |
65 |
|
|
66 |
|
|
67 | 55 |
} |
Also available in: Unified diff