Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-proj4 / src / crsJniProj.c @ 8405

History | View | Annotate | Download (9.28 KB)

1
 /**********************************************************************
2
 * $Id: crsJniProj.c,v 1.9 2006/09/07 10:38:13
3
 *
4
 * Name:     crsJniProj.c
5
 * Project:  Proj-4.4.9. Cartographic Projections library(Gerald Evenden).
6
 * Purpose:  Projections Basic Funcions.
7
 * Author:   Miguel Garcia Jimenez, garciajimenez.miguel@gmail.com
8
 * Collaborator: Jose Luis Gomez Martinez, jolugomar@gmail.com
9
 *               David Hernandez Lopez , dhernan@agr-ab.uclm.es
10
 *
11
 **********************************************************************/
12
/* gvSIG. Sistema de Informacion Geografica de la Generalitat Valenciana
13
*
14
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
*
16
* This program is free software; you can redistribute it and/or
17
* modify it under the terms of the GNU General Public License
18
* as published by the Free Software Foundation; either version 2
19
* of the License, or (at your option) any later version.
20
*
21
* This program is distributed in the hope that it will be useful,
22
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
* GNU General Public License for more details.
25
*
26
* You should have received a copy of the GNU General Public License
27
* along with this program; if not, write to the Free Software
28
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
*
30
*/
31

    
32
#include "projects.h"
33
#include <jni.h>
34
#include <proj_api.h>
35

    
36
#define arraysize 300
37

    
38
//Realizar una operacion entre CRS, pasando como parametros tres arrays de doubles(puntos)
39
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseOperation_operation
40
  (JNIEnv * env, jobject parent, jdoubleArray firstcoord, jdoubleArray secondcoord, jdoubleArray values, jlong src, jlong dest)
41
{
42
 int i;
43
 projPJ src_pj, dst_pj; // comprobar si se puede quitar
44
 src_pj = src;
45
 dst_pj = dest;
46
 double *xcoord = (* env)-> GetDoubleArrayElements(env, firstcoord, NULL);
47
 double *ycoord = (* env) -> GetDoubleArrayElements(env, secondcoord, NULL);
48
 double *zcoord = (* env) -> GetDoubleArrayElements(env, values, NULL);
49
 jint sizeofdata = (*env)->GetArrayLength(env, firstcoord);
50
 if(src_pj->is_latlong == 1)
51
 {
52
     for(i = 0;i<sizeofdata;i++)
53
     {
54
      *xcoord = *xcoord / (180/PI);
55
      *ycoord = *ycoord / (180/PI);
56

    
57
      pj_transform( src_pj, dst_pj,1,1, xcoord, ycoord, zcoord);
58
      if(dst_pj->is_latlong == 1)
59
      {
60
           *xcoord = *xcoord * (180/PI);
61
           *ycoord = *ycoord * (180/PI);
62

    
63
       }
64
       xcoord++;
65
       ycoord++;
66
       zcoord++;
67
      }
68
 }
69
 if(src_pj->is_latlong == 0)
70
  {
71
    for(i = 0;i<sizeofdata;i++)
72
     {
73
      pj_transform( src_pj, dst_pj,1,1, xcoord, ycoord, zcoord);
74

    
75
      if(dst_pj->is_latlong == 1)
76
      {
77
         *xcoord = *xcoord * (180/PI);
78
         *ycoord = *ycoord * (180/PI);
79
      }
80
      xcoord++;
81
      ycoord++;
82
      zcoord++;
83
     }
84
  }
85
 xcoord = xcoord - sizeofdata;
86
 ycoord = ycoord - sizeofdata;
87
 zcoord = zcoord - sizeofdata;
88
 (* env)->ReleaseDoubleArrayElements(env,firstcoord,(jdouble *) xcoord,JNI_COMMIT);
89
 (* env)->ReleaseDoubleArrayElements(env,secondcoord,(jdouble *) ycoord,JNI_COMMIT);
90
 (* env)->ReleaseDoubleArrayElements(env,values,(jdouble *) zcoord,JNI_COMMIT);
91
 return 1; // pendiente de analizar error
92
}
93

    
94
//Realizar una operacion entre CRS, pasando como parametros tres doubles(puntos)
95

    
96
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseOperation_operationSimple
97
  (JNIEnv * env, jobject parent, jdouble firstcoord, jdouble secondcoord, jdouble values, jlong src, jlong dest)
