svn-gvsig-desktop / tags / v1_9_Build_1246 / libraries / libjni-proj4 / src / jniproj.c @ 33782
History | View | Annotate | Download (4.85 KB)
1 |
/*!
|
---|---|
2 |
* \file jniproj.c
|
3 |
*
|
4 |
* \brief
|
5 |
* functions used by the java/jni wrappers of jproj4
|
6 |
*
|
7 |
*
|
8 |
* $Id: jniproj.c,v 1.1 2004/10/25 14:03:32 fwarmerdam Exp $
|
9 |
*
|
10 |
* \author Antonello Andrea
|
11 |
* \date Wed Oct 20 23:10:24 CEST 2004
|
12 |
*/
|
13 |
#include "proj_config.h" |
14 |
|
15 |
#ifdef JNI_ENABLED
|
16 |
|
17 |
#include "projects.h" |
18 |
#include "org_proj4_Projections.h" |
19 |
#include <jni.h> |
20 |
|
21 |
#define arraysize 300 |
22 |
|
23 |
/*!
|
24 |
* \brief
|
25 |
* executes reprojection
|
26 |
*
|
27 |
* JNI informations:
|
28 |
* Class: org_proj4_Projections
|
29 |
* Method: transform
|
30 |
* Signature: ([D[D[DLjava/lang/String;Ljava/lang/String;JI)V
|
31 |
*
|
32 |
*
|
33 |
* \param env - parameter used by jni (see JNI specification)
|
34 |
* \param parent - parameter used by jni (see JNI specification)
|
35 |
* \param firstcoord - array of x coordinates
|
36 |
* \param secondcoord - array of y coordinates
|
37 |
* \param values - array of z coordinates
|
38 |
* \param src - definition of the source projection
|
39 |
* \param dest - definition of the destination projection
|
40 |
* \param pcount
|
41 |
* \param poffset
|
42 |
*/
|
43 |
JNIEXPORT void JNICALL Java_org_proj4_Projections_transform
|
44 |
(JNIEnv * env, jobject parent, jdoubleArray firstcoord, jdoubleArray secondcoord, jdoubleArray values, jstring src, jstring dest, jlong pcount, jint poffset) |
45 |
{ |
46 |
int i;
|
47 |
projPJ src_pj, dst_pj; |
48 |
char * srcproj_def = (char *) (*env)->GetStringUTFChars (env, src, 0); |
49 |
char * destproj_def = (char *) (*env)->GetStringUTFChars (env, dest, 0); |
50 |
|
51 |
if (!(src_pj = pj_init_plus(srcproj_def)))
|
52 |
exit(1);
|
53 |
if (!(dst_pj = pj_init_plus(destproj_def)))
|
54 |
exit(1);
|
55 |
|
56 |
double *xcoord = (* env)-> GetDoubleArrayElements(env, firstcoord, NULL); |
57 |
double *ycoord = (* env) -> GetDoubleArrayElements(env, secondcoord, NULL); |
58 |
double *zcoord = (* env) -> GetDoubleArrayElements(env, values, NULL); |
59 |
|
60 |
jint sizeofdata = (*env)->GetArrayLength(env, firstcoord); |
61 |
for(i = 0;i<sizeofdata;i++) |
62 |
{ |
63 |
pj_transform( src_pj, dst_pj, pcount,poffset, xcoord, ycoord, zcoord); |
64 |
xcoord++; |
65 |
ycoord++; |
66 |
zcoord++; |
67 |
} |
68 |
xcoord = xcoord - sizeofdata; |
69 |
ycoord = ycoord - sizeofdata; |
70 |
zcoord = zcoord - sizeofdata; |
71 |
|
72 |
(* env)->ReleaseDoubleArrayElements(env,firstcoord,(jdouble *) xcoord,JNI_COMMIT); |
73 |
(* env)->ReleaseDoubleArrayElements(env,secondcoord,(jdouble *) ycoord,JNI_COMMIT); |
74 |
(* env)->ReleaseDoubleArrayElements(env,values,(jdouble *) zcoord,JNI_COMMIT); |
75 |
|
76 |
pj_free( src_pj ); |
77 |
pj_free( dst_pj ); |
78 |
} |
79 |
|
80 |
/*!
|
81 |
* \brief
|
82 |
* retrieves projection parameters
|
83 |
*
|
84 |
* JNI informations:
|
85 |
* Class: org_proj4_Projections
|
86 |
* Method: getProjInfo
|
87 |
* Signature: (Ljava/lang/String;)Ljava/lang/String;
|
88 |
*
|
89 |
*
|
90 |
* \param env - parameter used by jni (see JNI specification)
|
91 |
* \param parent - parameter used by jni (see JNI specification)
|
92 |
* \param projdefinition - definition of the projection
|
93 |
*/
|
94 |
JNIEXPORT jstring JNICALL Java_org_proj4_Projections_getProjInfo |
95 |
(JNIEnv * env, jobject parent, jstring projdefinition) |
96 |
{ |
97 |
PJ *pj; |
98 |
char * pjdesc;
|
99 |
char info[arraysize];
|
100 |
|
101 |
char * proj_def = (char *) (*env)->GetStringUTFChars (env, projdefinition, 0); |
102 |
|
103 |
if (!(pj = pj_init_plus(proj_def)))
|
104 |
exit(1);
|
105 |
|
106 |
// put together all the info of the projection and free the pointer to pjdesc
|
107 |
pjdesc = pj_get_def(pj, 0);
|
108 |
strcpy(info,pjdesc); |
109 |
pj_dalloc(pjdesc); |
110 |
|
111 |
return (*env)->NewStringUTF(env,info);
|
112 |
} |
113 |
|
114 |
|
115 |
/*!
|
116 |
* \brief
|
117 |
* retrieves ellipsoid parameters
|
118 |
*
|
119 |
* JNI informations:
|
120 |
* Class: org_proj4_Projections
|
121 |
* Method: getEllipsInfo
|
122 |
* Signature: (Ljava/lang/String;)Ljava/lang/String;
|
123 |
*
|
124 |
*
|
125 |
* \param env - parameter used by jni (see JNI specification)
|
126 |
* \param parent - parameter used by jni (see JNI specification)
|
127 |
* \param projdefinition - definition of the projection
|
128 |
*/
|
129 |
JNIEXPORT jstring JNICALL Java_org_proj4_Projections_getEllipsInfo |
130 |
(JNIEnv * env, jobject parent, jstring projdefinition) |
131 |
{ |
132 |
PJ *pj; |
133 |
char * pjdesc;
|
134 |
char ellipseinfo[arraysize];
|
135 |
char temp[50]; |
136 |
|
137 |
char * proj_def = (char *) (*env)->GetStringUTFChars (env, projdefinition, 0); |
138 |
|
139 |
if (!(pj = pj_init_plus(proj_def)))
|
140 |
exit(1);
|
141 |
|
142 |
// put together all the info of the ellipsoid
|
143 |
/* sprintf(temp,"name: %s;", pj->descr); */
|
144 |
sprintf(temp,"name: not available;");
|
145 |
strcpy(ellipseinfo,temp); |
146 |
sprintf(temp,"a: %lf;", pj->a);
|
147 |
strcat(ellipseinfo,temp); |
148 |
sprintf(temp,"e: %lf;", pj->e);
|
149 |
strcat(ellipseinfo,temp); |
150 |
sprintf(temp,"es: %lf;", pj->es);
|
151 |
strcat(ellipseinfo,temp); |
152 |
sprintf(temp,"ra: %lf;", pj->ra);
|
153 |
strcat(ellipseinfo,temp); |
154 |
sprintf(temp,"one_es: %lf;", pj->one_es);
|
155 |
strcat(ellipseinfo,temp); |
156 |
sprintf(temp,"rone_es: %lf;", pj->rone_es);
|
157 |
strcat(ellipseinfo,temp); |
158 |
sprintf(temp,"lam0: %lf;", pj->lam0);
|
159 |
strcat(ellipseinfo,temp); |
160 |
sprintf(temp,"phi0: %lf;", pj->phi0);
|
161 |
strcat(ellipseinfo,temp); |
162 |
sprintf(temp,"x0: %lf;", pj->x0);
|
163 |
strcat(ellipseinfo,temp); |
164 |
sprintf(temp,"y0: %lf;", pj->y0);
|
165 |
strcat(ellipseinfo,temp); |
166 |
sprintf(temp,"k0: %lf;", pj->k0);
|
167 |
strcat(ellipseinfo,temp); |
168 |
sprintf(temp,"to_meter: %lf;", pj->to_meter);
|
169 |
strcat(ellipseinfo,temp); |
170 |
sprintf(temp,"fr_meter: %lf;", pj->fr_meter);
|
171 |
strcat(ellipseinfo,temp); |
172 |
|
173 |
return (*env)->NewStringUTF(env,ellipseinfo);
|
174 |
} |
175 |
|
176 |
#endif
|