Statistics
| Revision:

root / trunk / libraries / libjni-gdal / src / rasterband_interfaz.c @ 5911

History | View | Annotate | Download (23.2 KB)

1
/**********************************************************************
2
 * $Id: rasterband_interfaz.c 5911 2006-06-20 13:16:08Z nacho $
3
 *
4
 * Name:     rasterband_interfaz.c
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:  Raster band's Basic Funcions.
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
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
        
51
#include <jni.h>
52
#include "es_gva_cit_jgdal_GdalRasterBand.h"
53
#include "es_gva_cit_jgdal_JNIBase.h"
54
#include "gdal.h"
55
#include "cpl_string.h"
56
  
57
/******************************************************************************/
58
//                                                        GetRasterBandXSize
59
/******************************************************************************/
60

    
61

    
62
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandXSizeNat
63
  (JNIEnv *env, jobject obj, jlong cPtr){
64
          
65
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
66
          int res = -1;
67
                    
68
    rb = *(GDALRasterBandH **)&cPtr;
69
    
70
    if(rb!=NULL)
71
            res = GDALGetRasterBandXSize(rb);        
72

    
73

    
74
    return res;
75
  }
76
  
77
  
78
/******************************************************************************/ 
79
//                                                        GetRasterBandYSize
80
/******************************************************************************/
81

    
82

    
83
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandYSizeNat
84
  (JNIEnv *env, jobject obj, jlong cPtr){
85
          
86
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
87
          int res = -1;
88
                    
89
    rb = *(GDALRasterBandH **)&cPtr;
90
    
91
    if(rb!=NULL)
92
            res = GDALGetRasterBandYSize(rb);        
93

    
94
    return res;
95
          
96
  }
97
  
98
 /****************************************************************************/
99
 //                                                         GetOverviewCount
100
 /******************************************************************************/
101
  
102
  
103
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getOverviewCountNat
104
  (JNIEnv *env, jobject obj, jlong cPtr){
105
          
106
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
107
          int res = -1;
108
                    
109
    rb = *(GDALRasterBandH **)&cPtr;
110
    
111
    if(rb!=NULL)
112
                res = GDALGetOverviewCount(rb);        
113

    
114
    return res;
115
    
116
  }
117
  
118
/******************************************************************************/   
119
//                                                                GetOverview
120
/******************************************************************************/
121

    
122

    
123
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getOverviewNat
124
  (JNIEnv *env, jobject obj, jlong cPtr, jint noverview){
125
          
126
        GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
127
        GDALRasterBandH *res = NULL;
128
        jlong jresult = 0;
129
          
130
        rb = *(GDALRasterBandH **)&cPtr;
131
    
132
    if(rb!=NULL)
133
            res = GDALGetOverview(rb,(int)noverview);
134
    
135
    *(GDALDatasetH **)&jresult = res;
136
        
137
    if(res==NULL)return -1;
138
    else return jresult;
139
                  
140
  }
141
  
142
/******************************************************************************/     
143
//                                                                min
144
/******************************************************************************/    
145
  
146
/*int min(int x, int y){
147
        if(x < y)
148
                return x;
149
        else
150
                return y;        
151
}*/
152
  
153
/******************************************************************************/     
154
//                                                                ReadRaster
155
/******************************************************************************/  
156
  
157
  
