Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / libraries / libjni-gdal / src / ogrspatialreference_interfaz.c @ 8745

History | View | Annotate | Download (9.35 KB)

1
 /**********************************************************************
2
 * $Id: ogrspatialreference_interfaz.c,v 1.9 2006/06/10 12:50:13
3
 *
4
 * Name:     OGRSpatialReference_interfaz.c
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:  dataset's Basic Funcions.
7
 * Author:   Miguel Garcia Jiemenez, garciajimenez.miguel@gmail.com
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_JNIBase.h"
54
#include "gdal.h"
55
#include "cpl_string.h"
56
#include "ogr_api.h"
57
#include "ogr_srs_api.h"
58

    
59
/******************************************************************************/
60
//                                                        OGRSpatialReference
61
/******************************************************************************/
62

    
63
JNIEXPORT jlong JNICALL Java_org_gvsig_crs_ogr_JNIBase_OGRSpatialReferenceNat
64
  (JNIEnv * env, jobject obj){
65

    
66
          OGRSpatialReferenceH *hSRS;
67
          jlong jresult=0;
68
          hSRS=(OGRSpatialReferenceH*)malloc(sizeof(OGRSpatialReferenceH));
69

    
70
         *hSRS = OSRNewSpatialReference( NULL );
71
          *(OGRSpatialReferenceH **)&jresult = hSRS;
72

    
73
          //printf("-------->%ld\n",(long)jresult);
74
          return (long)jresult;
75
  }
76

    
77
/******************************************************************************/
78
//                                                                exportToWkt
79
/******************************************************************************/
80

    
81
JNIEXPORT jstring JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_exportToWktNat
82
  (JNIEnv *env, jobject obj, jlong cPtr){
83

    
84
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
85
          jstring wkt;
86
          char *pszSRS_WKT = NULL;
87

    
88
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
89

    
90
          if(hSRS!=NULL){
91
                   OSRExportToWkt( *hSRS, &pszSRS_WKT );
92
                   if(pszSRS_WKT!=NULL){
93
                        wkt = (*env)->NewStringUTF(env, pszSRS_WKT);
94
                        return wkt;
95
                   }
96
          }
97

    
98
          return NULL;
99
  }
100
/******************************************************************************/
101
//                                                        OSRDestroySpatialReference
102
/******************************************************************************/
103

    
104
JNIEXPORT void JNICALL Java_org_gvsig_crs_ogr_JNIBase_OGRDestroySpatialReferenceNat
105
  (JNIEnv *env, jobject obj, jlong cPtr){
106

    
107
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
108

    
109
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
110

    
111
          if(hSRS!=NULL){
112
                  OSRDestroySpatialReference(*hSRS);
113
          }
114
  }
115

    
116
/******************************************************************************/
117
//                                                                importFromWkt
118
/******************************************************************************/
119
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_importFromWktNat
120
  (JNIEnv *env, jobject obj, jlong cPtr, jstring cs){
121

    
122
    OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
123
    jint err;
124

    
125
    hSRS = *(OGRSpatialReferenceH **)&cPtr;
126
    if(hSRS!=NULL){
127
                char *cad = (*env)->GetStringUTFChars(env, cs, 0);
128
            err = OSRImportFromWkt( *hSRS,&cad);
129
            return err;
130
    }
131

    
132
    return err;
133
 }
134

    
135
/******************************************************************************/
136
//                                                                setUTM
137
/******************************************************************************/
138

    
139
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_setUTMNat
140
  (JNIEnv *env, jobject obj, jlong cPtr, jint zona, jint norte_sur){
141

    
142
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
143
          jint err;
144

    
145
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
146
          if(hSRS!=NULL){
147
                  err = OSRSetUTM( *hSRS, zona, norte_sur );
148
                 return err;
149
          }
150
          return err;
151
  }
152

    
153
/******************************************************************************/
154
//                                                        setWellKnownGeogCS
155
/******************************************************************************/
156

    
157
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_setWellKnownGeogCSNat
158
  (JNIEnv *env, jobject obj, jlong cPtr, jstring cs){
159

    
160
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0;
161
          jint err;
162

    
163
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
164
          if(hSRS!=NULL){
165
                  const char *coord_sys = (*env)->GetStringUTFChars(env, cs, 0);
166
                  err = OSRSetWellKnownGeogCS( *hSRS, coord_sys );
167
                  (*env)->ReleaseStringUTFChars(env, cs, coord_sys);
168
                  return err;
169
          }
170

    
171
          return err;
172
  }