98
{
99
 int i;
100
 projPJ src_pj, dst_pj; // comprobar si se puede quitar
101
 src_pj = src;
102
 dst_pj = dest;
103

    
104
 double x,y,z;
105
 x=firstcoord;
106
 y=secondcoord;
107
 z=values;
108
 double *xcoord;
109
 double *ycoord;
110
 double *zcoord;
111
 *xcoord = firstcoord;
112
 *ycoord = secondcoord;
113
 *zcoord = values;
114

    
115
 if(src_pj->is_latlong == 1)
116
 {
117
   *xcoord = *xcoord / (180/PI);
118
   *ycoord = *ycoord / (180/PI);
119
 }
120

    
121
 pj_transform( src_pj, dst_pj,1,1, xcoord,ycoord,zcoord);
122

    
123
 if(dst_pj->is_latlong == 1)
124
 {
125
   *xcoord = *xcoord * (180/PI);
126
   *ycoord = *ycoord * (180/PI);
127
 }
128

    
129
 firstcoord =*xcoord;
130
 secondcoord =*ycoord;
131
 values =*zcoord;
132

    
133
 return 1; // pendiente de analizar error
134
}
135

    
136
//Realizar una operacion entre CRS, pasando como parametro un array de tres dobles(puntos)
137

    
138
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseOperation_operationArraySimple
139
  (JNIEnv * env, jobject parent, jdoubleArray coord, jlong src, jlong dest)
140
{
141

    
142
 projPJ src_pj, dst_pj; // comprobar si se puede quitar
143
 src_pj = src;
144
 dst_pj = dest;
145
 double *zcoord = (* env)-> GetDoubleArrayElements(env, coord, NULL);
146
 double *xcoord = zcoord++;
147
 double *ycoord = zcoord++;
148

    
149
 if(src_pj->is_latlong == 1)
150
 {
151
   *xcoord = *xcoord / (180/PI);
152
   *ycoord = *ycoord / (180/PI);
153
 }
154

    
155
 pj_transform( src_pj, dst_pj,1,1, xcoord, ycoord, zcoord);
156

    
157
 if(dst_pj->is_latlong == 1)
158
 {
159
    *xcoord = *xcoord * (180/PI);
160
    *ycoord = *ycoord * (180/PI);
161
 }
162

    
163
 (* env)->ReleaseDoubleArrayElements(env,coord,(jdouble *) xcoord,JNI_COMMIT);
164

    
165
 return 1; // pendiente de analizar error
166
}
167

    
168
//Crea un CRS a partir de una cadena proj4, devolviendo la direccion de memoria del CRS
169

    
170
JNIEXPORT projPJ JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_loadCrs
171
  (JNIEnv * env, jobject parent, jstring strCrs)
172
{
173
        projPJ src_pj;
174
        char * srcproj_def = (char *) (*env)->GetStringUTFChars (env, strCrs, 0);
175
        if (!(src_pj = pj_init_plus(srcproj_def))) return 0;
176
        return src_pj;
177
}
178

    
179
//Libera la direccion de memoria del CRS creado
180

    
181
JNIEXPORT void JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_freeCrs
182
  (JNIEnv * env, jobject parent, jlong crs )
183
{
184
    projPJ proj_pj;
185
    proj_pj = crs;
186
        pj_free( proj_pj );
187
}
188

    
189
//Devuelve un 1 si el CRS es latlong,  un 0 en caso contrario o un codigo de error (negativo) si el crs no está bien creado.
190

    
191
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_isLatlong
192
  (JNIEnv * env, jobject parent, jlong crs)
193
  {
194
          projPJ proj_pj = crs;
195

    
196
    int *errno = pj_get_errno_ref();
197
    if(*errno>=0)
198
        return proj_pj->is_latlong;
199
    else
200
        return *errno;
201
  }
202

    
203

    
204
//Devuelve el codigo de error correspondiente al ultimo crs creado.
205

    
206
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_getErrno
207
  (JNIEnv * env, jobject parent)
208
  {
209
    int *errno = pj_get_errno_ref();
210
    return *errno;
211
  }
212

    
213

    
214
  //Traduce un codigo de error a su correspondiente mensaje.
