Statistics
| Revision:

root / trunk / libraries / libJCRS / src / org / gvsig / crs / proj / JNIBaseCrs.java @ 12527

History | View | Annotate | Download (4.34 KB)

1
/* 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
 * 
45
 * @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
        
60
        
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
        static {
78
                System.loadLibrary("crsjniproj");
79
        }
80
        
81
        protected void createCrs(String strCrs) throws CrsProjException {
82
                cPtr=loadCrs(strCrs);
83
                
84
                int errNo = getErrNo(); 
85
                if (errNo<0 && errNo!=-10) throw new CrsProjException("Error creating CRS: "+strErrNo(errNo));
86
                _strCrs=strCrs;
87
        }
88
        
89
        protected void deleteCrs() {
90
                //if(cPtr>0) freeCrs(cPtr); 
91
                freeCrs(cPtr);
92
        }
93
        
94
        public boolean isLatlong() {
95
                latLong = isLatlong(cPtr);
96
                if(latLong == 0)
97
                        return false;
98
                return true;
99
        }
100
        
101
        protected long getPtr(){
102
                /*if (cPtr>0)        return cPtr;
103
                else throw new CrsProjException(_strCrs);*/
104
                return cPtr;
105
        }
106
        
107
        public String getStr() {
108
                return _strCrs;
109
        }
110
        
111
        public void changeStrCrs(String code) {
112
                _strCrs += code;
113
        }
114
        
115
        protected int getErrNo(){
116
                return getErrno();
117
        }
118
        
119
        protected static String strErrNo(int errno){
120
                return strErrno(errno);
121
        }
122
        
123
        //OPERATIONS
124
        
125
        public static int operate(double[] firstCoord,
126
                     double[] secondCoord,
127
                     double[] thirdCoord,
128
                     CrsProj srcCrs,
129
                     CrsProj destCrs)
130
                         throws OperationCrsException {
131
                
132
                int error=operation(firstCoord,secondCoord,thirdCoord,srcCrs.getPtr(),destCrs.getPtr());
133
                
134
                // error -38: el punto transformar est? fuera del ?mbito del nadgrid
135
                if(error!=0 && error !=-38) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
136
                return error;
137
        }
138

    
139
        public static void operateSimple(double firstCoord,
140
                                 double secondCoord,
141
                                 double thirdCoord,
142
                                 CrsProj srcCrs,
143
                                 CrsProj destCrs) throws OperationCrsException, CrsProjException {
144

    
145
                int error = operationSimple(firstCoord, secondCoord, thirdCoord,srcCrs.getPtr(),destCrs.getPtr());
146
                if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
147
        }
148

    
149
        public static void operateArraySimple(double[] Coord,
150
                                          CrsProj srcCrs,
151
                                          CrsProj destCrs)throws OperationCrsException,
152
                                               CrsProjException {
153

    
154
                int error = operationArraySimple(Coord,srcCrs.getPtr(),destCrs.getPtr());
155
                if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
156
        }
157
        
158
        public static int compareDatums(CrsProj crs1, CrsProj crs2){
159
                int compare = 0;
160
                compare = compareDatums(crs1.getPtr(),crs2.getPtr());        
161
                return compare;
162
        }
163
}