root / trunk / libraries / libjni-gdal / src / ogrdatasource_interfaz.cpp @ 7765
History | View | Annotate | Download (14.2 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: ogrdatasource_interfaz.cpp 7765 2006-10-03 07:05:18Z nacho $
|
3 |
*
|
4 |
* Name: ogrdatasource_interfaz.c
|
5 |
* Project: JGDAL. Interface java to gdal (Frank Warmerdam).
|
6 |
* Purpose:
|
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 |
|
52 |
#include <jni.h> |
53 |
#include "es_gva_cit_jogr_OGRDataSource.h" |
54 |
#include "es_gva_cit_jogr_JNIBase.h" |
55 |
#include "ogr_api.h" |
56 |
#include "ogrsf_frmts.h" |
57 |
|
58 |
|
59 |
|
60 |
/******************************************************************************/
|
61 |
// getName
|
62 |
/******************************************************************************/
|
63 |
|
64 |
JNIEXPORT jstring JNICALL Java_es_gva_cit_jogr_OGRDataSource_getNameNat |
65 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
66 |
|
67 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
68 |
jstring nom_ds; |
69 |
|
70 |
ds = *(OGRDataSource **)&cPtr; |
71 |
const char *name = ds->GetName(); |
72 |
|
73 |
if(name!=NULL) |
74 |
nom_ds = env->NewStringUTF(name); |
75 |
else return NULL; |
76 |
|
77 |
return nom_ds;
|
78 |
|
79 |
} |
80 |
|
81 |
/******************************************************************************/
|
82 |
// getLayerCount
|
83 |
/******************************************************************************/
|
84 |
|
85 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_getLayerCountNat |
86 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
87 |
|
88 |
int res=-1; |
89 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
90 |
|
91 |
ds = *(OGRDataSource **)&cPtr; |
92 |
if(ds!=NULL) |
93 |
res = ds->GetLayerCount(); |
94 |
|
95 |
return res;
|
96 |
} |
97 |
|
98 |
/******************************************************************************/
|
99 |
// getLayer
|
100 |
/******************************************************************************/
|
101 |
|
102 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_getLayerNat |
103 |
(JNIEnv *env, jobject obj, jlong cPtr, jint iLayer){ |
104 |
|
105 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
106 |
OGRLayer *capa; |
107 |
long layer=-1; |
108 |
|
109 |
ds = *(OGRDataSource **)&cPtr; |
110 |
if(ds!=NULL){ |
111 |
capa = ds->GetLayer(iLayer); |
112 |
if(capa!=NULL)layer = (long)&(*capa); |
113 |
} |
114 |
|
115 |
return (jlong)layer;
|
116 |
|
117 |
} |
118 |
|
119 |
/******************************************************************************/
|
120 |
// ~OGRDataSource
|
121 |
/******************************************************************************/
|
122 |
|
123 |
JNIEXPORT void JNICALL Java_es_gva_cit_jogr_OGRDataSource_FreeOGRDataSource
|
124 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
125 |
|
126 |
OGRDataSource *df = (OGRDataSource *) 0 ;
|
127 |
|
128 |
df = *(OGRDataSource **)&cPtr; |
129 |
if(df!=NULL){ |
130 |
delete df;
|
131 |
} |
132 |
} |
133 |
|
134 |
/******************************************************************************/
|
135 |
// reference
|
136 |
/******************************************************************************/
|
137 |
|
138 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_referenceNat |
139 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
140 |
|
141 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
142 |
int res=-1; |
143 |
|
144 |
ds = *(OGRDataSource **)&cPtr; |
145 |
if(ds!=NULL){ |
146 |
res=ds->Reference(); |
147 |
} |
148 |
return res;
|
149 |
|
150 |
} |
151 |
|
152 |
/******************************************************************************/
|
153 |
// dereference
|
154 |
/******************************************************************************/
|
155 |
|
156 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_dereferenceNat |
157 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
158 |
|
159 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
160 |
int res=-1; |
161 |
|
162 |
ds = *(OGRDataSource **)&cPtr; |
163 |
if(ds!=NULL){ |
164 |
res = ds->Dereference(); |
165 |
} |
166 |
return res;
|
167 |
|
168 |
} |
169 |
|
170 |
/******************************************************************************/
|
171 |
// getRefCount
|
172 |
/******************************************************************************/
|
173 |
|
174 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_getRefCountNat |
175 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
176 |
|
177 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
178 |
int res = -1; |
179 |
|
180 |
ds = *(OGRDataSource **)&cPtr; |
181 |
if(ds!=NULL){ |
182 |
res = ds->GetRefCount(); |
183 |
} |
184 |
return res;
|
185 |
|
186 |
|
187 |
} |
188 |
|
189 |
/******************************************************************************/
|
190 |
// getSummaryRefCount
|
191 |
/******************************************************************************/
|
192 |
|
193 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_JNIBase_getSummaryRefCountNat |
194 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
195 |
|
196 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
197 |
int res = -1; |
198 |
|
199 |
ds = *(OGRDataSource **)&cPtr; |
200 |
if(ds!=NULL){ |
201 |
res = ds->GetSummaryRefCount(); |
202 |
} |
203 |
return res;
|
204 |
|
205 |
} |
206 |
|
207 |
/******************************************************************************/
|
208 |
// OGRDataSource
|
209 |
/******************************************************************************/
|
210 |
|
211 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_getLayerByNameNat |
212 |
(JNIEnv *env, jobject obj, jlong cPtr, jstring name){ |
213 |
|
214 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
215 |
const char *layername; |
216 |
OGRLayer *layer; |
217 |
long ptro_layer=-1; |
218 |
|
219 |
ds = *(OGRDataSource **)&cPtr; |
220 |
layername = env->GetStringUTFChars( name, 0 );
|
221 |
if(ds!=NULL){ |
222 |
layer=ds->GetLayerByName(layername); |
223 |
if(layer!=NULL)ptro_layer = (long)&(*layer); |
224 |
} |
225 |
env->ReleaseStringUTFChars( name, layername ); |
226 |
return (jlong)ptro_layer;
|
227 |
} |
228 |
|
229 |
/******************************************************************************/
|
230 |
// deleteLayer
|
231 |
/******************************************************************************/
|
232 |
|
233 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRDataSource_deleteLayerNat |
234 |
(JNIEnv *env, jobject obj, jlong cPtr, jint layer){ |
235 |
|
236 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
237 |
int ogrerr;
|
238 |
|
239 |
ds = *(OGRDataSource **)&cPtr; |
240 |
if(ds!=NULL){ |
241 |
ogrerr = ds->DeleteLayer(layer); |
242 |
} |
243 |
return ogrerr;
|
244 |
} |
245 |
|
246 |
/******************************************************************************/
|
247 |
// testCapability
|
248 |
/******************************************************************************/
|
249 |
|
250 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRDataSource_testCapabilityNat |
251 |
(JNIEnv *env, jobject obj, jlong cPtr, jstring cap){ |
252 |
|
253 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
254 |
int res=-1; |
255 |
const char *capability; |
256 |
|
257 |
ds = *(OGRDataSource **)&cPtr; |
258 |
if(ds!=NULL){ |
259 |
capability = env->GetStringUTFChars( cap, 0 );
|
260 |
res = ds->TestCapability(capability); |
261 |
env->ReleaseStringUTFChars( cap, capability ); |
262 |
} |
263 |
return res;
|
264 |
|
265 |
} |
266 |
|
267 |
/******************************************************************************/
|
268 |
// createLayer
|
269 |
/******************************************************************************/
|
270 |
|
271 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_createLayerNat |
272 |
(JNIEnv *env, jobject obj, jlong cPtr, jstring pszName, jlong poSpatialRef, jstring eGType, jobjectArray papszOptions){ |
273 |
|
274 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
275 |
int longitud;
|
276 |
char **opciones;
|
277 |
OGRLayer *layer_dstno; |
278 |
OGRSpatialReference *spatialRef; |
279 |
long ptr_dtno=-1; |
280 |
OGRwkbGeometryType geomtype; |
281 |
|
282 |
ds = *(OGRDataSource **)&cPtr; |
283 |
|
284 |
spatialRef = *(OGRSpatialReference **)&poSpatialRef; |
285 |
|
286 |
if(ds!=NULL){ |
287 |
longitud = env->GetArrayLength( papszOptions); |
288 |
opciones = (char **)malloc(sizeof(char *)*longitud); |
289 |
for(int i=0;i<longitud;i++){ |
290 |
jstring el = (jstring)env->GetObjectArrayElement(papszOptions,i); |
291 |
const char *simple_option = env->GetStringUTFChars( el, 0); |
292 |
opciones[i]=(char *)malloc(strlen(simple_option));
|
293 |
strcpy(opciones[i],simple_option); |
294 |
env->ReleaseStringUTFChars( el, simple_option); |
295 |
} |
296 |
|
297 |
const char *type = env->GetStringUTFChars( eGType, 0); |
298 |
const char *name = env->GetStringUTFChars( pszName, 0); |
299 |
if(strcmp(type,"wkbUnknown")==0)geomtype = wkbUnknown; |
300 |
else if(strcmp(type,"wkbPoint")==0)geomtype = wkbPoint; |
301 |
else if(strcmp(type,"wkbLineString")==0)geomtype = wkbLineString; |
302 |
else if(strcmp(type,"wkbPolygon")==0)geomtype = wkbPolygon; |
303 |
else if(strcmp(type,"wkbMultiPoint")==0)geomtype = wkbMultiPoint; |
304 |
else if(strcmp(type,"wkbMultiLineString")==0)geomtype = wkbMultiLineString; |
305 |
else if(strcmp(type,"wkbMultiPolygon")==0)geomtype = wkbMultiPolygon; |
306 |
else if(strcmp(type,"wkbGeometryCollection")==0)geomtype = wkbGeometryCollection; |
307 |
else if(strcmp(type,"wkbNone")==0)geomtype = wkbNone; |
308 |
else if(strcmp(type,"wkbLinearRing")==0)geomtype = wkbLinearRing; |
309 |
else if(strcmp(type,"wkbPoint25D")==0)geomtype = wkbPoint25D; |
310 |
else if(strcmp(type,"wkbLineString25D")==0)geomtype = wkbLineString25D; |
311 |
else if(strcmp(type,"wkbPolygon25D")==0)geomtype = wkbPolygon25D; |
312 |
else if(strcmp(type,"wkbMultiPoint25D")==0)geomtype = wkbMultiPoint25D; |
313 |
else if(strcmp(type,"wkbMultiLineString25D")==0)geomtype = wkbMultiLineString25D; |
314 |
else if(strcmp(type,"wkbMultiPolygon25D")==0)geomtype = wkbMultiPolygon25D; |
315 |
else if(strcmp(type,"wkbGeometryCollection25D")==0)geomtype = wkbGeometryCollection25D; |
316 |
|
317 |
layer_dstno = ds->CreateLayer(name, spatialRef, geomtype, opciones); |
318 |
env->ReleaseStringUTFChars( eGType, type); |
319 |
env->ReleaseStringUTFChars( pszName, name); |
320 |
} |
321 |
|
322 |
for(int i=0;i<longitud;i++)free(opciones[i]); |
323 |
free(opciones); |
324 |
|
325 |
if(layer_dstno==NULL)return -1; |
326 |
|
327 |
ptr_dtno = (long)&(*layer_dstno);
|
328 |
return (jlong)ptr_dtno;
|
329 |
} |
330 |
|
331 |
/******************************************************************************/
|
332 |
// copyLayer
|
333 |
/******************************************************************************/
|
334 |
|
335 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_copyLayerNat |
336 |
(JNIEnv *env, jobject obj, jlong cPtr, jlong poSrcLayer, jstring pszNewName, jobjectArray papszOptions){ |
337 |
|
338 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
339 |
int longitud;
|
340 |
char **opciones;
|
341 |
OGRLayer *layer_dstno; |
342 |
OGRLayer *layer; |
343 |
long ptr_dtno=-1; |
344 |
|
345 |
ds = *(OGRDataSource **)&cPtr; |
346 |
layer = *(OGRLayer **)&poSrcLayer; |
347 |
if(ds!=NULL && layer!=NULL){ |
348 |
longitud = env->GetArrayLength( papszOptions); |
349 |
opciones = (char **)malloc(sizeof(char *)*longitud); |
350 |
for(int i=0;i<longitud;i++){ |
351 |
jstring el = (jstring)env->GetObjectArrayElement(papszOptions,i); |
352 |
const char *simple_option = env->GetStringUTFChars( el, 0); |
353 |
opciones[i]=(char *)malloc(strlen(simple_option));
|
354 |
strcpy(opciones[i],simple_option); |
355 |
env->ReleaseStringUTFChars( el, simple_option); |
356 |
} |
357 |
|
358 |
const char *name = env->GetStringUTFChars( pszNewName, 0); |
359 |
layer_dstno = ds->CopyLayer(layer, name, opciones); |
360 |
env->ReleaseStringUTFChars( pszNewName, name); |
361 |
|
362 |
} |
363 |
|
364 |
for(int i=0;i<longitud;i++)free(opciones[i]); |
365 |
free(opciones); |
366 |
|
367 |
if(layer_dstno==NULL)return -1; |
368 |
|
369 |
ptr_dtno = (long)&(*layer_dstno);
|
370 |
return (jlong)ptr_dtno;
|
371 |
} |
372 |
|
373 |
/******************************************************************************/
|
374 |
// getStyleTable
|
375 |
/******************************************************************************/
|
376 |
|
377 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_getStyleTableNat |
378 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
379 |
|
380 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
381 |
OGRStyleTable *styletable; |
382 |
long ptro_styletable=-1; |
383 |
|
384 |
ds = *(OGRDataSource **)&cPtr; |
385 |
if(ds!=NULL){ |
386 |
styletable = ds->GetStyleTable(); |
387 |
if(styletable!=NULL) |
388 |
ptro_styletable = (long)&(*styletable);
|
389 |
} |
390 |
return ptro_styletable;
|
391 |
} |
392 |
|
393 |
/******************************************************************************/
|
394 |
// executeSQL
|
395 |
/******************************************************************************/
|
396 |
|
397 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_executeSQLNat |
398 |
(JNIEnv *env, jobject obj, jlong cPtr, jstring pszStatement, jlong ptr_spatialFilter, jstring pszDialect){ |
399 |
|
400 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
401 |
OGRGeometry *geom = (OGRGeometry *) 0 ;
|
402 |
OGRLayer *layer; |
403 |
long ptro_layer=-1; |
404 |
|
405 |
ds = *(OGRDataSource **)&cPtr; |
406 |
geom = *(OGRGeometry **)&ptr_spatialFilter; |
407 |
if(ds!=NULL ){ |
408 |
const char *stat = env->GetStringUTFChars( pszStatement, 0); |
409 |
const char *dialect = env->GetStringUTFChars( pszDialect, 0); |
410 |
layer = ds->ExecuteSQL(stat, geom, dialect); |
411 |
env->ReleaseStringUTFChars( pszStatement, stat); |
412 |
env->ReleaseStringUTFChars( pszDialect, dialect); |
413 |
if(layer!=NULL) |
414 |
ptro_layer = (long)&(*layer);
|
415 |
} |
416 |
return ptro_layer;
|
417 |
} |
418 |
|
419 |
/******************************************************************************/
|
420 |
// releaseResultSet
|
421 |
/******************************************************************************/
|
422 |
|
423 |
JNIEXPORT void JNICALL Java_es_gva_cit_jogr_OGRDataSource_releaseResultSetNat
|
424 |
(JNIEnv *env, jobject obj, jlong cPtr, jlong ptr_poResultsSet){ |
425 |
|
426 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
427 |
OGRLayer *layer = (OGRLayer *) 0 ;
|
428 |
|
429 |
ds = *(OGRDataSource **)&cPtr; |
430 |
layer = *(OGRLayer **)&ptr_poResultsSet; |
431 |
if(ds!=NULL ){ |
432 |
ds->ReleaseResultSet(layer); |
433 |
} |
434 |
} |
435 |
|
436 |
/******************************************************************************/
|
437 |
// syncToDisk
|
438 |
/******************************************************************************/
|
439 |
|
440 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRDataSource_syncToDiskNat |
441 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
442 |
|
443 |
OGRDataSource *ds = (OGRDataSource *) 0 ;
|
444 |
int ogrerr;
|
445 |
|
446 |
ds = *(OGRDataSource **)&cPtr; |
447 |
if(ds!=NULL ){ |
448 |
ogrerr = ds->SyncToDisk(); |
449 |
} |
450 |
return ogrerr;
|
451 |
} |
452 |
|