173

    
174

    
175
/******************************************************************************/
176
//                                                                importFromEPSG
177
/******************************************************************************/
178

    
179
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_importFromEPSGNat
180
  (JNIEnv *env, jobject obj, jlong cPtr, jint cod){
181

    
182
        OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
183
        jint err;
184
        char *pszSRS_WKT = NULL;
185

    
186
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
187

    
188
          if(hSRS!=NULL){
189
                   err = OSRImportFromEPSG(*hSRS, cod );
190
                    OSRExportToWkt(*hSRS, &pszSRS_WKT);
191
          }
192

    
193
          return err;
194
  }
195

    
196

    
197
/******************************************************************************/
198
//                                                                importFromProj4
199
/******************************************************************************/
200

    
201
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_importFromProj4Nat
202
  (JNIEnv *env, jobject obj, jlong cPtr, jstring cs){
203

    
204
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
205
          jint err;
206

    
207
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
208
          if(hSRS!=NULL){
209
                  const char *coord_sys = (*env)->GetStringUTFChars(env, cs, 0);
210
                  err = OSRImportFromProj4( *hSRS, coord_sys );
211
                  (*env)->ReleaseStringUTFChars(env, cs, coord_sys);
212
                  return err;
213
          }
214

    
215
          return err;
216
  }
217

    
218
/******************************************************************************/
219
//                                                                exportToProj4
220
/******************************************************************************/
221

    
222
JNIEXPORT jstring JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_exportToProj4Nat
223
  (JNIEnv *env, jobject obj, jlong cPtr){
224

    
225
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
226
          jstring wkt;
227
          char *pszSRS_WKT = NULL;
228

    
229
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
230

    
231
          if(hSRS!=NULL){
232
                   OSRExportToProj4( *hSRS, &pszSRS_WKT );
233
                   if(pszSRS_WKT!=NULL){
234
                        wkt = (*env)->NewStringUTF(env, pszSRS_WKT);
235
                        return wkt;
236
                   }
237
          }
238

    
239
          return NULL;
240
  }
241

    
242
/******************************************************************************/
243
//                                                                importFromPCI
244
/******************************************************************************/
245

    
246
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_importFromPCINat
247
  (JNIEnv *env, jobject obj, jlong cPtr,jstring cod, jstring cs, jdoubleArray coord){
248

    
249
          OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
250
          jint err;
251
          double *xcoord = (* env)-> GetDoubleArrayElements(env, coord, NULL);
252

    
253
          hSRS = *(OGRSpatialReferenceH **)&cPtr;
254
          if(hSRS!=NULL){
255
                  const char *coord_sys = (*env)->GetStringUTFChars(env, cs, 0);
256
                  const char *cod_sys = (*env)->GetStringUTFChars(env, cod, 0);
257
                  err = OSRImportFromPCI( *hSRS, cod_sys, coord_sys, xcoord );
258
                  (*env)->ReleaseStringUTFChars(env, cs, coord_sys);
259
                  return err;
260
          }
261
          (* env)->ReleaseDoubleArrayElements(env,coord,(jdouble *) xcoord,JNI_COMMIT);
262

    
263
          return err;
264
  }
265

    
266
/******************************************************************************/
267
//                                                                importFromESRI
268
/******************************************************************************/
269
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_importFromESRINat
270
  (JNIEnv *env, jobject obj, jlong cPtr, jstring cs){
271

    
272
    OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ;
273
    jint err;
274

    
275
    hSRS = *(OGRSpatialReferenceH **)&cPtr;
276
    if(hSRS!=NULL){
277
                char *cad = (*env)->GetStringUTFChars(env, cs, 0);
278
            err = OSRImportFromWkt( *hSRS,&cad);
279
            return err;
280
    }
281

    
282
    return err;
283
 }
284

    
285

    
286
/******************************************************************************/
287
//                                                                importFromUSGS
288
/******************************************************************************/
289
JNIEXPORT jint JNICALL Java_org_gvsig_crs_ogr_JNIBaseCRS_importFromUSGSNat
290
  (JNIEnv *env, jobject obj, jlong cPtr,jlong iProjSys ,jlong iZone, jdoubleArray padfPrjParams, jlong iDatum){
291

    
292
        OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0;
293
        jint err;
294

    
295
        double *params = (* env)-> GetDoubleArrayElements(env, padfPrjParams, NULL);
296
        jint sizeofdata = (* env)-> GetArrayLength(env,padfPrjParams);
297

    
298
        if(sizeofdata != 15){
299
                printf("El tama?o del array de dobles debe ser 15");
300
                 return 5;
301
        }
302

    
303
        hSRS = *(OGRSpatialReferenceH **)&cPtr;
304
        if(hSRS!=NULL){
305
                err = OSRImportFromUSGS(*hSRS, iProjSys, iZone, params, iDatum);
306
                return err;
307
        }
308

    
309
        return err;
310
}
311

    
312