Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_901 / libraries / libjni-gdal / src / rasterband_interfaz.c @ 38629

History | View | Annotate | Download (25.2 KB)

1
/**********************************************************************
2
 * $Id: rasterband_interfaz.c 7765 2006-10-03 07:05:18Z 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
                  jshortArray shortarray;
512
                  jintArray intarray;
513
                  jfloatArray floatarray;
514
                  jdoubleArray doublearray;
515
                  
516
                  int tam;
517
                  unsigned char *byteBuf;
518
                  unsigned short *shortBuf;
519
                  unsigned int *intBuf;
520
                  float *floatBuf;
521
                  double *doubleBuf;
522
                  
523
                char funcion[11];
524
                char signature[3];
525
                
526
                switch(eBufType){
527
                        case 1:        
528
                                        strncpy(funcion,"buffByte\0",9);
529
                                        strncpy(signature,"[B\0",3);
530
                                        break;
531
                        case 2:        
532
                        case 3:        
533
                        case 8:
534
                                        strncpy(funcion,"buffShort\0",10);
535
                                        strncpy(signature,"[S\0",3);
536
                                        break;
537
                        case 4:        
538
                        case 5:        
539
                        case 9:        
540
                                        strncpy(funcion,"buffInt\0",8);
541
                                        strncpy(signature,"[I\0",3);
542
                                        break;
543
                        case 6:        
544
                        case 10:
545
                                        strncpy(funcion,"buffFloat\0",10);
546
                                        strncpy(signature,"[F\0",3);
547
                                        break;        
548
                        case 7:        
549
                        case 11:
550
                                        strncpy(funcion,"buffDouble\0",11);
551
                                        strncpy(signature,"[D\0",3);
552
                                        break;        
553
                }
554
                  
555
                  
556
                  clase = (*env)->GetObjectClass(env, buffer);
557
                  id_campo = (*env)->GetFieldID(env, clase, funcion, signature);
558
                  metodo = (*env)->GetMethodID(env, clase, "getSize","()I");
559
                  tam = (*env)->CallIntMethod(env,buffer,metodo);
560
                  
561
                  rb = *(GDALRasterBandH **)&cPtr;
562
                  
563
                  switch(eBufType){
564
                        case 1:        
565
                                bytearray =(jbyteArray)(*env)->GetObjectField(env, buffer, id_campo); 
566
                                  byteBuf = (unsigned char *)malloc(sizeof(unsigned char)*tam);
567
                                  if(bytearray!=NULL)
568
                                      (*env)->GetByteArrayRegion(env, bytearray, 0, tam, (jbyte *)byteBuf); 
569
                              if(rb != NULL)
570
                                        GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, byteBuf, nXSize, nYSize, GDT_Byte, 0, 0 );          
571
                        free(byteBuf);
572
                                break;
573
                        case 2:        
574
                        case 3:        
575
                        case 8:
576
                                shortarray = (jshortArray)(*env)->GetObjectField(env, buffer, id_campo); 
577
                                  shortBuf = (unsigned short *)malloc(sizeof(unsigned short) * tam);
578
                                  if(shortarray!=NULL)
579
                                      (*env)->GetShortArrayRegion(env, shortarray, 0, tam, (jshort *)shortBuf); 
580
                                 if(rb!=NULL)
581
                                        GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, shortBuf, nXSize, nYSize, GDT_Int16, 0, 0 );          
582
                        free(shortBuf);         
583
                                break;
584
                        case 4:        
585
                        case 5:        
586
                        case 9:        
587
                                intarray = (jintArray)(*env)->GetObjectField(env, buffer, id_campo); 
588
                                  intBuf = (unsigned int *)malloc(sizeof(unsigned int) * tam);
589
                                  if(intarray!=NULL)
590
                                      (*env)->GetIntArrayRegion(env, intarray, 0, tam, (jint *)intBuf); 
591
                                  if(rb!=NULL)
592
                                        GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, intBuf, nXSize, nYSize, GDT_Int32, 0, 0 );          
593
                        free(intBuf);
594
                                break;
595
                        case 6:        
596
                        case 10:
597
                                floatarray = (jfloatArray)(*env)->GetObjectField(env, buffer, id_campo); 
598
                                  floatBuf = (float *)malloc(sizeof(float) * tam);
599
                                  if(floatarray!=NULL)
600
                                      (*env)->GetFloatArrayRegion(env, floatarray, 0, tam, (jfloat *)floatBuf); 
601
                                  if(rb!=NULL)
602
                                        GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, floatBuf, nXSize, nYSize, GDT_Float32, 0, 0 );          
603
                        free(floatBuf);
604
                                break;
605
                        case 7:        
606
                        case 11:
607
                                doublearray = (jdoubleArray)(*env)->GetObjectField(env, buffer, id_campo); 
608
                                  doubleBuf = (double *)malloc(sizeof(double) * tam);
609
                                  if(doublearray!=NULL)
610
                                      (*env)->GetDoubleArrayRegion(env, doublearray, 0, tam, (jdouble *)doubleBuf); 
611
                                  if(rb!=NULL)
612
                                        GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, doubleBuf, nXSize, nYSize, GDT_Float64, 0, 0 );          
613
                        free(doubleBuf);
614
                                break;
615
                                
616
                }
617
                    
618
  }
619
    
620
/******************************************************************************/
621
//                                                                GetBlockYSize
622
/******************************************************************************/
623

    
624

    
625
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockYSizeNat
626
  (JNIEnv *env, jobject obj, jlong cPtr){
627
          
628
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
629
          int pnXSize=-1,pnYSize=-1;
630
                    
631
    rb = *(GDALRasterBandH **)&cPtr;
632
    
633
    if(rb!=NULL)
634
            GDALGetBlockSize( rb,&pnXSize, &pnYSize );
635

    
636
    return pnYSize;
637
  }
