Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libJCRS / src / org / gvsig / crs / ogr / TransEPSG.java @ 21878

History | View | Annotate | Download (5.61 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.ogr;
42

    
43
import java.sql.ResultSet;
44
import java.sql.SQLException;
45

    
46

    
47
import es.idr.teledeteccion.connection.EpsgConnection;
48
import es.idr.teledeteccion.connection.Query;
49

    
50

    
51
/**
52
 * Clase para conseguir la informaci?n de la transformaci?n elegida
53
 * de la EPSG
54
 * 
55
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
56
 *
57
 */
58

    
59
public class TransEPSG {
60
        int parameter_code = 0;
61
        int coord_op_method_code = 0;
62
        boolean inverseTransformation = false;
63
        
64
        public EpsgConnection connect;
65
        
66
        double[] param_value_double = {0,0,0,0,0,0,0};
67
        String[] param_value = {"0","0","0","0","0","0","0"};
68
        String[] param_name = {"0","0","0","0","0","0","0"};
69

    
70
        /**
71
         * Acepta el c?digo de la transformaci?n a utilizar, y se
72
         * recupera la informaci?n necesaria para la generaci?n del CRS
73
         * @param coord_op_code
74
         * @param conn
75
         * @param invTr
76
         */
77
        public TransEPSG(int coord_op_code, EpsgConnection conn, boolean invTr){
78
                inverseTransformation = invTr;
79
                ResultSet result;
80
                connect = conn;
81
                int uom_code = 0;                                
82
                String sentence = "SELECT coord_op_method_code, parameter_code, parameter_value, uom_code " +
83
                                "FROM epsg_coordoperationparamvalue " +
84
                                "WHERE coord_op_code = " + coord_op_code;
85
                result = Query.select(sentence,connect.getConnection());
86
                int i = 0;
87
                try {
88
                        while (result.next()){
89
                                coord_op_method_code = result.getInt("coord_op_method_code");
90
                                parameter_code = result.getInt("parameter_code");
91
                                
92
                                double param_val = result.getDouble("parameter_value");                                
93
                                                                
94
                                sentence = "SELECT parameter_name " +
95
                                                        "FROM epsg_coordoperationparam " +
96
                                                        "WHERE parameter_code = " + parameter_code;
97
                                ResultSet result2 = Query.select(sentence,connect.getConnection());
98
                
99
                                result2.next();
100
                                param_name[i] = result2.getString("parameter_name");
101
                                uom_code = result.getInt("uom_code");
102
                                if (uom_code != 0){
103
                                        sentence = "SELECT factor_b, factor_c, unit_of_meas_type " +
104
                                          "FROM epsg_unitofmeasure " +                                      
105
                                          "WHERE uom_code = " + uom_code;
106
                                        ResultSet result3 = Query.select(sentence,connect.getConnection());
107
                                        
108
                                        double factor_b = 0;
109
                                        double factor_c = 0;                                
110
                                        result3.next();
111
                                        String type = result3.getString("unit_of_meas_type");
112
                                        factor_b = result3.getDouble("factor_b");
113
                                        factor_c = result3.getDouble("factor_c");                                
114
                                        
115
                                        if (uom_code == 9202){}
116
                                        else {
117
                                                if (factor_b != 0 && factor_c != 0 && !type.equals("angle")){                                                
118
                                                        param_val = (param_val * factor_b) / factor_c;
119
                                                        if (type.equals("scale")) 
120
                                                                param_val = (param_val -1) * 1000000;                                                
121
                                                }
122
                                                else if(factor_b != 0 && factor_c != 0 && type.equals("angle")){
123
                                                        param_val = ((param_val * factor_b) / factor_c) * (180.0 / Math.PI);
124
                                                        param_val = param_val * 3600;
125
                                                }else if (uom_code == 9110){
126
                                                        param_val = especialDegree(param_val);
127
                                                        param_val = Math.toDegrees(param_val);
128
                                                        param_val = param_val * 3600;
129
                                                }else {
130
                                                        System.out.println("C?digo de medida no v?lido...");                                        
131
                                                }
132
                                        }
133
                                        param_value_double[i] = param_val;
134
                                        i++;
135
                                }
136
                        }
137
                        
138
                        if (inverseTransformation) {
139
                                for (int j = 0; j < param_value_double.length; j++){
140
                                        param_value_double[j] = param_value_double[j] * -1.0;
141
                                }
142
                        }
143
                        
144
                } catch (SQLException e) {
145
                        e.printStackTrace();
146
                }
147
                for (int k = 0; k < param_value_double.length; k++){
148
                        param_value[k] = ""+ String.valueOf(param_value_double[k]);
149
                }
150
        }
151
        
152
        /**
153
         * M?todo para pasar a las unidades correctas el valor de los distintos
154
         * par?metros de la proyecci?n.
155
         * @param val
156
         * @return
157
         */
158
        private double especialDegree(double val){
159
                int signo = 1;
160
                double grad, min;
161
                double sec;
162
                
163
                if (val < 0){
164
                        signo = -1;
165
                        val = Math.abs(val);
166
                }                
167
                
168
                grad = Math.floor(val);
169
                val=(val-grad)*100.0;
170
                min=Math.floor(val);
171
                sec=(val-min)*100.0;
172
                
173
                val = ((grad + (min/60.0) + (sec/3600.0)) * (Math.PI/180.0)) * signo;
174
                
175
                return val;
176
        }
177
        
178
        private float round(double f,int i)
179
        {
180
                double d=Math.pow(10.0,(double) i);
181
                double aux=f*d;
182
                int auxi=(int) aux;
183
                float df=auxi/((float) d);
184
                return df;
185
        }
186
        
187
        public String[] getParamName(){
188
                return param_name;
189
        }
190
        
191
        public String[] getParamValue(){
192
                return param_value;
193
        }
194

    
195
}