Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_901 / libraries / libjni-gdal / src / ogrsfdriver_interfaz.cpp @ 38629

History | View | Annotate | Download (6.09 KB)

1 905 igbrotru
 /**********************************************************************
2
 * $Id$
3
 *
4
 * Name:     ogrsfdriver_interfaz.c
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
9
 **********************************************************************/
10 2210 igbrotru
/* 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 905 igbrotru
51
52
#include <jni.h>
53 920 igbrotru
#include "es_gva_cit_jogr_OGRSFDriver.h"
54
#include "es_gva_cit_jogr_JNIBase.h"
55 905 igbrotru
#include "ogr_api.h"
56
#include "ogrsf_frmts.h"
57
58
/******************************************************************************/
59
//                                                                        getName
60
/******************************************************************************/
61
62 920 igbrotru
 JNIEXPORT jstring JNICALL Java_es_gva_cit_jogr_OGRSFDriver_getNameNat
63 905 igbrotru
  (JNIEnv *env, jobject obj, jlong cPtr){
64
65
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
66
          jstring                                        nom_drv;
67
68
          drv = *(OGRSFDriver **)&cPtr;
69
          const char *name = drv->GetName();
70
71
          if(name!=NULL)
72
                  nom_drv = env->NewStringUTF(name);
73
          else return NULL;
74 1088 igbrotru
75 905 igbrotru
          return nom_drv;
76
  }
77
78 1035 igbrotru
79
80
/******************************************************************************/
81
//                                                                        open                                                                                +
82
/******************************************************************************/
83
84
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRSFDriver_openNat
85
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszName, jboolean bUpdate){
86
87
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
88
          OGRDataSource                         *ds;
89
          long                                         ptr_ds;
90
          drv = *(OGRSFDriver **)&cPtr;
91
92
          const char *name = env->GetStringUTFChars( pszName, 0);
93
          if(bUpdate==true)
94
                  ds=drv->Open(name,1);
95
          else
96
                  ds=drv->Open(name,0);
97
          env->ReleaseStringUTFChars( pszName, name);
98
99
          if(ds==NULL)return -1;
100
101
          ptr_ds = (long)&(*ds);
102
          return (jlong)ptr_ds;
103
104
  }
105
106
/******************************************************************************/
107
//                                                                        testCapability                                                                +
108
/******************************************************************************/
109
110
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSFDriver_testCapabilityNat
111
  (JNIEnv *env, jobject obj, jlong cPtr, jstring cap){
112
113
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
114
          drv = *(OGRSFDriver **)&cPtr;
115
          int res=-1;
116
117
          const char *testcap = env->GetStringUTFChars( cap, 0);
118
          res = drv->TestCapability(testcap);
119
          env->ReleaseStringUTFChars( cap, testcap);
120
          return res;
121
122
  }
123
124
/******************************************************************************/
125
//                                                                        createDataSource
126
/******************************************************************************/
127
128
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRSFDriver_createDataSourceNat
129
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszName){
130
131
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
132
          drv = *(OGRSFDriver **)&cPtr;
133
          OGRDataSource                         *ds;
134
          long                                         ptr_ds;
135
136
          const char *name = env->GetStringUTFChars( pszName, 0);
137
          ds = drv->CreateDataSource(name);
138
          env->ReleaseStringUTFChars( pszName, name);
139
          if(ds==NULL)return -1;
140
141
          ptr_ds = (long)&(*ds);
142
          return (jlong)ptr_ds;
143
  }
144
145
146
/******************************************************************************/
147
//                                                                        deleteDataSource                                                        +
148
/******************************************************************************/
149
150
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSFDriver_deleteDataSourceNat
151
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszName){
152
153
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
154
          drv = *(OGRSFDriver **)&cPtr;
155
          int                                                ogrerr;
156
157
          const char *name = env->GetStringUTFChars( pszName, 0);
158
        ogrerr = drv->DeleteDataSource(name);
159
          env->ReleaseStringUTFChars( pszName, name);
160
          return ogrerr;
161
  }
162
163
/******************************************************************************/
164
//                                                                        copyDataSource                                                                +
165
/******************************************************************************/
166
167
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRSFDriver_copyDataSourceNat
168
  (JNIEnv *env, jobject obj, jlong cPtr, jlong dsSrc, jstring pszNewName, jobjectArray joptions){
169
170
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
171
          char                                         **options;
172
          int                                                longitud;
173
          OGRDataSource                        *ds_fte;
174
          OGRDataSource                        *ds_dstno;
175
          long                                        ptr_dtno;
176
177
          drv = *(OGRSFDriver **)&cPtr;
178
          ds_fte = *(OGRDataSource **)&dsSrc;
179
180
          longitud = env->GetArrayLength(joptions);
181
          options = (char **)malloc(sizeof(char *)*longitud);
182
          for(int i=0;i<longitud;i++){
183
                  jstring el = (jstring)env->GetObjectArrayElement(joptions,i);
184
                  const char *simple_option = env->GetStringUTFChars( el, 0);
185
                  options[i]=(char *)malloc(strlen(simple_option));
186
                  strcpy(options[i],simple_option);
187
                  env->ReleaseStringUTFChars( el, simple_option);
188
          }
189
190
          const char *name = env->GetStringUTFChars( pszNewName, 0);
191
          ds_dstno = drv->CopyDataSource(ds_fte, name, options);
192
          env->ReleaseStringUTFChars( pszNewName, name);
193
194
          for(int i=0;i<longitud;i++)free(options[i]);
195
          free(options);
196
197
          if(ds_dstno==NULL)return -1;
198
199
          ptr_dtno = (long)&(*ds_dstno);
200
          return (jlong)ptr_dtno;
201
202 1088 igbrotru
  }