Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libJCRS / src / org / gvsig / crs / proj / JNIBaseCrs.java @ 33793

History | View | Annotate | Download (5.98 KB)

1 32198 nbrodin
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2 8878 jlgomez
 *
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 32198 nbrodin
 *   Av. Blasco Ib��ez, 50
24 8878 jlgomez
 *   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 8405 dguerrero
package org.gvsig.crs.proj;
42
43 8878 jlgomez
/**
44
 *
45 32198 nbrodin
 * @author Miguel Garc�a Jim�nez (garciajimenez.miguel@gmail.com)
46 8878 jlgomez
 *
47
 */
48 8405 dguerrero
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 8656 dguerrero
        protected static native int compareDatums(long datum1, long datum2);
57 8405 dguerrero
        protected native int getErrno();
58 8656 dguerrero
        protected static native String strErrno(int errno);
59 8405 dguerrero
60 8656 dguerrero
61
        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
77 8405 dguerrero
        static {
78 32198 nbrodin
                System.loadLibrary("crsjniproj2.0.1");
79 8405 dguerrero
        }
80
81
        protected void createCrs(String strCrs) throws CrsProjException {
82 33682 fdiaz
            long cPtr;
83 8405 dguerrero
                cPtr=loadCrs(strCrs);
84
85
                int errNo = getErrNo();
86 32198 nbrodin
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
87
                //TODO: Revisarlo en el c�digo jni.
88 23536 dguerrero
                //if (errNo<0 && errNo!=-10) throw new CrsProjException("Error creating CRS: "+strErrNo(errNo));
89 33682 fdiaz
                if (errNo<0 && errNo!=-10) {
90
                    throw new CrsProjException("Error creating CRS.");
91
                }
92
                this.cPtr = cPtr;
93 8405 dguerrero
                _strCrs=strCrs;
94
        }
95
96
        protected void deleteCrs() {
97 12279 dguerrero
                //if(cPtr>0) freeCrs(cPtr);
98
                if(cPtr>0);
99 8405 dguerrero
        }
100
101
        public boolean isLatlong() {
102 33682 fdiaz
            if (cPtr==0) {
103
                return false;
104
            }
105 8405 dguerrero
                latLong = isLatlong(cPtr);
106
                if(latLong == 0)
107
                        return false;
108
                return true;
109
        }
110
111 12527 dguerrero
        protected long getPtr() {
112 12279 dguerrero
                /*if (cPtr>0)        return cPtr;
113
                else throw new CrsProjException(_strCrs);*/
114
                return cPtr;
115 8405 dguerrero
        }
116
117
        public String getStr() {
118
                return _strCrs;
119
        }
120
121
        public void changeStrCrs(String code) {
122
                _strCrs += code;
123
        }
124
125
        protected int getErrNo(){
126
                return getErrno();
127
        }
128
129 8656 dguerrero
        protected static String strErrNo(int errno){
130 8405 dguerrero
                return strErrno(errno);
131
        }
132 8656 dguerrero
133
        //OPERATIONS
134
135
        public static int operate(double[] firstCoord,
136
                     double[] secondCoord,
137
                     double[] thirdCoord,
138
                     CrsProj srcCrs,
139
                     CrsProj destCrs)
140 12527 dguerrero
                         throws OperationCrsException{
141 8656 dguerrero
142 33682 fdiaz
            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 8656 dguerrero
149 32198 nbrodin
                // 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 23536 dguerrero
                //if(error!=0 && error !=-38) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
153 33682 fdiaz
                if(error!=0 && error !=-38) {
154
                    throw new OperationCrsException(srcCrs,destCrs, "");
155
                }
156 8656 dguerrero
                return error;
157
        }
158
159
        public static void operateSimple(double firstCoord,
160
                                 double secondCoord,
161
                                 double thirdCoord,
162
                                 CrsProj srcCrs,
163 12527 dguerrero
                                 CrsProj destCrs) throws OperationCrsException{
164 33682 fdiaz
        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 32198 nbrodin
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
171
                //TODO: Revisarlo en el c�digo jni.
172 23536 dguerrero
                //if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
173 23710 dguerrero
                if(error!=1) throw new OperationCrsException(srcCrs,destCrs, "");
174 8656 dguerrero
        }
175
176
        public static void operateArraySimple(double[] Coord,
177
                                          CrsProj srcCrs,
178 12527 dguerrero
                                          CrsProj destCrs)throws OperationCrsException{
179 33682 fdiaz
        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 32198 nbrodin
                // **** Provisional: strErrNo tira la m�quina virtual en Windows. *****
186
                //TODO: Revisarlo en el c�digo jni.
187 23536 dguerrero
                //if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
188 23710 dguerrero
                if(error!=1) throw new OperationCrsException(srcCrs,destCrs, "");
189 8656 dguerrero
        }
190
191
        public static int compareDatums(CrsProj crs1, CrsProj crs2){
192
                int compare = 0;
193 33682 fdiaz
        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 12527 dguerrero
                compare = compareDatums(crs1.getPtr(),crs2.getPtr());
199 8656 dguerrero
                return compare;
200
        }
201 8405 dguerrero
}