Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libJCRS / src / org / gvsig / crs / CrsFactory.java @ 29000

History | View | Annotate | Download (5.63 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;
42

    
43
import java.util.TreeMap;
44

    
45
import org.cresques.cts.ICRSFactory;
46
import org.cresques.cts.IProjection;
47
import org.gvsig.crs.repository.EpsgRepository;
48
import org.gvsig.crs.repository.EpsgRepositoryGT;
49
import org.gvsig.crs.repository.EsriRepository;
50
import org.gvsig.crs.repository.EsriRepositoryGT;
51
import org.gvsig.crs.repository.ICrsRepository;
52
import org.gvsig.crs.repository.Iau2000Repository;
53
import org.gvsig.crs.repository.Iau2000RepositoryGT;
54
import org.gvsig.crs.repository.UsrRepository;
55
import org.gvsig.crs.repository.UsrRepositoryGT;
56

    
57
/**
58
 * Clase que consigue el CRS a trav?s del c?digo de la EPSG o de
59
 * la cadena WKT
60
 * 
61
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) 
62
 *
63
 */
64

    
65
public class CrsFactory implements ICRSFactory {
66
        static TreeMap data = new TreeMap();
67
        
68
        public CrsFactory() {        
69
        }
70
        /**
71
         * Obtiene un CRS a partir de su c?digo (p.e. EPSG:23030).
72
         * @param code
73
         * @return
74
         * @throws CrsException
75
         */
76
        public ICrs getCRS(String code) throws CrsException {
77
                
78
                /*if (data.containsKey(code))
79
                        return (ICrs) data.get(code);*/
80

    
81
                String repoId = "";
82
                String crsCode = "";
83
                ICrs crs = null;
84
                
85
                if(code.indexOf(":", code.indexOf(":")+1)<0){
86
                        repoId = code.substring(0, code.indexOf(":"));
87
                        crsCode = code.substring(code.indexOf(":")+1);
88
                
89
                        ICrsRepository repo = null;
90
                        
91
                        if(repoId.equals("EPSG")){
92
                                repo = new EpsgRepositoryGT();                                
93
                                crs = repo.getCrs(crsCode);
94
                                if (crs==null) {
95
                                        repo = new EpsgRepository();
96
                                        crs = repo.getCrs(crsCode);
97
                                }
98
                        }else if (repoId.equals("IAU2000")){
99
                                repo = new Iau2000RepositoryGT();                                
100
                                crs = repo.getCrs(crsCode);
101
                                if (crs==null) {
102
                                        repo = new Iau2000Repository();
103
                                        crs = repo.getCrs(crsCode);
104
                                }
105
                        }else if (repoId.equals("ESRI")){
106
                                repo = new EsriRepositoryGT();                                
107
                                crs = repo.getCrs(crsCode);
108
                                if (crs==null) {
109
                                        repo = new EsriRepository();
110
                                        crs = repo.getCrs(crsCode);
111
                                }
112
                        }else if (repoId.equals("USR")){
113
                                repo = new UsrRepositoryGT();                                
114
                                crs = repo.getCrs(crsCode);
115
                                if (crs==null) {
116
                                        repo = new UsrRepository();
117
                                        crs = repo.getCrs(crsCode);
118
                                }
119
                        }                
120
                }
121
                else{
122
                        String sourceParams = null;
123
                        String targetParams = null;
124
                        
125
                        crsCode = code.substring(0,code.indexOf(":",code.indexOf(":")+1));
126
                        sourceParams = code.substring(code.indexOf("@")+1,code.lastIndexOf("@"));
127
                        targetParams = code.substring(code.lastIndexOf("@")+1);
128
                        
129
                        if (sourceParams.equals(""))
130
                                sourceParams = null;
131
                        else if (targetParams.equals("1")){ // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas. 
132
                                targetParams = sourceParams;
133
                                sourceParams = "";
134
                        }
135
                        if (targetParams.equals("")||targetParams.equals("0")) // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas.
136
                                targetParams = null;
137
                        
138
                        crs = getCRS(crsCode);
139
                        crs.setTransformationParams(sourceParams,targetParams);
140
                }
141
                
142
                /*code = crs.getAbrev();
143
                
144
                data.put(code, crs);*/
145

    
146
                return crs;
147
                
148
                /*if (data.containsKey(code))
149
                        return (Crs) data.get(code);
150

151
                Crs crs = new Crs(code);
152
                
153
                // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
154
                // mejor hecho.
155
                code = crs.getAbrev();
156
                
157
                data.put(code, crs);
158

159
                return crs;*/
160
        }
161
        
162
        /**
163
         * 
164
         * @param epsg_code
165
         * @param code
166
         * @return
167
         * @throws CrsException
168
         */
169
        public ICrs getCRS(int epsg_code, String code) throws CrsException {
170
                /*if (data.containsKey(code))
171
                        return (Crs) data.get(code);*/
172

    
173
                Crs crs = new Crs(epsg_code, code);
174
                
175
                // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
176
                // mejor hecho.
177
                /*code = crs.getAbrev();
178
                
179
                data.put(code, crs);*/
180

    
181
                return crs;
182
        }
183
        
184
        /**
185
         * 
186
         * @param epsg_code
187
         * @param code
188
         * @param params
189
         * @return
190
         * @throws CrsException
191
         */
192
        public ICrs getCRS(int epsg_code, String code, String params) throws CrsException {
193
                /*if (data.containsKey(code))
194
                        return (Crs) data.get(code);*/
195
                
196
                Crs crs = new Crs(epsg_code, code,params);
197
                
198
                // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
199
                // mejor hecho.
200
                /*code = crs.getAbrev();
201
                
202
                data.put(code, crs);*/
203

    
204
                return crs;
205
        }
206
        
207
        /**
208
         * 
209
         */
210
        public IProjection get(String name) {
211
                // TODO Auto-generated method stub
212
                try {
213
                        return getCRS(name);
214
                } catch (CrsException e) {
215
                        // TODO Auto-generated catch block
216
                        e.printStackTrace();
217
                }
218
                return null;
219
        }
220
        
221
        /**
222
         * 
223
         */
224
        public boolean doesRigurousTransformations() {
225
                return true;
226
        }
227
}