638
  
639
/******************************************************************************/
640
//                                                                GetRasterDataType
641
/******************************************************************************/  
642
  
643
  JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterDataTypeNat
644
  (JNIEnv *env, jobject obj, jlong cPtr){
645
          
646
          int datatype = -1;
647
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
648
          
649
          rb = *(GDALRasterBandH **)&cPtr;
650
          
651
          if(rb!=NULL)
652
            datatype = GDALGetRasterDataType( rb );
653
 
654
    return datatype;
655
  }
656
  
657
/******************************************************************************/
658
//                                                                GetRasterNoDataValue
659
/******************************************************************************/  
660
  
661
JNIEXPORT jdouble JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterNoDataValueNat
662
  (JNIEnv *env, jobject obj, jlong cPtr){
663
          
664
          double nodata = -1;
665
          int bGotNodata = 0;
666
          GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
667
          
668
          rb = *(GDALRasterBandH **)&cPtr;
669
          
670
          if(rb!=NULL)
671
            nodata = GDALGetRasterNoDataValue( rb, &bGotNodata );
672
 
673
    return nodata;
674
  }
675
  
676
/******************************************************************************/ 
677
//                                                                 GetMetadata
678
/******************************************************************************/
679

    
680
JNIEXPORT jobjectArray JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getMetadataNat
681
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszDomain){
682
          
683
           char                **papszMetadata;
684
           GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
685
           int i, nmetadatos;
686
           
687
           jclass class_string;
688
           jobjectArray vector_str;
689
           
690
           //Obtenemos los metadatos sobre papszMetadata
691
            
692
           rb = *(GDALRasterBandH **)&cPtr;
693
                    
694
           
695
           if(rb!=NULL){
696
                 papszMetadata = GDALGetMetadata( rb, NULL );
697
                 
698
                 
699
                 //Si hay metadatos devolvemos creamos el vector de String de java y los devolvemos
700
                 
701
                 nmetadatos = CSLCount(papszMetadata);
702
             if( nmetadatos > 0 )
703
              {
704
                class_string = (*env)->FindClass (env, "java/lang/String");
705
                         vector_str=(*env)->NewObjectArray(env, nmetadatos, class_string, (*env)->NewStringUTF(env,""));
706
                         
707
                         //Cargamos los metadatos
708
                         
709
                for( i = 0; papszMetadata[i] != NULL; i++ )
710
                        (*env)->SetObjectArrayElement(env,vector_str,i,(*env)->NewStringUTF(env,papszMetadata[i]));
711
                                        
712
                           return vector_str;            
713
              }
714
           }
715
     
716
           return NULL;
717
  }
718
  
719
/******************************************************************************/ 
720
//                                                        GetRasterColorInterpretation
721
/******************************************************************************/
722

    
723
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorInterpretationNat
724
  (JNIEnv *env, jobject obj, jlong cPtr){
725
           GDALRasterBandH *rb  = (GDALRasterBandH *) 0 ;
726
          int interp;
727
          
728
          rb = *(GDALRasterBandH **)&cPtr;
729
         interp = GDALGetRasterColorInterpretation(rb);           
730
         
731
         return (jint)interp;
732
  }
733