158
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterNat
159
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){
160

    
161
                  jclass class_gdalbuffer;
162
                  jmethodID metodo;
163
                  jobject obj_gdalbuffer = NULL;
164
                  jfieldID id_campo;
165
                  
166
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
167
                  
168
                  jbyteArray bytearray;
169
                  jshortArray shortarray;
170
                  jintArray intarray;
171
                  jfloatArray floatarray;
172
                  jdoubleArray doublearray;
173
                  
174
                  unsigned char *pabyScanLineBuf;
175
                  int *buffInt=NULL;
176
                  unsigned int *buffUInt=NULL;
177
                  long *buffLong=NULL;
178
                  unsigned long *buffULong=NULL;
179
                  float *buffFloat=NULL;
180
                  double *buffDouble=NULL;
181
                                   
182
            rb = *(GDALRasterBandH **)&cPtr;
183
                  
184
                  if(rb!=NULL){
185
                          
186
                  //Creamos el objeto java que contendr? la l?nea
187
                  
188
                          class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
189
                          
190
                          if(eBufType==1){
191
                                  
192
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaByte", "(I)V");
193
                                          
194
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
195
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffByte", "[B");
196
                                                    
197
                                //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
198
                                                    
199
                                  pabyScanLineBuf = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
200
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, pabyScanLineBuf, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0);          
201
                                bytearray = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
202
                                if(bytearray!=NULL){
203
                                          (*env)->SetByteArrayRegion(env, bytearray, 0, (int)(BufXSize*BufYSize),(jbyte *)pabyScanLineBuf); 
204
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, bytearray);
205
                                }
206
                                if(pabyScanLineBuf != NULL)CPLFree(pabyScanLineBuf);
207
                                
208
                          }else
209
                          
210
                          //------------------------------------------------------------------
211
                          
212
                          if(eBufType==2 || eBufType==3 || eBufType==8){
213
                                  
214
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaShort", "(I)V");
215
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
216
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffShort", "[S");
217
                                            
218
                           //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
219
                                                                              
220
                                  if(eBufType==2){
221
                                          buffUInt = (unsigned int*) CPLMalloc(sizeof(unsigned int) *(int)BufXSize * (int)BufYSize);
222
                                          GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffUInt, (int)BufXSize, (int)BufYSize, GDT_UInt16, 0, 0);
223
                                            shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
224
                                    if(shortarray!=NULL){
225
                                                  (*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffUInt); 
226
                                                  (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray);
227
                                        }
228
                                        if(buffUInt != NULL)CPLFree(buffUInt);
229
                                        return obj_gdalbuffer;                
230
                                  }
231
                                  
232
                                  buffInt = (int*) CPLMalloc(sizeof(int) *(int)BufXSize * (int)BufYSize);
233
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffInt, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
234
                                  shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
235
                            if(shortarray!=NULL){
236
                                          (*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffInt); 
237
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray);
238
                                }
239

    
240
                                if(buffInt != NULL)CPLFree(buffInt);
241
                                
242
                          }else
243
                          
244
                          //------------------------------------------------------------------
245
                          
246
                          if(eBufType==4 || eBufType==5 || eBufType==9){
247
                                  
248
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaInt", "(I)V");
249
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
250
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffInt", "[I");
251
                                            
252
                           //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
253
                                                                              
254
                                  if(eBufType==4){
255
                                          buffULong = (unsigned long*) CPLMalloc(sizeof(unsigned long) *(int)BufXSize * (int)BufYSize);
256
                                          GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffULong, (int)BufXSize, (int)BufYSize, GDT_UInt32, 0, 0);
257
                                          intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
258
                                    if(intarray!=NULL){
259
                                                  (*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffULong); 
260
                                                  (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray);
261
                                        }
262
                                        if(buffULong != NULL)CPLFree(buffULong);
263
                                        return obj_gdalbuffer;
264
                                  }
265
                                  
266
                                  buffLong = (long*) CPLMalloc(sizeof(long) *(int)BufXSize * (int)BufYSize);
267
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffLong, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
268
                                  intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
269
                            if(intarray!=NULL){
270
                                          (*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffLong); 
271
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray);
272
                                }
273

    
274
                                if(buffLong != NULL)CPLFree(buffLong);
275
                                
276
                          }else
277
                          
278
                          //------------------------------------------------------------------
279
                          
280
                          if(eBufType==6 || eBufType==10){
281
                                  
282
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaFloat", "(I)V");
283
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
284
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffFloat", "[F");
285
                                            
286
                                   //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
287
                           
288
                                   buffFloat = (float*) CPLMalloc(sizeof(float) *(int)BufXSize * (int)BufYSize);
289
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffFloat, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
290
                                  floatarray = (*env)->NewFloatArray(env,(int)(BufXSize*BufYSize));
291
                            if(floatarray!=NULL){
292
                                          (*env)->SetFloatArrayRegion(env, floatarray, 0, (int)(BufXSize*BufYSize),(jfloat *)buffFloat); 
293
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, floatarray);
294
                                }
295

    
296
                                if(buffFloat != NULL)CPLFree(buffFloat);
297
                          }else
298
                          
299
                          //------------------------------------------------------------------
300
                          
301
                          if(eBufType==7 || eBufType==11){
302
                                  
303
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaDouble", "(I)V");
304
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
305
                                  id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffDouble", "[D");
306
                                            
307
                                   //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
308
                           
309
                                   buffDouble = (double*) CPLMalloc(sizeof(double) *(int)BufXSize * (int)BufYSize);
310
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffDouble, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0);
311
                                  doublearray = (*env)->NewDoubleArray(env,(int)(BufXSize*BufYSize));
312
                            if(doublearray!=NULL){
313
                                          (*env)->SetDoubleArrayRegion(env, doublearray, 0, (int)(BufXSize*BufYSize),(jdouble *)buffDouble); 
314
                                         (*env)->SetObjectField(env, obj_gdalbuffer, id_campo, doublearray);
315
                                }
316

    
317
                                if(buffDouble != NULL)CPLFree(buffDouble);
318
                          }
