svn-gvsig-desktop / trunk / libraries / libjni-proj4 / src / crsJniProj.c @ 8660
History | View | Annotate | Download (9.43 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_JNIBaseCrs_operation
|
40 |
(JNIEnv * env, jobject parent, jdoubleArray firstcoord, jdoubleArray secondcoord, jdoubleArray values, jlong src, jlong dest) |
41 |
{ |
42 |
int errno = 0; |
43 |
int i;
|
44 |
projPJ src_pj, dst_pj; // comprobar si se puede quitar
|
45 |
src_pj = src; |
46 |
dst_pj = dest; |
47 |
double *xcoord = (* env)-> GetDoubleArrayElements(env, firstcoord, NULL); |
48 |
double *ycoord = (* env) -> GetDoubleArrayElements(env, secondcoord, NULL); |
49 |
double *zcoord = (* env) -> GetDoubleArrayElements(env, values, NULL); |
50 |
jint sizeofdata = (*env)->GetArrayLength(env, firstcoord); |
51 |
if(src_pj->is_latlong == 1) |
52 |
{ |
53 |
for(i = 0;i<sizeofdata;i++) |
54 |
{ |
55 |
*xcoord = *xcoord / (180/PI);
|
56 |
*ycoord = *ycoord / (180/PI);
|
57 |
|
58 |
errno = pj_transform( src_pj, dst_pj,1,1, xcoord, ycoord, zcoord); |
59 |
if(dst_pj->is_latlong == 1) |
60 |
{ |
61 |
*xcoord = *xcoord * (180/PI);
|
62 |
*ycoord = *ycoord * (180/PI);
|
63 |
|
64 |
} |
65 |
xcoord++; |
66 |
ycoord++; |
67 |
zcoord++; |
68 |
} |
69 |
} |
70 |
if(src_pj->is_latlong == 0) |
71 |
{ |
72 |
for(i = 0;i<sizeofdata;i++) |
73 |
{ |
74 |
errno = pj_transform( src_pj, dst_pj,1,1, xcoord, ycoord, zcoord); |
75 |
|
76 |
if(dst_pj->is_latlong == 1) |
77 |
{ |
78 |
*xcoord = *xcoord * (180/PI);
|
79 |
*ycoord = *ycoord * (180/PI);
|
80 |
} |
81 |
xcoord++; |
82 |
ycoord++; |
83 |
zcoord++; |
84 |
} |
85 |
} |
86 |
xcoord = xcoord - sizeofdata; |
87 |
ycoord = ycoord - sizeofdata; |
88 |
zcoord = zcoord - sizeofdata; |
89 |
(* env)->ReleaseDoubleArrayElements(env,firstcoord,(jdouble *) xcoord,JNI_COMMIT); |
90 |
(* env)->ReleaseDoubleArrayElements(env,secondcoord,(jdouble *) ycoord,JNI_COMMIT); |
91 |
(* env)->ReleaseDoubleArrayElements(env,values,(jdouble *) zcoord,JNI_COMMIT); |
92 |
// return 1; // pendiente de analizar error
|
93 |
return errno;
|
94 |
} |
95 |
|
96 |
//Realizar una operacion entre CRS, pasando como parametros tres doubles(puntos)
|
97 |
|
98 |
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_operationSimple
|
99 |
(JNIEnv * env, jobject parent, jdouble firstcoord, jdouble secondcoord, jdouble values, jlong src, jlong dest) |
100 |
{ |
101 |
int errno = 0; |
102 |
int i;
|
103 |
projPJ src_pj, dst_pj; // comprobar si se puede quitar
|
104 |
src_pj = src; |
105 |
dst_pj = dest; |
106 |
|
107 |
double x,y,z;
|
108 |
x=firstcoord; |
109 |
y=secondcoord; |
110 |
z=values; |
111 |
double *xcoord;
|
112 |
double *ycoord;
|
113 |
double *zcoord;
|
114 |
*xcoord = firstcoord; |
115 |
*ycoord = secondcoord; |
116 |
*zcoord = values; |
117 |
|
118 |
if(src_pj->is_latlong == 1) |
119 |
{ |
120 |
*xcoord = *xcoord / (180/PI);
|
121 |
*ycoord = *ycoord / (180/PI);
|
122 |
} |
123 |
|
124 |
errno = pj_transform( src_pj, dst_pj,1,1, xcoord,ycoord,zcoord); |
125 |
|
126 |
if(dst_pj->is_latlong == 1) |
127 |
{ |
128 |
*xcoord = *xcoord * (180/PI);
|
129 |
*ycoord = *ycoord * (180/PI);
|
130 |
} |
131 |
|
132 |
firstcoord =*xcoord; |
133 |
secondcoord =*ycoord; |
134 |
values =*zcoord; |
135 |
|
136 |
// return 1; // pendiente de analizar error
|
137 |
return errno;
|
138 |
} |
139 |
|
140 |
//Realizar una operacion entre CRS, pasando como parametro un array de tres dobles(puntos)
|
141 |
|
142 |
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_operationArraySimple
|
143 |
(JNIEnv * env, jobject parent, jdoubleArray coord, jlong src, jlong dest) |
144 |
{ |
145 |
int errno = 0; |
146 |
projPJ src_pj, dst_pj; // comprobar si se puede quitar
|
147 |
src_pj = src; |
148 |
dst_pj = dest; |
149 |
double *zcoord = (* env)-> GetDoubleArrayElements(env, coord, NULL); |
150 |
double *xcoord = zcoord++;
|
151 |
double *ycoord = zcoord++;
|
152 |
|
153 |
if(src_pj->is_latlong == 1) |
154 |
{ |
155 |
*xcoord = *xcoord / (180/PI);
|
156 |
*ycoord = *ycoord / (180/PI);
|
157 |
} |
158 |
|
159 |
errno = pj_transform( src_pj, dst_pj,1,1, xcoord, ycoord, zcoord); |
160 |
|
161 |
if(dst_pj->is_latlong == 1) |
162 |
{ |
163 |
*xcoord = *xcoord * (180/PI);
|
164 |
*ycoord = *ycoord * (180/PI);
|
165 |
} |
166 |
|
167 |
(* env)->ReleaseDoubleArrayElements(env,coord,(jdouble *) xcoord,JNI_COMMIT); |
168 |
|
169 |
// return 1; // pendiente de analizar error
|
170 |
return errno;
|
171 |
} |
172 |
|
173 |
//Crea un CRS a partir de una cadena proj4, devolviendo la direccion de memoria del CRS
|
174 |
|
175 |
JNIEXPORT projPJ JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_loadCrs |
176 |
(JNIEnv * env, jobject parent, jstring strCrs) |
177 |
{ |
178 |
projPJ src_pj; |
179 |
char * srcproj_def = (char *) (*env)->GetStringUTFChars (env, strCrs, 0); |
180 |
if (!(src_pj = pj_init_plus(srcproj_def))) return 0; |
181 |
return src_pj;
|
182 |
} |
183 |
|
184 |
//Libera la direccion de memoria del CRS creado
|
185 |
|
186 |
JNIEXPORT void JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_freeCrs
|
187 |
(JNIEnv * env, jobject parent, jlong crs ) |
188 |
{ |
189 |
projPJ proj_pj; |
190 |
proj_pj = crs; |
191 |
pj_free( proj_pj ); |
192 |
} |
193 |
|
194 |
//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.
|
195 |
|
196 |
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_isLatlong
|
197 |
(JNIEnv * env, jobject parent, jlong crs) |
198 |
{ |
199 |
projPJ proj_pj = crs; |
200 |
|
201 |
int *errno = pj_get_errno_ref();
|
202 |
if(*errno>=0) |
203 |
return proj_pj->is_latlong;
|
204 |
else
|
205 |
return *errno;
|
206 |
} |
207 |
|
208 |
|
209 |
//Devuelve el codigo de error correspondiente al ultimo crs creado.
|
210 |
|
211 |
JNIEXPORT int JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_getErrno
|
212 |
(JNIEnv * env, jobject parent) |
213 |
{ |
214 |
int *errno = pj_get_errno_ref();
|
215 |
return *errno;
|
216 |
} |
217 |
|
218 |
|
219 |
//Traduce un codigo de error a su correspondiente mensaje.
|
220 |
|
221 |
JNIEXPORT jstring JNICALL Java_org_gvsig_crs_proj_JNIBaseCrs_strErrno |
222 |
(JNIEnv * env, jobject parent, jint errno) |
223 |
{ |
224 |
int err = errno;
|
225 |
char * strerr = pj_strerrno(err);
|
226 |
return (*env)->NewStringUTF(env,strerr);
|
227 |
} |
228 |
|
229 |
|
230 |
/*!
|
231 |
* \brief
|
232 |
* retrieves projection parameters
|
233 |
*
|
234 |
* JNI informations:
|
235 |
* Class: org_proj4_Projections
|
236 |
* Method: getProjInfo
|
237 |
* Signature: (Ljava/lang/String;)Ljava/lang/String;
|
238 |
*
|
239 |
*
|
240 |
* \param env - parameter used by jni (see JNI specification)
|
241 |
* \param parent - parameter used by jni (see JNI specification)
|
242 |
* \param projdefinition - definition of the projection
|
243 |
*/
|
244 |
/*
|
245 |
JNIEXPORT jstring JNICALL Java_org_proj4_Projections_getProjInfo
|
246 |
(JNIEnv * env, jobject parent, jstring projdefinition)
|
247 |
{
|
248 |
PJ *pj;
|
249 |
char * pjdesc;
|
250 |
char info[arraysize];
|
251 |
|
252 |
char * proj_def = (char *) (*env)->GetStringUTFChars (env, projdefinition, 0);
|
253 |
|
254 |
if (!(pj = pj_init_plus(proj_def)))
|
255 |
exit(1);
|
256 |
|
257 |
// put together all the info of the projection and free the pointer to pjdesc
|
258 |
pjdesc = pj_get_def(pj, 0);
|
259 |
strcpy(info,pjdesc);
|
260 |
pj_dalloc(pjdesc);
|
261 |
|
262 |
return (*env)->NewStringUTF(env,info);
|
263 |
}
|
264 |
*/
|
265 |
|
266 |
/*!
|
267 |
* \brief
|
268 |
* retrieves ellipsoid parameters
|
269 |
*
|
270 |
* JNI informations:
|
271 |
* Class: org_proj4_Projections
|
272 |
* Method: getEllipsInfo
|
273 |
* Signature: (Ljava/lang/String;)Ljava/lang/String;
|
274 |
*
|
275 |
*
|
276 |
* \param env - parameter used by jni (see JNI specification)
|
277 |
* \param parent - parameter used by jni (see JNI specification)
|
278 |
* \param projdefinition - definition of the projection
|
279 |
*/
|
280 |
/*
|
281 |
JNIEXPORT jstring JNICALL Java_org_proj4_Projections_getEllipsInfo
|
282 |
(JNIEnv * env, jobject parent, jstring projdefinition)
|
283 |
{
|
284 |
PJ *pj;
|
285 |
char * pjdesc;
|
286 |
char ellipseinfo[arraysize];
|
287 |
char temp[50];
|
288 |
|
289 |
char * proj_def = (char *) (*env)->GetStringUTFChars (env, projdefinition, 0);
|
290 |
|
291 |
if (!(pj = pj_init_plus(proj_def)))
|
292 |
exit(1);
|
293 |
|
294 |
// put together all the info of the ellipsoid
|
295 |
// sprintf(temp,"name: %s;", pj->descr);
|
296 |
sprintf(temp,"name: not available;");
|
297 |
strcpy(ellipseinfo,temp);
|
298 |
sprintf(temp,"a: %lf;", pj->a);
|
299 |
strcat(ellipseinfo,temp);
|
300 |
sprintf(temp,"e: %lf;", pj->e);
|
301 |
strcat(ellipseinfo,temp);
|
302 |
sprintf(temp,"es: %lf;", pj->es);
|
303 |
strcat(ellipseinfo,temp);
|
304 |
sprintf(temp,"ra: %lf;", pj->ra);
|
305 |
strcat(ellipseinfo,temp);
|
306 |
sprintf(temp,"one_es: %lf;", pj->one_es);
|
307 |
strcat(ellipseinfo,temp);
|
308 |
sprintf(temp,"rone_es: %lf;", pj->rone_es);
|
309 |
strcat(ellipseinfo,temp);
|
310 |
sprintf(temp,"lam0: %lf;", pj->lam0);
|
311 |
strcat(ellipseinfo,temp);
|
312 |
sprintf(temp,"phi0: %lf;", pj->phi0);
|
313 |
strcat(ellipseinfo,temp);
|
314 |
sprintf(temp,"x0: %lf;", pj->x0);
|
315 |
strcat(ellipseinfo,temp);
|
316 |
sprintf(temp,"y0: %lf;", pj->y0);
|
317 |
strcat(ellipseinfo,temp);
|
318 |
sprintf(temp,"k0: %lf;", pj->k0);
|
319 |
strcat(ellipseinfo,temp);
|
320 |
sprintf(temp,"to_meter: %lf;", pj->to_meter);
|
321 |
strcat(ellipseinfo,temp);
|
322 |
sprintf(temp,"fr_meter: %lf;", pj->fr_meter);
|
323 |
strcat(ellipseinfo,temp);
|
324 |
|
325 |
return (*env)->NewStringUTF(env,ellipseinfo);
|
326 |
}
|
327 |
*/
|