Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / proj / JNIBaseCrs.java @ 8656

History | View | Annotate | Download (3.11 KB)

1
package org.gvsig.crs.proj;
2

    
3

    
4
public class JNIBaseCrs
5
{
6
        protected long cPtr;
7
        protected int latLong;
8
        protected String _strCrs;
9
        protected native long loadCrs(String crs);
10
        protected native void freeCrs(long crs);
11
        protected native int isLatlong(long crs);
12
        protected static native int compareDatums(long datum1, long datum2);
13
        protected native int getErrno();
14
        protected static native String strErrno(int errno);
15
        
16
        
17
        protected static native int operation(double[] firstCoord,
18
                    double[] secondCoord,
19
                    double[] values,
20
                    long srcCodeString,
21
                    long destCodeString);
22

    
23
        protected static native int operationSimple(double firstcoord,
24
                        double secondcoord,
25
                        double values,
26
                        long srcCodeString,
27
                        long destCodeString);
28

    
29
        protected static native int operationArraySimple(double[] Coord,
30
                         long srcCodeString,
31
                         long destCodeString);
32
        
33
        static {
34
                System.loadLibrary("crsjniproj");
35
        }
36
        
37
        protected void createCrs(String strCrs) throws CrsProjException {
38
                cPtr=loadCrs(strCrs);
39
                
40
                int errNo = getErrNo(); 
41
                if (errNo<0 && errNo!=-10) throw new CrsProjException("Error creating CRS: "+strErrNo(errNo));
42
                _strCrs=strCrs;
43
        }
44
        
45
        protected void deleteCrs() {
46
                if(cPtr>0) freeCrs(cPtr); 
47
        }
48
        
49
        public boolean isLatlong() {
50
                latLong = isLatlong(cPtr);
51
                if(latLong == 0)
52
                        return false;
53
                return true;
54
        }
55
        
56
        protected long getPtr() throws CrsProjException {
57
                if (cPtr>0)        return cPtr;
58
                else throw new CrsProjException(_strCrs);
59
        }
60
        
61
        public String getStr() {
62
                return _strCrs;
63
        }
64
        
65
        public void changeStrCrs(String code) {
66
                _strCrs += code;
67
        }
68
        
69
        protected int getErrNo(){
70
                return getErrno();
71
        }
72
        
73
        protected static String strErrNo(int errno){
74
                return strErrno(errno);
75
        }
76
        
77
        //OPERATIONS
78
        
79
        public static int operate(double[] firstCoord,
80
                     double[] secondCoord,
81
                     double[] thirdCoord,
82
                     CrsProj srcCrs,
83
                     CrsProj destCrs)
84
                         throws OperationCrsException,
85
                                        CrsProjException {
86
                
87
                int error=operation(firstCoord,secondCoord,thirdCoord,srcCrs.getPtr(),destCrs.getPtr());
88
                
89
                // error -38: el punto transformar est? fuera del ?mbito del nadgrid
90
                if(error!=0 && error !=-38) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
91
                return error;
92
        }
93

    
94
        public static void operateSimple(double firstCoord,
95
                                 double secondCoord,
96
                                 double thirdCoord,
97
                                 CrsProj srcCrs,
98
                                 CrsProj destCrs) throws OperationCrsException, CrsProjException {
99

    
100
                int error = operationSimple(firstCoord, secondCoord, thirdCoord,srcCrs.getPtr(),destCrs.getPtr());
101
                if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
102
        }
103

    
104
        public static void operateArraySimple(double[] Coord,
105
                                          CrsProj srcCrs,
106
                                          CrsProj destCrs)throws OperationCrsException,
107
                                               CrsProjException {
108

    
109
                int error = operationArraySimple(Coord,srcCrs.getPtr(),destCrs.getPtr());
110
                if(error!=1) throw new OperationCrsException(srcCrs,destCrs, strErrNo(error));
111
        }
112
        
113
        public static int compareDatums(CrsProj crs1, CrsProj crs2){
114
                int compare = 0;
115
                try {
116
                        compare = compareDatums(crs1.getPtr(),crs2.getPtr());
117
                } catch (CrsProjException e) {
118
                        // TODO Auto-generated catch block
119
                        e.printStackTrace();
120
                }        
121
                return compare;
122
        }
123
}