319
                          
320
                  }//if(rb!=NULL)
321
                                    
322
                  return obj_gdalbuffer;
323
                  
324
  } 
325
  
326
/******************************************************************************/     
327
//                                                                ReadRaster
328
/******************************************************************************/  
329
  
330
  
331
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterWithPaletteNat
332
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){
333

    
334
                  jclass class_gdalbuffer;
335
                  jmethodID metodo;
336
                  jobject obj_gdalbuffer = NULL;
337
                  jfieldID id_campoR, id_campoG, id_campoB, id_campoA;
338
                  int dfNoData, bGotNodata;
339
                  
340
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
341
                  
342
                  jbyteArray bytearrayR, bytearrayG, bytearrayB, bytearrayA;
343
                  
344
                  unsigned char *scanLineBufR, *scanLineBufG, *scanLineBufB, *scanLineBufA;
345
                  
346
                  GDALColorTableH hTable;
347
        GByte      abyPCT[256][4];
348
                int i = 0;                  
349
                                   
350
            rb = *(GDALRasterBandH **)&cPtr;
351
                  
352
                  if(rb!=NULL){
353
                          
354
                  //Creamos el objeto java que contendr? la l?nea
355
                  
356
                          class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
357
                          
358
                          if(eBufType==1){
359
                                  
360
                                  metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaPalette", "(I)V");
361
                                          
362
                                  obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
363
                                  id_campoR = (*env)->GetFieldID(env, class_gdalbuffer, "buffRPalette", "[B");
364
                                  id_campoG = (*env)->GetFieldID(env, class_gdalbuffer, "buffGPalette", "[B");
365
                                  id_campoB = (*env)->GetFieldID(env, class_gdalbuffer, "buffBPalette", "[B");
366
                                  id_campoA = (*env)->GetFieldID(env, class_gdalbuffer, "buffAPalette", "[B");
367
                                                    
368
                                //Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
369
                                                    
370
                                  scanLineBufR = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
371
                                  scanLineBufG = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
372
                                  scanLineBufB = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
373
                                  scanLineBufA = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize);
374
                                  
375
                                  GDALRasterIO(rb, GF_Read,  (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, scanLineBufR, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0);
376
                                                                    
377
                                    hTable = GDALGetRasterColorTable( rb );          
378
                                     
379
                                  if( hTable != NULL ){
380
                                  int min = GDALGetColorEntryCount( hTable );
381
                                  dfNoData = GDALGetRasterNoDataValue( rb, &bGotNodata );
382
                                  if(256 < min)
383
                                   min = 256;
384
                                         for( i = 0; i < min; i++ ){
385
                                    GDALColorEntry sEntry;
386

    
387
                                    GDALGetColorEntryAsRGB( hTable, i, &sEntry );
388
                                    abyPCT[i][0] = sEntry.c1;
389
                                    abyPCT[i][1] = sEntry.c2;
390
                                    abyPCT[i][2] = sEntry.c3;
391
                                    abyPCT[i][3] = sEntry.c4;
392
                                    if(sEntry.c4 == 0){
393
                                            abyPCT[i][0] = 255;
394
                                            abyPCT[i][1] = 255;
395
                                            abyPCT[i][2] = 255;
396
                                            abyPCT[i][3] = 0;
397
                                    }         
398
                                    //printf("%d %d %d %d\n", sEntry.c1,sEntry.c2, sEntry.c3,sEntry.c4);
399
                                }
400
                                
401
                                for( i = GDALGetColorEntryCount( hTable ); i < 256; i++ ){
402
                                    abyPCT[i][0] = 0;
403
                                    abyPCT[i][1] = 0;
404
                                    abyPCT[i][2] = 0;
405
                                    abyPCT[i][3] = 255;
406
                                }
407
                                
408
                                for( i = nXSize * nYSize - 1; i >= 0; i-- ){
409
                                    scanLineBufG[i] = abyPCT[scanLineBufR[i]][1];
410
                                    scanLineBufB[i] = abyPCT[scanLineBufR[i]][2];
411
                                           scanLineBufA[i] = abyPCT[scanLineBufR[i]][3];
412
                                           scanLineBufR[i] = abyPCT[scanLineBufR[i]][0];
413
                                }
414
                                //printf("-%d %d %d %d\n", scanLineBufR[0], scanLineBufG[0], scanLineBufB[0],scanLineBufA[0]);
415
                                  }
416
                                                            
417
                                bytearrayR = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
418
                                bytearrayG = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
419
                                bytearrayB = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
420
                                bytearrayA = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
421
                                if(bytearrayR!=NULL){
422
                                          (*env)->SetByteArrayRegion(env, bytearrayR, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufR); 
423
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoR, bytearrayR);
424
                                }
425
                                if(scanLineBufR != NULL)
426
                                        CPLFree(scanLineBufR);
427
                                        
428
                                if(bytearrayG!=NULL){
429
                                          (*env)->SetByteArrayRegion(env, bytearrayG, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufG); 
430
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoG, bytearrayG);
431
                                }
432
                                if(scanLineBufG != NULL)
433
                                        CPLFree(scanLineBufG);
434
                                        
435
                                if(bytearrayB!=NULL){
436
                                          (*env)->SetByteArrayRegion(env, bytearrayB, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufB); 
437
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoB, bytearrayB);
438
                                }