215

    
216
  JNIEXPORT jstring JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_strErrno
217
  (JNIEnv * env, jobject parent, jint errno)
218
  {
219
    int err = errno;
220
    char * strerr = pj_strerrno(err);
221
    return (*env)->NewStringUTF(env,strerr);
222
  }
223

    
224

    
225
/*!
226
 * \brief
227
 * retrieves projection parameters
228
 *
229
 * JNI informations:
230
 * Class:     org_proj4_Projections
231
 * Method:    getProjInfo
232
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
233
 *
234
 *
235
 * \param env - parameter used by jni (see JNI specification)
236
 * \param parent - parameter used by jni (see JNI specification)
237
 * \param projdefinition - definition of the projection
238
*/
239
/*
240
JNIEXPORT jstring JNICALL Java_org_proj4_Projections_getProjInfo
241
  (JNIEnv * env, jobject parent, jstring projdefinition)
242
{
243
 PJ *pj;
244
 char * pjdesc;
245
 char info[arraysize];
246

247
 char * proj_def = (char *) (*env)->GetStringUTFChars (env, projdefinition, 0);
248

249
 if (!(pj = pj_init_plus(proj_def)))
250
  exit(1);
251

252
 // put together all the info of the projection and free the pointer to pjdesc
253
 pjdesc = pj_get_def(pj, 0);
254
 strcpy(info,pjdesc);
255
 pj_dalloc(pjdesc);
256

257
 return (*env)->NewStringUTF(env,info);
258
}
259
*/
260

    
261
/*!
262
 * \brief
263
 * retrieves ellipsoid parameters
264
 *
265
 * JNI informations:
266
 * Class:     org_proj4_Projections
267
 * Method:    getEllipsInfo
268
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
269
 *
270
 *
271
 * \param env - parameter used by jni (see JNI specification)
272
 * \param parent - parameter used by jni (see JNI specification)
273
 * \param projdefinition - definition of the projection
274
*/
275
/*
276
JNIEXPORT jstring JNICALL Java_org_proj4_Projections_getEllipsInfo
277
  (JNIEnv * env, jobject parent, jstring projdefinition)
278
{
279
 PJ *pj;
280
 char * pjdesc;
281
 char ellipseinfo[arraysize];
282
 char temp[50];
283

284
 char * proj_def = (char *) (*env)->GetStringUTFChars (env, projdefinition, 0);
285

286
 if (!(pj = pj_init_plus(proj_def)))
287
  exit(1);
288

289
 // put together all the info of the ellipsoid
290
//  sprintf(temp,"name: %s;", pj->descr);
291
 sprintf(temp,"name: not available;");
292
 strcpy(ellipseinfo,temp);
293
 sprintf(temp,"a: %lf;", pj->a);
294
 strcat(ellipseinfo,temp);
295
 sprintf(temp,"e: %lf;", pj->e);
296
 strcat(ellipseinfo,temp);
297
 sprintf(temp,"es: %lf;", pj->es);
298
 strcat(ellipseinfo,temp);
299
 sprintf(temp,"ra: %lf;", pj->ra);
300
 strcat(ellipseinfo,temp);
301
 sprintf(temp,"one_es: %lf;", pj->one_es);
302
 strcat(ellipseinfo,temp);
303
 sprintf(temp,"rone_es: %lf;", pj->rone_es);
304
 strcat(ellipseinfo,temp);
305
 sprintf(temp,"lam0: %lf;", pj->lam0);
306
 strcat(ellipseinfo,temp);
307
 sprintf(temp,"phi0: %lf;", pj->phi0);
308
 strcat(ellipseinfo,temp);
309
 sprintf(temp,"x0: %lf;", pj->x0);
310
 strcat(ellipseinfo,temp);
311
 sprintf(temp,"y0: %lf;", pj->y0);
312
 strcat(ellipseinfo,temp);
313
 sprintf(temp,"k0: %lf;", pj->k0);
314
 strcat(ellipseinfo,temp);
315
 sprintf(temp,"to_meter: %lf;", pj->to_meter);
316
 strcat(ellipseinfo,temp);
317
 sprintf(temp,"fr_meter: %lf;", pj->fr_meter);
318
 strcat(ellipseinfo,temp);
319

320
 return (*env)->NewStringUTF(env,ellipseinfo);
321
}
322
*/