Statistics
| Revision:

gvsig-raster / org.gvsig.raster.gdal / trunk / org.gvsig.raster.gdal / org.gvsig.raster.gdal.jni / src / main / native / jgdal / ogrsfdriver_interfaz.cpp @ 2453

History | View | Annotate | Download (6.07 KB)

1
 /**********************************************************************
2
 * $Id: ogrsfdriver_interfaz.cpp 7765 2006-10-03 07:05:18Z nacho $
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
/* 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 "ogr_api.h"
54
#include "ogrsf_frmts.h"
55

    
56
/******************************************************************************/
57
//                                                                        getName
58
/******************************************************************************/
59
  
60
 JNIEXPORT jstring JNICALL Java_org_gvsig_jogr_OGRSFDriver_getNameNat
61
  (JNIEnv *env, jobject obj, jlong cPtr){
62
          
63
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
64
          jstring                                        nom_drv;
65
          
66
          drv = *(OGRSFDriver **)&cPtr;
67
          const char *name = drv->GetName();
68
          
69
          if(name!=NULL)
70
                  nom_drv = env->NewStringUTF(name);
71
          else return NULL;
72
                    
73
          return nom_drv;
74
  }
75
  
76
 
77

    
78
/******************************************************************************/
79
//                                                                        open                                                                                +
80
/******************************************************************************/
81

    
82
JNIEXPORT jlong JNICALL Java_org_gvsig_jogr_OGRSFDriver_openNat
83
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszName, jboolean bUpdate){
84
          
85
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
86
          OGRDataSource                         *ds;
87
          long                                         ptr_ds;
88
          drv = *(OGRSFDriver **)&cPtr;
89
        
90
          const char *name = env->GetStringUTFChars( pszName, 0);
91
          if(bUpdate==true)
92
                  ds=drv->Open(name,1);
93
          else
94
                  ds=drv->Open(name,0);
95
          env->ReleaseStringUTFChars( pszName, name);
96
          
97
          if(ds==NULL)return -1;
98
          
99
          ptr_ds = (long)&(*ds);
100
          return (jlong)ptr_ds;
101
          
102
  }
103

    
104
/******************************************************************************/
105
//                                                                        testCapability                                                                +
106
/******************************************************************************/
107

    
108
JNIEXPORT jint JNICALL Java_org_gvsig_jogr_OGRSFDriver_testCapabilityNat
109
  (JNIEnv *env, jobject obj, jlong cPtr, jstring cap){
110
          
111
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
112
          drv = *(OGRSFDriver **)&cPtr;
113
          int res=-1;
114
          
115
          const char *testcap = env->GetStringUTFChars( cap, 0);
116
          res = drv->TestCapability(testcap);
117
          env->ReleaseStringUTFChars( cap, testcap);
118
          return res;
119
          
120
  }
121

    
122
/******************************************************************************/
123
//                                                                        createDataSource
124
/******************************************************************************/
125

    
126
JNIEXPORT jlong JNICALL Java_org_gvsig_jogr_OGRSFDriver_createDataSourceNat
127
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszName){
128
          
129
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
130
          drv = *(OGRSFDriver **)&cPtr;
131
          OGRDataSource                         *ds;
132
          long                                         ptr_ds;
133
          
134
          const char *name = env->GetStringUTFChars( pszName, 0);
135
          ds = drv->CreateDataSource(name);
136
          env->ReleaseStringUTFChars( pszName, name);
137
          if(ds==NULL)return -1;
138
          
139
          ptr_ds = (long)&(*ds);
140
          return (jlong)ptr_ds;
141
  }
142

    
143

    
144
/******************************************************************************/
145
//                                                                        deleteDataSource                                                        +
146
/******************************************************************************/
147

    
148
JNIEXPORT jint JNICALL Java_org_gvsig_jogr_OGRSFDriver_deleteDataSourceNat
149
  (JNIEnv *env, jobject obj, jlong cPtr, jstring pszName){
150
          
151
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
152
          drv = *(OGRSFDriver **)&cPtr;
153
          int                                                ogrerr;
154
          
155
          const char *name = env->GetStringUTFChars( pszName, 0);
156
        ogrerr = drv->DeleteDataSource(name);
157
          env->ReleaseStringUTFChars( pszName, name);
158
          return ogrerr;
159
  }
160

    
161
/******************************************************************************/
162
//                                                                        copyDataSource                                                                +
163
/******************************************************************************/
164

    
165
JNIEXPORT jlong JNICALL Java_org_gvsig_jogr_OGRSFDriver_copyDataSourceNat
166
  (JNIEnv *env, jobject obj, jlong cPtr, jlong dsSrc, jstring pszNewName, jobjectArray joptions){
167
          
168
          OGRSFDriver                         *drv = (OGRSFDriver *) 0 ;
169
          char                                         **options;
170
          int                                                longitud;
171
          OGRDataSource                        *ds_fte;
172
          OGRDataSource                        *ds_dstno;
173
          long                                        ptr_dtno;
174
          
175
          drv = *(OGRSFDriver **)&cPtr;
176
          ds_fte = *(OGRDataSource **)&dsSrc;
177
          
178
          longitud = env->GetArrayLength(joptions);
179
          options = (char **)malloc(sizeof(char *)*longitud);
180
          for(int i=0;i<longitud;i++){
181
                  jstring el = (jstring)env->GetObjectArrayElement(joptions,i);
182
                  const char *simple_option = env->GetStringUTFChars( el, 0);
183
                  options[i]=(char *)malloc(strlen(simple_option));
184
                  strcpy(options[i],simple_option);
185
                  env->ReleaseStringUTFChars( el, simple_option);
186
          }
187
          
188
          const char *name = env->GetStringUTFChars( pszNewName, 0);
189
          ds_dstno = drv->CopyDataSource(ds_fte, name, options);
190
          env->ReleaseStringUTFChars( pszNewName, name);
191
          
192
          for(int i=0;i<longitud;i++)free(options[i]);
193
          free(options);
194
          
195
          if(ds_dstno==NULL)return -1;
196
          
197
          ptr_dtno = (long)&(*ds_dstno);
198
          return (jlong)ptr_dtno;
199
          
200
  }
201