439
                                if(scanLineBufB != NULL)
440
                                        CPLFree(scanLineBufB);
441
                                        
442
                                if(bytearrayA!=NULL){
443
                                          (*env)->SetByteArrayRegion(env, bytearrayA, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufA); 
444
                                          (*env)->SetObjectField(env, obj_gdalbuffer, id_campoA, bytearrayA);
445
                                }
446
                                if(scanLineBufA != NULL)
447
                                        CPLFree(scanLineBufA);
448
                                
449
                          }
450
                  }
451
                  //CPLFree(hTable);
452

    
453
                  return obj_gdalbuffer;
454
                  
455
  } 
456
  
457
/******************************************************************************/
458
//                                                                GetRasterColorTable
459
/******************************************************************************/
460

    
461
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorTableNat
462
  (JNIEnv *env, jobject obj, jlong cPtr){
463

    
464
        GDALColorTableH hTable = NULL;
465
        jlong jresult = 0;
466
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
467
          
468
          rb = *(GDALRasterBandH **)&cPtr;
469
        hTable = GDALGetRasterColorTable( rb );
470
    
471
    *(GDALColorTableH **)&jresult = hTable;
472
        
473
    if(hTable == NULL)
474
            return -1;
475
    else 
476
            return jresult;
477
  }
478
  
479
/******************************************************************************/
480
//                                                                GetBlockXSize
481
/******************************************************************************/
482

    
483

    
484
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockXSizeNat
485
  (JNIEnv *env, jobject obj, jlong cPtr){
486
          
487
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
488
          int pnXSize=-1,pnYSize=-1;
489
                    
490
    rb = *(GDALRasterBandH **)&cPtr;
491
    
492
    if(rb!=NULL)
493
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
494

    
495
    return pnXSize;
496
  }
497

    
498

    
499
/******************************************************************************/     
500
//                                                                WriteRaster
501
/******************************************************************************/  
502
  
503
JNIEXPORT void JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_writeRasterNat
504
  (JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jobject buffer, jint eBufType){
505
          
506
                  GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
507
                  jclass clase;
508
                  jfieldID id_campo;
509
                  jmethodID metodo;
510
                  jbyteArray bytearray;
511
                  int tam;
512
                  unsigned char *abyRaster;
513
                  
514
                char funcion[11];
515
                char signature[3];
516
                
517
                switch(eBufType){
518
                        case 1:        
519
                                        strncpy(funcion,"buffByte\0",9);
520
                                        strncpy(signature,"[B\0",3);
521
                                        break;
522
                        case 2:        
523
                        case 3:        
524
                        case 8:
525
                                        strncpy(funcion,"buffShort\0",10);
526
                                        strncpy(signature,"[S\0",3);
527
                                        break;
528
                        case 4:        
529
                        case 5:        
530
                        case 9:        
531
                                        strncpy(funcion,"buffInt\0",8);
532
                                        strncpy(signature,"[I\0",3);
533
                                        break;
534
                        case 6:        
535
                        case 10:
536
                                        strncpy(funcion,"buffFloat\0",10);
537
                                        strncpy(signature,"[F\0",3);
538
                                        break;        
539
                        case 7:        
540
                        case 11:
541
                                        strncpy(funcion,"buffDouble\0",11);
542
                                        strncpy(signature,"[D\0",3);
543
                                        break;        
544
                }
545
                  
546
                  
547
                  clase = (*env)->GetObjectClass(env, buffer);
548
                  id_campo = (*env)->GetFieldID(env, clase, funcion, signature);
549
                  metodo = (*env)->GetMethodID(env, clase, "getSize","()I");
550
                  tam = (*env)->CallIntMethod(env,buffer,metodo);
551
                  
552
                  bytearray =(jbyteArray)(*env)->GetObjectField(env, buffer, id_campo); 
553
                  
554
                  abyRaster=(unsigned char *)malloc(sizeof(unsigned char)*tam);
555
                  
556
                  if(bytearray!=NULL){
557
                      (*env)->GetByteArrayRegion(env,bytearray,0,tam,(jbyte *)abyRaster); 
558
                }
559
                  
560
                  rb = *(GDALRasterBandH **)&cPtr;
561
                  
562
                  if(rb!=NULL)
563
                          GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, 
564
                  abyRaster, nXSize, nYSize, eBufType, 0, 0 );
