Statistics
| Revision:

root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.jcrs.lib / src / main / java / org / gvsig / crs / proj / JNIBaseCrs.java @ 264

History | View | Annotate | Download (6.31 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
        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 147 jjdelcerro
        protected void createCrs(String strCrs) throws CrsProjException {
82
            long cPtr;
83
                cPtr=loadCrs(strCrs);
84 264 fdiaz
85
                int errNo = getErrNo();
86 147 jjdelcerro
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
87
                //TODO: Revisarlo en el c�digo jni.
88
                //if (errNo<0 && errNo!=-10) throw new CrsProjException("Error creating CRS: "+strErrNo(errNo));
89
                if (errNo<0 && errNo!=-10) {
90 264 fdiaz
                    throw new CrsProjException("Error creating CRS. Erro code = "+errNo);
91 147 jjdelcerro
                }
92
                this.cPtr = cPtr;
93
                _strCrs=strCrs;
94
        }
95 264 fdiaz
96 147 jjdelcerro
        protected void deleteCrs() {
97
                //if(cPtr>0) freeCrs(cPtr);
98 264 fdiaz
                if(cPtr>0);
99 147 jjdelcerro
        }
100 264 fdiaz
101 147 jjdelcerro
        public boolean isLatlong() {
102
            if (cPtr==0) {
103
                return false;
104
            }
105
                latLong = isLatlong(cPtr);
106
                if(latLong == 0)
107
                        return false;
108
                return true;
109
        }
110 264 fdiaz
111 147 jjdelcerro
        protected long getPtr() {
112
                /*if (cPtr>0)        return cPtr;
113
                else throw new CrsProjException(_strCrs);*/
114
                return cPtr;
115
        }
116 264 fdiaz
117 147 jjdelcerro
        public String getStr() {
118
                return _strCrs;
119
        }
120 264 fdiaz
121 147 jjdelcerro
        public void changeStrCrs(String code) {
122
                _strCrs += code;
123
        }
124 264 fdiaz
125 147 jjdelcerro
        protected int getErrNo(){
126
                return getErrno();
127
        }
128 264 fdiaz
129 147 jjdelcerro
        protected static String strErrNo(int errno){
130
                return strErrno(errno);
131
        }
132 264 fdiaz
133 147 jjdelcerro
        //OPERATIONS
134 264 fdiaz
135 147 jjdelcerro
        public static int operate(double[] firstCoord,
136
                     double[] secondCoord,
137
                     double[] thirdCoord,
138
                     CrsProj srcCrs,
139
                     CrsProj destCrs)
140
                         throws OperationCrsException{
141 264 fdiaz
142 147 jjdelcerro
            long srcCrsPtr = srcCrs.getPtr();
143
            long destCrsPtr = destCrs.getPtr();
144
        if (srcCrsPtr == 0 || destCrsPtr == 0){
145
            throw new OperationCrsException(srcCrs,destCrs, "");
146
        }
147
                int error=operation(firstCoord,secondCoord,thirdCoord,srcCrsPtr,destCrsPtr);
148 264 fdiaz
149 147 jjdelcerro
                // error -38: el punto transformar est� fuera del �mbito del nadgrid
150
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
151
                //TODO: Revisarlo en el c�digo jni.
152
                //if(error!=0 && error !=-38) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
153
                if(error!=0 && error !=-38) {
154 264 fdiaz
                    throw new OperationCrsException(error, srcCrs,destCrs, "Error code = "+error+", "+strErrno(error));
155 147 jjdelcerro
                }
156
                return error;
157
        }
158
159
        public static void operateSimple(double firstCoord,
160
                                 double secondCoord,
161
                                 double thirdCoord,
162
                                 CrsProj srcCrs,
163
                                 CrsProj destCrs) throws OperationCrsException{
164
        long srcCrsPtr = srcCrs.getPtr();
165
        long destCrsPtr = destCrs.getPtr();
166
        if (srcCrsPtr == 0 || destCrsPtr == 0){
167
            throw new OperationCrsException(srcCrs,destCrs, "");
168
        }
169
                int error = operationSimple(firstCoord, secondCoord, thirdCoord,srcCrsPtr,destCrsPtr);
170
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
171
                //TODO: Revisarlo en el c�digo jni.
172
                //if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
173 264 fdiaz
                if(error!=1) throw new OperationCrsException(error, srcCrs,destCrs, "Error code = "+error+", "+strErrno(error));
174 147 jjdelcerro
        }
175
176
        public static void operateArraySimple(double[] Coord,
177
                                          CrsProj srcCrs,
178
                                          CrsProj destCrs)throws OperationCrsException{
179
        long srcCrsPtr = srcCrs.getPtr();
180
        long destCrsPtr = destCrs.getPtr();
181
        if (srcCrsPtr == 0 || destCrsPtr == 0){
182
            throw new OperationCrsException(srcCrs,destCrs, "");
183
        }
184
                int error = operationArraySimple(Coord,srcCrsPtr,destCrsPtr);
185
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
186
                //TODO: Revisarlo en el c�digo jni.
187
                //if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
188 264 fdiaz
                if(error!=1) throw new OperationCrsException(error, srcCrs,destCrs,"Error code = "+error+", "+strErrno(error));
189 147 jjdelcerro
        }
190 264 fdiaz
191 147 jjdelcerro
        public static int compareDatums(CrsProj crs1, CrsProj crs2){
192
                int compare = 0;
193
        long crs1Ptr = crs1.getPtr();
194
        long cr2Ptr = crs2.getPtr();
195
        if (crs1Ptr == 0 || cr2Ptr == 0){
196
            throw new IllegalArgumentException("Coordinate compare error: " + crs1.getStr() + " to " + crs2.getStr());
197
        }
198 264 fdiaz
                compare = compareDatums(crs1.getPtr(),crs2.getPtr());
199 147 jjdelcerro
                return compare;
200
        }
201
}