Revision 10988 branches/v10/libraries/libjni-gdal/src/es/gva/cit/jgdal/Gdal.java

View differences:

Gdal.java
55 55

  
56 56
import java.io.*;
57 57
import java.util.Date;
58
import sun.misc.Signal;
59
import sun.misc.SignalHandler;
60
import java.lang.reflect.*;
58 61

  
59 62
//import es.gva.cit.jgdal.GdalException;
60 63

  
......
68 71
 */
69 72

  
70 73
public class Gdal extends JNIBase{
71
	
72
		
73 74
	//CONSTANTES
74 75
	
75 76
	//GDALAccess
......
111 112
	/**
112 113
	 *Constructor a partir de la direcci?n de memoria 
113 114
	 */
114
	
115 115
	public Gdal(long cPtr){
116 116
		this.cPtr=cPtr;
117 117
	}
......
119 119
	/**
120 120
	 *Constructor generico
121 121
	 */
122
	
123 122
	public Gdal(){}
124 123
	
125 124
	/**
126 125
	 * Devuelve la direcci?n de memoria del objeto dataset en C.
127 126
	 */
128
	
129 127
	public long getPtro(){return cPtr;}
130 128
	
131 129
	/**
......
135 133
	 * @param access	Apertura en solo lectura o escritura.
136 134
	 * @throws GdalException
137 135
	 */
138
	
139
	public void open(String pszFilename, int access)throws GdalException, IOException{
140
			
136
	public void open(String pszFilename, int access)throws GdalException, IOException {
141 137
		File f = new File( pszFilename );
142 138
		if(!f.exists())
143
		  throw new IOException("El archivo "+pszFilename+" no existe");
139
		  throw new GdalException("El archivo "+pszFilename+" no existe");
144 140
		  
145 141
	    if(!f.canRead())
146
	      throw new IOException("El archivo no puede leerse");
142
	      throw new GdalException("El archivo no puede leerse");
143

  
144
	    /*String os = System.getProperty("os.name");
145
		if(os.toLowerCase().startsWith("windows"))
146
			DiagSignalHandler.install("ABRT");
147
		else
148
			DiagSignalHandler.install("ALRM");*/
149
	    //DiagSignalHandler.install("ALRM");
147 150
	
148 151
	    cPtr=openArrayNat(pszFilename.getBytes(), access);
149 152
	    //cPtr=openNat(pszFilename, access);
150
	    
151
	    if(cPtr<=0)
152
	    	throw new GdalException("Error en Open de GDAL");
153
	 
154 153
	}
155 154
	
156 155
	/**
......
159 158
	 * @throws GdalException
160 159
	 * @return Array de Strings que corresponden a los metadatos que ofrece la im?gen
161 160
	 */
162
	
163
	public String[] getMetadata()throws GdalException{
164
		
165
			
166
		if(cPtr <= 0)
167
			throw new GdalException("Error en GDALGetMetadata(). La llamada GDALOpen no tuvo exito");
161
	public String[] getMetadata()throws GdalException {
168 162
		String[] res = getMetadataNat(cPtr,null);
169 163
		if(res == null)
170 164
			return new String[0];
......
180 174
	 * @return Objeto GdalRasterBand que representa la banda recuperada	
181 175
	 */
182 176
	
183
	public GdalRasterBand getRasterBand(int hBand)throws GdalException{
184
		
177
	public GdalRasterBand getRasterBand(int hBand)throws GdalException {
185 178
		long cPtr_rb;
186
		
187
		if(cPtr <= 0)
188
			throw new GdalException("Error en GDALGetRasterBand(). La llamada GDALOpen no tuvo exito");
189
		    	
179
			
190 180
		cPtr_rb = getRasterBandNat(cPtr,hBand);
191 181
		
192
		if(cPtr_rb < 0)
193
			throw new GdalException("Error en GetRasterBand(). No ha podido obtenerse una banda");
194
		else return new GdalRasterBand(cPtr_rb);
195
				
182
		return new GdalRasterBand(cPtr_rb);	
196 183
	}
197 184
	
198 185
		
......
203 190
	 * @return	Devuelve un entero con la longitud de la im?gen en el eje X en pixels.
204 191
	 * @throws GdalException 
205 192
	 */
206
	
207
	public int getRasterXSize()throws GdalException{
208
		
193
	public int getRasterXSize()throws GdalException {
209 194
		String msg1="Error en GDALGetRasterXSize. La llamada GDALOpen no tuvo ?xito";
210 195
		String msg2="Error en tama?o X";
211 196
		return baseSimpleFunctions(5,msg1,msg2);
212
		
213 197
	}
214 198
		
215 199
	
......
219 203
	 * @return	Devuelve un entero con la longitud de la im?gen en el eje Y en pixels.
220 204
	 * @throws GdalException 
221 205
	 */
222
	
223
	public int getRasterYSize()throws GdalException{
224
		
206
	public int getRasterYSize()throws GdalException {
225 207
		String msg1="Error en GDALGetRasterYSize. La llamada GDALOpen no tuvo ?xito";
226 208
		String msg2="Error en tama?o Y";
227 209
		return baseSimpleFunctions(6,msg1,msg2);
228
		
229 210
	}
230 211
	
231 212
	
......
235 216
	 * @return	Devuelve un entero con el n?mero de bandas que contiene la im?gen.
236 217
	 * @throws GdalException
237 218
	 */
238
	
239
	public int getRasterCount()throws GdalException{
240
		
219
	public int getRasterCount()throws GdalException {
241 220
		String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito";
242 221
		String msg2="Error en el conteo de n?mero de bandas";
243 222
		return baseSimpleFunctions(7,msg1,msg2);
244
		
245 223
	}
246 224
	
247 225
	
......
251 229
	 * @return	Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize.
252 230
	 * @throws GdalException
253 231
	 */
254
	
255
	public GeoTransform getGeoTransform()throws GdalException{
256
		
257
				
258
		if(cPtr <= 0)
259
			throw new GdalException("Error en getGeoTransform(). La llamada Open no tuvo exito");
260
		
232
	public GeoTransform getGeoTransform()throws GdalException {
261 233
		GeoTransform gt=new GeoTransform();
262 234
		
263
		if(getGeoTransformNat(cPtr,gt)<0)
235
		if(getGeoTransformNat(cPtr,gt) < 0)
264 236
			throw new GdalException("Error en getGeoTransform(). No se han obtenido valores para geoTransform.");
265 237
		else{
266 238
	
......
274 246
	 * @return	Cadena con el nombre del driver
275 247
	 * @throws GdalException
276 248
	 */
277
	
278
	public String getDriverShortName()throws GdalException{
279
		
280
				
281
		if(cPtr <= 0)
282
			throw new GdalException("Error en getDriverShortName(). La llamada Open no tuvo exito");
249
	public String getDriverShortName()throws GdalException {
283 250
		String shortName = getDriverShortNameNat(cPtr);
284 251
		
285 252
		if(shortName == null)
286 253
			throw new GdalException("Error en getDriverShortName(). No ha podido obtenerse el driver");
287 254
		else 
288 255
			return shortName;
289
		
290 256
	}
291 257
	
292 258
	/**
......
295 261
	 * @return	Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize.
296 262
	 * @throws GdalException
297 263
	 */
298
	
299
	public void setGeoTransform(GeoTransform gt)throws GdalException{
300
		
301
				
302
		if(cPtr <= 0)
303
			throw new GdalException("Error en setGeoTransform(). La llamada Open no tuvo exito");		
304
		
264
	public void setGeoTransform(GeoTransform gt)throws GdalException {
305 265
		int res = setGeoTransformNat(cPtr,gt);
306
		
307
		if(res<0)
308
			throw new GdalException("Error en getGeoTransform(). No se ha podido a?adir valores para geoTransform. Es posible que el formato no lo soporte.");
309
	
310 266
	}
311 267
	
312 268
	/**
......
315 271
	 * @return	Devuelve un String con los datos del sistema de coordenadas de referencia.
316 272
	 * @throws GdalException
317 273
	 */
318
	
319
	public String getProjectionRef()throws GdalException{
320
		
321
		if(cPtr <= 0)
322
			throw new GdalException("Error en getGetProjectionRef(). La llamada Open no tuvo exito");
323
		
324
		
274
	public String getProjectionRef()throws GdalException {
325 275
		String res = getProjectionRefNat(cPtr);
326 276
		
327 277
		if(res == null)return new String("");
328 278
		else return res;
329
		
330 279
	}
331 280
	
332 281
	/**
......
334 283
	 *
335 284
	 * @throws GdalException 
336 285
	 */
337
	
338
	public void close()throws GdalException{
339
		
340
		if(cPtr <= 0)
341
			throw new GdalException("Error en Close(). La llamada Open no tuvo exito");
286
	public void close()throws GdalException {
342 287
		closeNat(cPtr);	
343
		
344 288
	}
345 289
	
346 290
	/**
......
348 292
	 * 
349 293
	 * @param name	Nombre del driver
350 294
	 */
351
	
352
	public static GdalDriver getDriverByName(String name)throws GdalException{
295
	public static GdalDriver getDriverByName(String name)throws GdalException {
296
		long ptrdrv = -1;
353 297
		
354
		long ptrdrv=-1;
355
		
356
		ptrdrv=getDriverByNameNat(name);
298
		ptrdrv = getDriverByNameNat(name);
357 299
		//System.out.println("ptrdrv="+ptrdrv);
358
		if(ptrdrv > 0)
359
			return (new GdalDriver(ptrdrv));
360
		else 
361
			throw new GdalException("Error en getDriverByName(). No se ha podido obtener el driver.");
362 300
		
301
		return (new GdalDriver(ptrdrv));
363 302
	}
364 303
	
365 304
	
......
369 308
	 * @return	Devuelve un entero con el n?mero de bandas que contiene la im?gen.
370 309
	 * @throws GdalException
371 310
	 */
372
	
373
	public int getGCPCount()throws GdalException{
374
		
311
	public int getGCPCount()throws GdalException {
375 312
		String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito";
376 313
		String msg2="Error en el conteo de n?mero de bandas";
377 314
		return baseSimpleFunctions(8,msg1,msg2);
378
		
379 315
	}
380 316
	
381 317
	/**
......
383 319
	 *@param proj	proyecci?n
384 320
	 *@throws GdalException 
385 321
	 */
386
	
387
	public void setProjection(String proj)throws GdalException{
388
		
389
		if(cPtr <= 0)
390
			throw new GdalException("Error en setProjection(). La llamada Open no tuvo exito");
391
		
322
	public void setProjection(String proj)throws GdalException {
392 323
		int res = setProjectionNat(cPtr, proj);
393 324
		
394
		if(res<0)
325
		if(res < 0)
395 326
			throw new GdalException("Error en setProjection(). No se ha podido asignar la proyecci?n.");
396 327
	}
397 328
	
......
419 350
	 * @return	Cadena con el nombre del tipo de banda de color
420 351
	 * @throws GdalException
421 352
	 */
422
	
423
	public String getColorInterpretationName(int colorInterp)throws GdalException{
424
		
425
		if(cPtr <= 0)
426
			throw new GdalException("Error en getColorInterpretationName(). La llamada Open no tuvo exito");
353
	public String getColorInterpretationName(int colorInterp)throws GdalException {
427 354
		String bandTypeName = getColorInterpretationNameNat(cPtr, colorInterp);
428 355
		
429 356
		if(bandTypeName == null)
430 357
			throw new GdalException("Error en getColorInterpretationName(). No ha podido obtenerse el tipo de banda de color");
431 358
		else 
432 359
			return bandTypeName;
433
		
434 360
	}
435 361
	
436
}
362
}

Also available in: Unified diff