Statistics
| Revision:

root / branches / F2 / libraries / libJCRS / src / org / gvsig / crs / ogr / GetTransepsg.java @ 11027

History | View | Annotate | Download (5.39 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
import org.gvsig.crs.EpsgConnection;
47
import org.gvsig.crs.Query;
48

    
49

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

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

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

    
194
}