565
                  
566
        free(abyRaster);
567
  }
568
    
569
/******************************************************************************/
570
//                                                                GetBlockYSize
571
/******************************************************************************/
572

    
573

    
574
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockYSizeNat
575
  (JNIEnv *env, jobject obj, jlong cPtr){
576
          
577
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
578
          int pnXSize=-1,pnYSize=-1;
579
                    
580
    rb = *(GDALRasterBandH **)&cPtr;
581
    
582
    if(rb!=NULL)
583
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
584

    
585
    return pnYSize;
586
  }
587
  
588
/******************************************************************************/
589
//                                                                GetRasterDataType
590
/******************************************************************************/  
591
  
592
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterDataTypeNat
593
  (JNIEnv *env, jobject obj, jlong cPtr){
594
          
595
          int datatype = -1;
596
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
597
          
598
          rb = *(GDALRasterBandH **)&cPtr;
599
          
600
          if(rb!=NULL)
601
            datatype = GDALGetRasterDataType( rb );
602
 
603
    return datatype;
604
  }
605
  
606
/******************************************************************************/
607
//                                                                GetRasterNoDataValue
608
/******************************************************************************/  
609
  
610
JNIEXPORT jdouble JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterNoDataValueNat
611
  (JNIEnv *env, jobject obj, jlong cPtr){
612
          
613
          double nodata = -1;
614
          int bGotNodata = 0;
615
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
616
          
617
          rb = *(GDALRasterBandH **)&cPtr;
618
          
619
          if(rb!=NULL)
620
            nodata = GDALGetRasterNoDataValue( rb, &bGotNodata );
621
 
622
    return nodata;
623
  }
624
  
625
/******************************************************************************/ 
626
//                                                                 GetMetadata
627
/******************************************************************************/
628

    
629
JNIEXPORT jobjectArray JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getMetadataNat
630
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszDomain){
631
          
632
           char                **papszMetadata;
633
           GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
634
           int i, nmetadatos;
635
           
636
           jclass class_string;
637
           jobjectArray vector_str;
638
           
639
           //Obtenemos los metadatos sobre papszMetadata
640
            
641
           rb = *(GDALRasterBandH **)&cPtr;
642
                    
643
           
644
           if(rb!=NULL){
645
                 papszMetadata = GDALGetMetadata( rb, NULL );
646
                 
647
                 
648
                 //Si hay metadatos devolvemos creamos el vector de String de java y los devolvemos
649
                 
650
                 nmetadatos = CSLCount(papszMetadata);
651
             if( nmetadatos > 0 )
652
              {
653
                class_string = (*env)->FindClass (env, "java/lang/String");
654
                         vector_str=(*env)->NewObjectArray(env, nmetadatos, class_string, (*env)->NewStringUTF(env,""));
655
                         
656
                         //Cargamos los metadatos
657
                         
658
                for( i = 0; papszMetadata[i] != NULL; i++ )
659
                        (*env)->SetObjectArrayElement(env,vector_str,i,(*env)->NewStringUTF(env,papszMetadata[i]));
660
                                        
661
                           return vector_str;            
662
              }
663
           }
664
     
665
           return NULL;
666
  }
667
  
668
/******************************************************************************/ 
669
//                                                        GetRasterColorInterpretation
670
/******************************************************************************/
671

    
672
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorInterpretationNat
673
  (JNIEnv *env, jobject obj, jlong cPtr, jint band){
674
           GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
675
            rb = *(GDALRasterBandH **)&cPtr;
676

    
677
         GDALColorInterp interp = GDALGetRasterColorInterpretation(rb);           
678
         
679
         return (jint)interp;
680
  }
681