svn-gvsig-desktop / tags / v2_0_0_Build_2002 / libraries / libjni-gdal-macosx / src / rasterband_interfaz.c @ 43233
History | View | Annotate | Download (23.3 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: rasterband_interfaz.c 8219 2006-10-23 06:25:39Z 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 |
printf("==>Ptro a objeto:%ld %ld\n",cPtr, rb);
|
70 |
|
71 |
if(rb!=NULL) |
72 |
res = GDALGetRasterBandXSize(rb); |
73 |
|
74 |
printf("==>Tama?o devuelto:%d\n",res);
|
75 |
|
76 |
|
77 |
return res;
|
78 |
} |
79 |
|
80 |
|
81 |
/******************************************************************************/
|
82 |
// GetRasterBandYSize
|
83 |
/******************************************************************************/
|
84 |
|
85 |
|
86 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterBandYSizeNat |
87 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
88 |
|
89 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
90 |
int res = -1; |
91 |
|
92 |
rb = *(GDALRasterBandH **)&cPtr; |
93 |
|
94 |
if(rb!=NULL) |
95 |
res = GDALGetRasterBandYSize(rb); |
96 |
|
97 |
return res;
|
98 |
|
99 |
} |
100 |
|
101 |
/****************************************************************************/
|
102 |
// GetOverviewCount
|
103 |
/******************************************************************************/
|
104 |
|
105 |
|
106 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getOverviewCountNat |
107 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
108 |
|
109 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
110 |
int res = -1; |
111 |
|
112 |
rb = *(GDALRasterBandH **)&cPtr; |
113 |
|
114 |
if(rb!=NULL) |
115 |
res = GDALGetOverviewCount(rb); |
116 |
|
117 |
return res;
|
118 |
|
119 |
} |
120 |
|
121 |
/******************************************************************************/
|
122 |
// GetOverview
|
123 |
/******************************************************************************/
|
124 |
|
125 |
|
126 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getOverviewNat |
127 |
(JNIEnv *env, jobject obj, jlong cPtr, jint noverview){ |
128 |
|
129 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
130 |
GDALRasterBandH *res = NULL;
|
131 |
jlong jresult = 0;
|
132 |
|
133 |
rb = *(GDALRasterBandH **)&cPtr; |
134 |
|
135 |
if(rb!=NULL) |
136 |
res = GDALGetOverview(rb,(int)noverview);
|
137 |
|
138 |
*(GDALDatasetH **)&jresult = res; |
139 |
|
140 |
if(res==NULL)return -1; |
141 |
else return jresult; |
142 |
|
143 |
} |
144 |
|
145 |
/******************************************************************************/
|
146 |
// min
|
147 |
/******************************************************************************/
|
148 |
|
149 |
/*int min(int x, int y){
|
150 |
if(x < y)
|
151 |
return x;
|
152 |
else
|
153 |
return y;
|
154 |
}*/
|
155 |
|
156 |
/******************************************************************************/
|
157 |
// ReadRaster
|
158 |
/******************************************************************************/
|
159 |
|
160 |
|
161 |
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterNat |
162 |
(JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){ |
163 |
|
164 |
jclass class_gdalbuffer; |
165 |
jmethodID metodo; |
166 |
jobject obj_gdalbuffer = NULL;
|
167 |
jfieldID id_campo; |
168 |
|
169 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
170 |
|
171 |
jbyteArray bytearray; |
172 |
jshortArray shortarray; |
173 |
jintArray intarray; |
174 |
jfloatArray floatarray; |
175 |
jdoubleArray doublearray; |
176 |
|
177 |
unsigned char *pabyScanLineBuf; |
178 |
int *buffInt=NULL; |
179 |
unsigned int *buffUInt=NULL; |
180 |
long *buffLong=NULL; |
181 |
unsigned long *buffULong=NULL; |
182 |
float *buffFloat=NULL; |
183 |
double *buffDouble=NULL; |
184 |
|
185 |
rb = *(GDALRasterBandH **)&cPtr; |
186 |
|
187 |
if(rb!=NULL){ |
188 |
|
189 |
//Creamos el objeto java que contendr? la l?nea
|
190 |
|
191 |
class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
|
192 |
|
193 |
if(eBufType==1){ |
194 |
|
195 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaByte", "(I)V"); |
196 |
|
197 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
|
198 |
id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffByte", "[B"); |
199 |
|
200 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
201 |
|
202 |
pabyScanLineBuf = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize); |
203 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, pabyScanLineBuf, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0); |
204 |
bytearray = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
|
205 |
if(bytearray!=NULL){ |
206 |
(*env)->SetByteArrayRegion(env, bytearray, 0, (int)(BufXSize*BufYSize),(jbyte *)pabyScanLineBuf); |
207 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, bytearray); |
208 |
} |
209 |
if(pabyScanLineBuf != NULL)CPLFree(pabyScanLineBuf); |
210 |
|
211 |
}else
|
212 |
|
213 |
//------------------------------------------------------------------
|
214 |
|
215 |
if(eBufType==2 || eBufType==3 || eBufType==8){ |
216 |
|
217 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaShort", "(I)V"); |
218 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
|
219 |
id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffShort", "[S"); |
220 |
|
221 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
222 |
|
223 |
if(eBufType==2){ |
224 |
buffUInt = (unsigned int*) CPLMalloc(sizeof(unsigned int) *(int)BufXSize * (int)BufYSize); |
225 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffUInt, (int)BufXSize, (int)BufYSize, GDT_UInt16, 0, 0); |
226 |
shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
|
227 |
if(shortarray!=NULL){ |
228 |
(*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffUInt); |
229 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray); |
230 |
} |
231 |
if(buffUInt != NULL)CPLFree(buffUInt); |
232 |
return obj_gdalbuffer;
|
233 |
} |
234 |
|
235 |
buffInt = (int*) CPLMalloc(sizeof(int) *(int)BufXSize * (int)BufYSize); |
236 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffInt, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0); |
237 |
shortarray = (*env)->NewShortArray(env,(int)(BufXSize*BufYSize));
|
238 |
if(shortarray!=NULL){ |
239 |
(*env)->SetShortArrayRegion(env, shortarray, 0, (int)(BufXSize*BufYSize),(jshort *)buffInt); |
240 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, shortarray); |
241 |
} |
242 |
|
243 |
if(buffInt != NULL)CPLFree(buffInt); |
244 |
|
245 |
}else
|
246 |
|
247 |
//------------------------------------------------------------------
|
248 |
|
249 |
if(eBufType==4 || eBufType==5 || eBufType==9){ |
250 |
|
251 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaInt", "(I)V"); |
252 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
|
253 |
id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffInt", "[I"); |
254 |
|
255 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
256 |
|
257 |
if(eBufType==4){ |
258 |
buffULong = (unsigned long*) CPLMalloc(sizeof(unsigned long) *(int)BufXSize * (int)BufYSize); |
259 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffULong, (int)BufXSize, (int)BufYSize, GDT_UInt32, 0, 0); |
260 |
intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
|
261 |
if(intarray!=NULL){ |
262 |
(*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffULong); |
263 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray); |
264 |
} |
265 |
if(buffULong != NULL)CPLFree(buffULong); |
266 |
return obj_gdalbuffer;
|
267 |
} |
268 |
|
269 |
buffLong = (long*) CPLMalloc(sizeof(long) *(int)BufXSize * (int)BufYSize); |
270 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffLong, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0); |
271 |
intarray = (*env)->NewIntArray(env,(int)(BufXSize*BufYSize));
|
272 |
if(intarray!=NULL){ |
273 |
(*env)->SetIntArrayRegion(env, intarray, 0, (int)(BufXSize*BufYSize),(jint *)buffLong); |
274 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, intarray); |
275 |
} |
276 |
|
277 |
if(buffLong != NULL)CPLFree(buffLong); |
278 |
|
279 |
}else
|
280 |
|
281 |
//------------------------------------------------------------------
|
282 |
|
283 |
if(eBufType==6 || eBufType==10){ |
284 |
|
285 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaFloat", "(I)V"); |
286 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
|
287 |
id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffFloat", "[F"); |
288 |
|
289 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
290 |
|
291 |
buffFloat = (float*) CPLMalloc(sizeof(float) *(int)BufXSize * (int)BufYSize); |
292 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffFloat, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0); |
293 |
floatarray = (*env)->NewFloatArray(env,(int)(BufXSize*BufYSize));
|
294 |
if(floatarray!=NULL){ |
295 |
(*env)->SetFloatArrayRegion(env, floatarray, 0, (int)(BufXSize*BufYSize),(jfloat *)buffFloat); |
296 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, floatarray); |
297 |
} |
298 |
|
299 |
if(buffFloat != NULL)CPLFree(buffFloat); |
300 |
}else
|
301 |
|
302 |
//------------------------------------------------------------------
|
303 |
|
304 |
if(eBufType==7 || eBufType==11){ |
305 |
|
306 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaDouble", "(I)V"); |
307 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
|
308 |
id_campo = (*env)->GetFieldID(env, class_gdalbuffer, "buffDouble", "[D"); |
309 |
|
310 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
311 |
|
312 |
buffDouble = (double*) CPLMalloc(sizeof(double) *(int)BufXSize * (int)BufYSize); |
313 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, buffDouble, (int)BufXSize, (int)BufYSize, (int)eBufType, 0, 0); |
314 |
doublearray = (*env)->NewDoubleArray(env,(int)(BufXSize*BufYSize));
|
315 |
if(doublearray!=NULL){ |
316 |
(*env)->SetDoubleArrayRegion(env, doublearray, 0, (int)(BufXSize*BufYSize),(jdouble *)buffDouble); |
317 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campo, doublearray); |
318 |
} |
319 |
|
320 |
if(buffDouble != NULL)CPLFree(buffDouble); |
321 |
} |
322 |
|
323 |
}//if(rb!=NULL)
|
324 |
|
325 |
return obj_gdalbuffer;
|
326 |
|
327 |
} |
328 |
|
329 |
/******************************************************************************/
|
330 |
// ReadRaster
|
331 |
/******************************************************************************/
|
332 |
|
333 |
|
334 |
JNIEXPORT jobject JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_readRasterWithPaletteNat |
335 |
(JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jint BufXSize, jint BufYSize, jint eBufType){ |
336 |
|
337 |
jclass class_gdalbuffer; |
338 |
jmethodID metodo; |
339 |
jobject obj_gdalbuffer = NULL;
|
340 |
jfieldID id_campoR, id_campoG, id_campoB, id_campoA; |
341 |
int dfNoData, bGotNodata;
|
342 |
|
343 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
344 |
|
345 |
jbyteArray bytearrayR, bytearrayG, bytearrayB, bytearrayA; |
346 |
|
347 |
unsigned char *scanLineBufR, *scanLineBufG, *scanLineBufB, *scanLineBufA; |
348 |
|
349 |
GDALColorTableH hTable; |
350 |
GByte abyPCT[256][4]; |
351 |
int i = 0; |
352 |
|
353 |
rb = *(GDALRasterBandH **)&cPtr; |
354 |
|
355 |
if(rb!=NULL){ |
356 |
|
357 |
//Creamos el objeto java que contendr? la l?nea
|
358 |
|
359 |
class_gdalbuffer = (*env)->FindClass (env, "es/gva/cit/jgdal/GdalBuffer");
|
360 |
|
361 |
if(eBufType==1){ |
362 |
|
363 |
metodo = (*env)->GetMethodID(env, class_gdalbuffer, "reservaPalette", "(I)V"); |
364 |
|
365 |
obj_gdalbuffer = (*env)->NewObject (env,class_gdalbuffer,metodo,(int)(BufXSize*BufYSize));
|
366 |
id_campoR = (*env)->GetFieldID(env, class_gdalbuffer, "buffRPalette", "[B"); |
367 |
id_campoG = (*env)->GetFieldID(env, class_gdalbuffer, "buffGPalette", "[B"); |
368 |
id_campoB = (*env)->GetFieldID(env, class_gdalbuffer, "buffBPalette", "[B"); |
369 |
id_campoA = (*env)->GetFieldID(env, class_gdalbuffer, "buffAPalette", "[B"); |
370 |
|
371 |
//Reservamos memoria para el buffer y lo cargamos llamando a GDALRasterIO
|
372 |
|
373 |
scanLineBufR = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize); |
374 |
scanLineBufG = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize); |
375 |
scanLineBufB = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize); |
376 |
scanLineBufA = (unsigned char*) CPLMalloc(sizeof(unsigned char) *(int)BufXSize * (int)BufYSize); |
377 |
|
378 |
GDALRasterIO(rb, GF_Read, (int)nXOff, (int)nYOff, (int)nXSize, (int)nYSize, scanLineBufR, (int)BufXSize, (int)BufYSize, GDT_Byte, 0, 0); |
379 |
|
380 |
hTable = GDALGetRasterColorTable( rb ); |
381 |
|
382 |
if( hTable != NULL ){ |
383 |
int min = GDALGetColorEntryCount( hTable );
|
384 |
dfNoData = GDALGetRasterNoDataValue( rb, &bGotNodata ); |
385 |
if(256 < min) |
386 |
min = 256;
|
387 |
for( i = 0; i < min; i++ ){ |
388 |
GDALColorEntry sEntry; |
389 |
|
390 |
GDALGetColorEntryAsRGB( hTable, i, &sEntry ); |
391 |
abyPCT[i][0] = sEntry.c1;
|
392 |
abyPCT[i][1] = sEntry.c2;
|
393 |
abyPCT[i][2] = sEntry.c3;
|
394 |
abyPCT[i][3] = sEntry.c4;
|
395 |
if(sEntry.c4 == 0){ |
396 |
abyPCT[i][0] = 255; |
397 |
abyPCT[i][1] = 255; |
398 |
abyPCT[i][2] = 255; |
399 |
abyPCT[i][3] = 0; |
400 |
} |
401 |
//printf("%d %d %d %d\n", sEntry.c1,sEntry.c2, sEntry.c3,sEntry.c4);
|
402 |
} |
403 |
|
404 |
for( i = GDALGetColorEntryCount( hTable ); i < 256; i++ ){ |
405 |
abyPCT[i][0] = 0; |
406 |
abyPCT[i][1] = 0; |
407 |
abyPCT[i][2] = 0; |
408 |
abyPCT[i][3] = 255; |
409 |
} |
410 |
|
411 |
for( i = nXSize * nYSize - 1; i >= 0; i-- ){ |
412 |
scanLineBufG[i] = abyPCT[scanLineBufR[i]][1];
|
413 |
scanLineBufB[i] = abyPCT[scanLineBufR[i]][2];
|
414 |
scanLineBufA[i] = abyPCT[scanLineBufR[i]][3];
|
415 |
scanLineBufR[i] = abyPCT[scanLineBufR[i]][0];
|
416 |
} |
417 |
//printf("-%d %d %d %d\n", scanLineBufR[0], scanLineBufG[0], scanLineBufB[0],scanLineBufA[0]);
|
418 |
} |
419 |
|
420 |
bytearrayR = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
|
421 |
bytearrayG = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
|
422 |
bytearrayB = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
|
423 |
bytearrayA = (*env)->NewByteArray(env,(int)(BufXSize*BufYSize));
|
424 |
if(bytearrayR!=NULL){ |
425 |
(*env)->SetByteArrayRegion(env, bytearrayR, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufR); |
426 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campoR, bytearrayR); |
427 |
} |
428 |
if(scanLineBufR != NULL) |
429 |
CPLFree(scanLineBufR); |
430 |
|
431 |
if(bytearrayG!=NULL){ |
432 |
(*env)->SetByteArrayRegion(env, bytearrayG, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufG); |
433 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campoG, bytearrayG); |
434 |
} |
435 |
if(scanLineBufG != NULL) |
436 |
CPLFree(scanLineBufG); |
437 |
|
438 |
if(bytearrayB!=NULL){ |
439 |
(*env)->SetByteArrayRegion(env, bytearrayB, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufB); |
440 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campoB, bytearrayB); |
441 |
} |
442 |
if(scanLineBufB != NULL) |
443 |
CPLFree(scanLineBufB); |
444 |
|
445 |
if(bytearrayA!=NULL){ |
446 |
(*env)->SetByteArrayRegion(env, bytearrayA, 0, (int)(BufXSize*BufYSize),(jbyte *)scanLineBufA); |
447 |
(*env)->SetObjectField(env, obj_gdalbuffer, id_campoA, bytearrayA); |
448 |
} |
449 |
if(scanLineBufA != NULL) |
450 |
CPLFree(scanLineBufA); |
451 |
|
452 |
} |
453 |
} |
454 |
//CPLFree(hTable);
|
455 |
|
456 |
return obj_gdalbuffer;
|
457 |
|
458 |
} |
459 |
|
460 |
/******************************************************************************/
|
461 |
// GetRasterColorTable
|
462 |
/******************************************************************************/
|
463 |
|
464 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorTableNat |
465 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
466 |
|
467 |
GDALColorTableH hTable = NULL;
|
468 |
jlong jresult = 0;
|
469 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
470 |
|
471 |
rb = *(GDALRasterBandH **)&cPtr; |
472 |
hTable = GDALGetRasterColorTable( rb ); |
473 |
|
474 |
*(GDALColorTableH **)&jresult = hTable; |
475 |
|
476 |
if(hTable == NULL) |
477 |
return -1; |
478 |
else
|
479 |
return jresult;
|
480 |
} |
481 |
|
482 |
/******************************************************************************/
|
483 |
// GetBlockXSize
|
484 |
/******************************************************************************/
|
485 |
|
486 |
|
487 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockXSizeNat |
488 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
489 |
|
490 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
491 |
int pnXSize=-1,pnYSize=-1; |
492 |
|
493 |
rb = *(GDALRasterBandH **)&cPtr; |
494 |
|
495 |
if(rb!=NULL) |
496 |
GDALGetBlockSize( rb,&pnXSize, &pnYSize ); |
497 |
|
498 |
return pnXSize;
|
499 |
} |
500 |
|
501 |
|
502 |
/******************************************************************************/
|
503 |
// WriteRaster
|
504 |
/******************************************************************************/
|
505 |
|
506 |
JNIEXPORT void JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_writeRasterNat
|
507 |
(JNIEnv *env, jobject obj, jlong cPtr, jint nXOff, jint nYOff, jint nXSize, jint nYSize, jobject buffer, jint eBufType){ |
508 |
|
509 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
510 |
jclass clase; |
511 |
jfieldID id_campo; |
512 |
jmethodID metodo; |
513 |
jbyteArray bytearray; |
514 |
int tam;
|
515 |
unsigned char *abyRaster; |
516 |
|
517 |
char funcion[11]; |
518 |
char signature[3]; |
519 |
|
520 |
switch(eBufType){
|
521 |
case 1: |
522 |
strncpy(funcion,"buffByte\0",9); |
523 |
strncpy(signature,"[B\0",3); |
524 |
break;
|
525 |
case 2: |
526 |
case 3: |
527 |
case 8: |
528 |
strncpy(funcion,"buffShort\0",10); |
529 |
strncpy(signature,"[S\0",3); |
530 |
break;
|
531 |
case 4: |
532 |
case 5: |
533 |
case 9: |
534 |
strncpy(funcion,"buffInt\0",8); |
535 |
strncpy(signature,"[I\0",3); |
536 |
break;
|
537 |
case 6: |
538 |
case 10: |
539 |
strncpy(funcion,"buffFloat\0",10); |
540 |
strncpy(signature,"[F\0",3); |
541 |
break;
|
542 |
case 7: |
543 |
case 11: |
544 |
strncpy(funcion,"buffDouble\0",11); |
545 |
strncpy(signature,"[D\0",3); |
546 |
break;
|
547 |
} |
548 |
|
549 |
|
550 |
clase = (*env)->GetObjectClass(env, buffer); |
551 |
id_campo = (*env)->GetFieldID(env, clase, funcion, signature); |
552 |
metodo = (*env)->GetMethodID(env, clase, "getSize","()I"); |
553 |
tam = (*env)->CallIntMethod(env,buffer,metodo); |
554 |
|
555 |
bytearray =(jbyteArray)(*env)->GetObjectField(env, buffer, id_campo); |
556 |
|
557 |
abyRaster=(unsigned char *)malloc(sizeof(unsigned char)*tam); |
558 |
|
559 |
if(bytearray!=NULL){ |
560 |
(*env)->GetByteArrayRegion(env,bytearray,0,tam,(jbyte *)abyRaster);
|
561 |
} |
562 |
|
563 |
rb = *(GDALRasterBandH **)&cPtr; |
564 |
|
565 |
if(rb!=NULL) |
566 |
GDALRasterIO( rb, GF_Write, nXOff, nYOff, nXSize, nYSize, |
567 |
abyRaster, nXSize, nYSize, eBufType, 0, 0 ); |
568 |
|
569 |
free(abyRaster); |
570 |
} |
571 |
|
572 |
/******************************************************************************/
|
573 |
// GetBlockYSize
|
574 |
/******************************************************************************/
|
575 |
|
576 |
|
577 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getBlockYSizeNat |
578 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
579 |
|
580 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
581 |
int pnXSize=-1,pnYSize=-1; |
582 |
|
583 |
rb = *(GDALRasterBandH **)&cPtr; |
584 |
|
585 |
if(rb!=NULL) |
586 |
GDALGetBlockSize( rb,&pnXSize, &pnYSize ); |
587 |
|
588 |
return pnYSize;
|
589 |
} |
590 |
|
591 |
/******************************************************************************/
|
592 |
// GetRasterDataType
|
593 |
/******************************************************************************/
|
594 |
|
595 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_JNIBase_getRasterDataTypeNat |
596 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
597 |
|
598 |
int datatype = -1; |
599 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
600 |
|
601 |
rb = *(GDALRasterBandH **)&cPtr; |
602 |
|
603 |
if(rb!=NULL) |
604 |
datatype = GDALGetRasterDataType( rb ); |
605 |
|
606 |
return datatype;
|
607 |
} |
608 |
|
609 |
/******************************************************************************/
|
610 |
// GetRasterNoDataValue
|
611 |
/******************************************************************************/
|
612 |
|
613 |
JNIEXPORT jdouble JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterNoDataValueNat |
614 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
615 |
|
616 |
double nodata = -1; |
617 |
int bGotNodata = 0; |
618 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
619 |
|
620 |
rb = *(GDALRasterBandH **)&cPtr; |
621 |
|
622 |
if(rb!=NULL) |
623 |
nodata = GDALGetRasterNoDataValue( rb, &bGotNodata ); |
624 |
|
625 |
return nodata;
|
626 |
} |
627 |
|
628 |
/******************************************************************************/
|
629 |
// GetMetadata
|
630 |
/******************************************************************************/
|
631 |
|
632 |
JNIEXPORT jobjectArray JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getMetadataNat |
633 |
(JNIEnv *env, jobject obj, jlong cPtr, jstring pszDomain){ |
634 |
|
635 |
char **papszMetadata;
|
636 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
637 |
int i, nmetadatos;
|
638 |
|
639 |
jclass class_string; |
640 |
jobjectArray vector_str; |
641 |
|
642 |
//Obtenemos los metadatos sobre papszMetadata
|
643 |
|
644 |
rb = *(GDALRasterBandH **)&cPtr; |
645 |
|
646 |
|
647 |
if(rb!=NULL){ |
648 |
papszMetadata = GDALGetMetadata( rb, NULL );
|
649 |
|
650 |
|
651 |
//Si hay metadatos devolvemos creamos el vector de String de java y los devolvemos
|
652 |
|
653 |
nmetadatos = CSLCount(papszMetadata); |
654 |
if( nmetadatos > 0 ) |
655 |
{ |
656 |
class_string = (*env)->FindClass (env, "java/lang/String");
|
657 |
vector_str=(*env)->NewObjectArray(env, nmetadatos, class_string, (*env)->NewStringUTF(env,""));
|
658 |
|
659 |
//Cargamos los metadatos
|
660 |
|
661 |
for( i = 0; papszMetadata[i] != NULL; i++ ) |
662 |
(*env)->SetObjectArrayElement(env,vector_str,i,(*env)->NewStringUTF(env,papszMetadata[i])); |
663 |
|
664 |
return vector_str;
|
665 |
} |
666 |
} |
667 |
|
668 |
return NULL; |
669 |
} |
670 |
|
671 |
/******************************************************************************/
|
672 |
// GetRasterColorInterpretation
|
673 |
/******************************************************************************/
|
674 |
|
675 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jgdal_GdalRasterBand_getRasterColorInterpretationNat |
676 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
677 |
GDALRasterBandH *rb = (GDALRasterBandH *) 0 ;
|
678 |
int interp;
|
679 |
|
680 |
rb = *(GDALRasterBandH **)&cPtr; |
681 |
interp = GDALGetRasterColorInterpretation(rb); |
682 |
|
683 |
return (jint)interp;
|
684 |
} |
685 |
|