Statistics
| Revision:

root / org.gvsig.jcrs / libJCRS / src / org / gvsig / crs / CrsFactory.java @ 38

History | View | Annotate | Download (5.89 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
                        if (code.indexOf("@")==-1){
127
                                crsCode=crsCode.substring(0, crsCode.indexOf(","));
128
                        }else{
129
                                sourceParams = code.substring(code.indexOf("@")+1,code.lastIndexOf("@"));
130
                                targetParams = code.substring(code.lastIndexOf("@")+1);
131

    
132
                                if (sourceParams.equals(""))
133
                                        sourceParams = null;
134
                                else if (targetParams.equals("1")){ // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas.
135
                                        targetParams = sourceParams;
136
                                        sourceParams = "";
137
                                }
138
                                if (targetParams.equals("")||targetParams.equals("0")) // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas.
139
                                        targetParams = null;
140
                        }
141
                        crs = getCRS(crsCode);
142
                        crs.setTransformationParams(sourceParams,targetParams);
143
                }
144

    
145
                /*code = crs.getAbrev();
146

147
                data.put(code, crs);*/
148

    
149
                return crs;
150

    
151
                /*if (data.containsKey(code))
152
                        return (Crs) data.get(code);
153

154
                Crs crs = new Crs(code);
155

156
                // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
157
                // mejor hecho.
158
                code = crs.getAbrev();
159

160
                data.put(code, crs);
161

162
                return crs;*/
163
        }
164

    
165
        /**
166
         *
167
         * @param epsg_code
168
         * @param code
169
         * @return
170
         * @throws CrsException
171
         */
172
        public ICrs getCRS(int epsg_code, String code) throws CrsException {
173
                /*if (data.containsKey(code))
174
                        return (Crs) data.get(code);*/
175

    
176
                Crs crs = new Crs(epsg_code, code);
177

    
178
                // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
179
                // mejor hecho.
180
                /*code = crs.getAbrev();
181

182
                data.put(code, crs);*/
183

    
184
                return crs;
185
        }
186

    
187
        /**
188
         *
189
         * @param epsg_code
190
         * @param code
191
         * @param params
192
         * @return
193
         * @throws CrsException
194
         */
195
        public ICrs getCRS(int epsg_code, String code, String params) throws CrsException {
196
                /*if (data.containsKey(code))
197
                        return (Crs) data.get(code);*/
198

    
199
                Crs crs = new Crs(epsg_code, code,params);
200

    
201
                // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
202
                // mejor hecho.
203
                /*code = crs.getAbrev();
204

205
                data.put(code, crs);*/
206

    
207
                return crs;
208
        }
209

    
210
        /**
211
         *
212
         */
213
        public IProjection get(String name) {
214
                // TODO Auto-generated method stub
215
                try {
216
                        return getCRS(name);
217
                } catch (CrsException e) {
218
                        // TODO Auto-generated catch block
219
                        e.printStackTrace();
220
                }
221
                return null;
222
        }
223

    
224
        /**
225
         *
226
         */
227
        public boolean doesRigurousTransformations() {
228
                return true;
229
        }
230
}