root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.jcrs.lib / src / main / java / org / gvsig / crs / proj / JNIBaseCrs.java @ 270
History | View | Annotate | Download (9.15 KB)
1 | 147 | jjdelcerro | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib��ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
||
34 | * Campus Universitario s/n
|
||
35 | * 02071 Alabacete
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 967 599 200
|
||
39 | */
|
||
40 | |||
41 | package org.gvsig.crs.proj; |
||
42 | |||
43 | /**
|
||
44 | 264 | fdiaz | *
|
45 | 147 | jjdelcerro | * @author Miguel Garc�a Jim�nez (garciajimenez.miguel@gmail.com)
|
46 | *
|
||
47 | */
|
||
48 | public class JNIBaseCrs |
||
49 | { |
||
50 | protected long cPtr; |
||
51 | protected int latLong; |
||
52 | protected String _strCrs; |
||
53 | protected native long loadCrs(String crs); |
||
54 | protected native void freeCrs(long crs); |
||
55 | protected native int isLatlong(long crs); |
||
56 | protected static native int compareDatums(long datum1, long datum2); |
||
57 | protected native int getErrno(); |
||
58 | 270 | jjdelcerro | //protected static native String strErrno(int errno);
|
59 | 264 | fdiaz | |
60 | |||
61 | 147 | jjdelcerro | protected static native int operation(double[] firstCoord, |
62 | double[] secondCoord, |
||
63 | double[] values, |
||
64 | long srcCodeString,
|
||
65 | long destCodeString);
|
||
66 | |||
67 | protected static native int operationSimple(double firstcoord, |
||
68 | double secondcoord,
|
||
69 | double values,
|
||
70 | long srcCodeString,
|
||
71 | long destCodeString);
|
||
72 | |||
73 | protected static native int operationArraySimple(double[] Coord, |
||
74 | long srcCodeString,
|
||
75 | long destCodeString);
|
||
76 | 264 | fdiaz | |
77 | 147 | jjdelcerro | static {
|
78 | System.loadLibrary("crsjniproj2.0.1"); |
||
79 | } |
||
80 | 264 | fdiaz | |
81 | 270 | jjdelcerro | private static final String[] pj_err_list = new String[]{ |
82 | "no arguments in initialization list", /* -1 */ |
||
83 | "no options found in 'init' file", /* -2 */ |
||
84 | "no colon in init= string", /* -3 */ |
||
85 | "projection not named", /* -4 */ |
||
86 | "unknown projection id", /* -5 */ |
||
87 | "effective eccentricity = 1.", /* -6 */ |
||
88 | "unknown unit conversion id", /* -7 */ |
||
89 | "invalid boolean param argument", /* -8 */ |
||
90 | "unknown elliptical parameter name", /* -9 */ |
||
91 | "reciprocal flattening (1/f) = 0", /* -10 */ |
||
92 | "|radius reference latitude| > 90", /* -11 */ |
||
93 | "squared eccentricity < 0", /* -12 */ |
||
94 | "major axis or radius = 0 or not given", /* -13 */ |
||
95 | "latitude or longitude exceeded limits", /* -14 */ |
||
96 | "invalid x or y", /* -15 */ |
||
97 | "improperly formed DMS value", /* -16 */ |
||
98 | "non-convergent inverse meridinal dist", /* -17 */ |
||
99 | "non-convergent inverse phi2", /* -18 */ |
||
100 | "acos/asin: |arg| >1.+1e-14", /* -19 */ |
||
101 | "tolerance condition error", /* -20 */ |
||
102 | "conic lat_1 = -lat_2", /* -21 */ |
||
103 | "lat_1 >= 90", /* -22 */ |
||
104 | "lat_1 = 0", /* -23 */ |
||
105 | "lat_ts >= 90", /* -24 */ |
||
106 | "no distance between control points", /* -25 */ |
||
107 | "projection not selected to be rotated", /* -26 */ |
||
108 | "W <= 0 or M <= 0", /* -27 */ |
||
109 | "lsat not in 1-5 range", /* -28 */ |
||
110 | "path not in range", /* -29 */ |
||
111 | "h <= 0", /* -30 */ |
||
112 | "k <= 0", /* -31 */ |
||
113 | "lat_0 = 0 or 90 or alpha = 90", /* -32 */ |
||
114 | "lat_1=lat_2 or lat_1=0 or lat_2=90", /* -33 */ |
||
115 | "elliptical usage required", /* -34 */ |
||
116 | "invalid UTM zone number", /* -35 */ |
||
117 | "arg(s) out of range for Tcheby eval", /* -36 */ |
||
118 | "failed to find projection to be rotated", /* -37 */ |
||
119 | "failed to load NAD27-83 correction file", /* -38 */ |
||
120 | "both n & m must be spec'd and > 0", /* -39 */ |
||
121 | "n <= 0, n > 1 or not specified", /* -40 */ |
||
122 | "lat_1 or lat_2 not specified", /* -41 */ |
||
123 | "|lat_1| == |lat_2|", /* -42 */ |
||
124 | "lat_0 is pi/2 from mean lat", /* -43 */ |
||
125 | "unparseable coordinate system definition", /* -44 */ |
||
126 | "geocentric transformation missing z or ellps", /* -45 */ |
||
127 | "unknown prime meridian conversion id", /* -46 */ |
||
128 | }; |
||
129 | |||
130 | public static String strErrno(int errno) { |
||
131 | if( errno>=0 ) { |
||
132 | return "errno "+errno; |
||
133 | } |
||
134 | int i = -errno - 1; |
||
135 | if( i>=pj_err_list.length ) {
|
||
136 | return "invalid projection system error ("+errno+")."; |
||
137 | } |
||
138 | return pj_err_list[i];
|
||
139 | } |
||
140 | |||
141 | |||
142 | 147 | jjdelcerro | protected void createCrs(String strCrs) throws CrsProjException { |
143 | long cPtr;
|
||
144 | cPtr=loadCrs(strCrs); |
||
145 | 264 | fdiaz | |
146 | int errNo = getErrNo();
|
||
147 | 147 | jjdelcerro | // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
|
148 | //TODO: Revisarlo en el c�digo jni.
|
||
149 | //if (errNo<0 && errNo!=-10) throw new CrsProjException("Error creating CRS: "+strErrNo(errNo));
|
||
150 | if (errNo<0 && errNo!=-10) { |
||
151 | 264 | fdiaz | throw new CrsProjException("Error creating CRS. Erro code = "+errNo); |
152 | 147 | jjdelcerro | } |
153 | this.cPtr = cPtr;
|
||
154 | _strCrs=strCrs; |
||
155 | } |
||
156 | 264 | fdiaz | |
157 | 147 | jjdelcerro | protected void deleteCrs() { |
158 | //if(cPtr>0) freeCrs(cPtr);
|
||
159 | 264 | fdiaz | if(cPtr>0); |
160 | 147 | jjdelcerro | } |
161 | 264 | fdiaz | |
162 | 147 | jjdelcerro | public boolean isLatlong() { |
163 | if (cPtr==0) { |
||
164 | return false; |
||
165 | } |
||
166 | latLong = isLatlong(cPtr); |
||
167 | if(latLong == 0) |
||
168 | return false; |
||
169 | return true; |
||
170 | } |
||
171 | 264 | fdiaz | |
172 | 147 | jjdelcerro | protected long getPtr() { |
173 | /*if (cPtr>0) return cPtr;
|
||
174 | else throw new CrsProjException(_strCrs);*/
|
||
175 | return cPtr;
|
||
176 | } |
||
177 | 264 | fdiaz | |
178 | 147 | jjdelcerro | public String getStr() { |
179 | return _strCrs;
|
||
180 | } |
||
181 | 264 | fdiaz | |
182 | 147 | jjdelcerro | public void changeStrCrs(String code) { |
183 | _strCrs += code; |
||
184 | } |
||
185 | 264 | fdiaz | |
186 | 147 | jjdelcerro | protected int getErrNo(){ |
187 | return getErrno();
|
||
188 | } |
||
189 | 264 | fdiaz | |
190 | 147 | jjdelcerro | protected static String strErrNo(int errno){ |
191 | return strErrno(errno);
|
||
192 | } |
||
193 | 264 | fdiaz | |
194 | 147 | jjdelcerro | //OPERATIONS
|
195 | 264 | fdiaz | |
196 | 147 | jjdelcerro | public static int operate(double[] firstCoord, |
197 | double[] secondCoord, |
||
198 | double[] thirdCoord, |
||
199 | CrsProj srcCrs, |
||
200 | CrsProj destCrs) |
||
201 | throws OperationCrsException{
|
||
202 | 264 | fdiaz | |
203 | 147 | jjdelcerro | long srcCrsPtr = srcCrs.getPtr();
|
204 | long destCrsPtr = destCrs.getPtr();
|
||
205 | if (srcCrsPtr == 0 || destCrsPtr == 0){ |
||
206 | throw new OperationCrsException(srcCrs,destCrs, ""); |
||
207 | } |
||
208 | int error=operation(firstCoord,secondCoord,thirdCoord,srcCrsPtr,destCrsPtr);
|
||
209 | 264 | fdiaz | |
210 | 147 | jjdelcerro | // error -38: el punto transformar est� fuera del �mbito del nadgrid
|
211 | // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
|
||
212 | //TODO: Revisarlo en el c�digo jni.
|
||
213 | //if(error!=0 && error !=-38) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
|
||
214 | if(error!=0 && error !=-38) { |
||
215 | 264 | fdiaz | throw new OperationCrsException(error, srcCrs,destCrs, "Error code = "+error+", "+strErrno(error)); |
216 | 147 | jjdelcerro | } |
217 | return error;
|
||
218 | } |
||
219 | |||
220 | public static void operateSimple(double firstCoord, |
||
221 | double secondCoord,
|
||
222 | double thirdCoord,
|
||
223 | CrsProj srcCrs, |
||
224 | CrsProj destCrs) throws OperationCrsException{
|
||
225 | long srcCrsPtr = srcCrs.getPtr();
|
||
226 | long destCrsPtr = destCrs.getPtr();
|
||
227 | if (srcCrsPtr == 0 || destCrsPtr == 0){ |
||
228 | throw new OperationCrsException(srcCrs,destCrs, ""); |
||
229 | } |
||
230 | int error = operationSimple(firstCoord, secondCoord, thirdCoord,srcCrsPtr,destCrsPtr);
|
||
231 | // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
|
||
232 | //TODO: Revisarlo en el c�digo jni.
|
||
233 | //if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
|
||
234 | 264 | fdiaz | if(error!=1) throw new OperationCrsException(error, srcCrs,destCrs, "Error code = "+error+", "+strErrno(error)); |
235 | 147 | jjdelcerro | } |
236 | |||
237 | public static void operateArraySimple(double[] Coord, |
||
238 | CrsProj srcCrs, |
||
239 | CrsProj destCrs)throws OperationCrsException{
|
||
240 | long srcCrsPtr = srcCrs.getPtr();
|
||
241 | long destCrsPtr = destCrs.getPtr();
|
||
242 | if (srcCrsPtr == 0 || destCrsPtr == 0){ |
||
243 | throw new OperationCrsException(srcCrs,destCrs, ""); |
||
244 | } |
||
245 | int error = operationArraySimple(Coord,srcCrsPtr,destCrsPtr);
|
||
246 | // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
|
||
247 | //TODO: Revisarlo en el c�digo jni.
|
||
248 | //if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
|
||
249 | 264 | fdiaz | if(error!=1) throw new OperationCrsException(error, srcCrs,destCrs,"Error code = "+error+", "+strErrno(error)); |
250 | 147 | jjdelcerro | } |
251 | 264 | fdiaz | |
252 | 147 | jjdelcerro | public static int compareDatums(CrsProj crs1, CrsProj crs2){ |
253 | int compare = 0; |
||
254 | long crs1Ptr = crs1.getPtr();
|
||
255 | long cr2Ptr = crs2.getPtr();
|
||
256 | if (crs1Ptr == 0 || cr2Ptr == 0){ |
||
257 | throw new IllegalArgumentException("Coordinate compare error: " + crs1.getStr() + " to " + crs2.getStr()); |
||
258 | } |
||
259 | 264 | fdiaz | compare = compareDatums(crs1.getPtr(),crs2.getPtr()); |
260 | 147 | jjdelcerro | return compare;
|
261 | } |
||
262 | } |