root / org.gvsig.jcrs / tags / 2059 / libJCRS / src / org / gvsig / crs / CrsFactory.java @ 72
History | View | Annotate | Download (6.28 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.NoAuthRepository; |
55 |
import org.gvsig.crs.repository.NoAuthRepositoryGT; |
56 |
import org.gvsig.crs.repository.UsrRepository; |
57 |
import org.gvsig.crs.repository.UsrRepositoryGT; |
58 |
|
59 |
/**
|
60 |
* Clase que consigue el CRS a trav?s del c?digo de la EPSG o de
|
61 |
* la cadena WKT
|
62 |
*
|
63 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
64 |
*
|
65 |
*/
|
66 |
|
67 |
public class CrsFactory implements ICRSFactory { |
68 |
static TreeMap data = new TreeMap(); |
69 |
|
70 |
public CrsFactory() {
|
71 |
} |
72 |
/**
|
73 |
* Obtiene un CRS a partir de su c?digo (p.e. EPSG:23030).
|
74 |
* @param code
|
75 |
* @return
|
76 |
* @throws CrsException
|
77 |
*/
|
78 |
public ICrs getCRS(String code) throws CrsException { |
79 |
|
80 |
/*if (data.containsKey(code))
|
81 |
return (ICrs) data.get(code);*/
|
82 |
|
83 |
String repoId = ""; |
84 |
String crsCode = ""; |
85 |
ICrs crs = null;
|
86 |
|
87 |
if(code.indexOf(":", code.indexOf(":")+1)<0){ |
88 |
repoId = code.substring(0, code.indexOf(":")); |
89 |
crsCode = code.substring(code.indexOf(":")+1); |
90 |
|
91 |
ICrsRepository repo = null;
|
92 |
|
93 |
if(repoId.equals("EPSG")){ |
94 |
repo = new EpsgRepositoryGT();
|
95 |
crs = repo.getCrs(crsCode); |
96 |
if (crs==null) { |
97 |
repo = new EpsgRepository();
|
98 |
crs = repo.getCrs(crsCode); |
99 |
} |
100 |
}else if (repoId.equals("IAU2000")){ |
101 |
repo = new Iau2000RepositoryGT();
|
102 |
crs = repo.getCrs(crsCode); |
103 |
if (crs==null) { |
104 |
repo = new Iau2000Repository();
|
105 |
crs = repo.getCrs(crsCode); |
106 |
} |
107 |
}else if (repoId.equals("CRS")){ |
108 |
repo = new NoAuthRepositoryGT();
|
109 |
crs = repo.getCrs(crsCode); |
110 |
if (crs==null) { |
111 |
repo = new NoAuthRepository();
|
112 |
crs = repo.getCrs(crsCode); |
113 |
} |
114 |
}else if (repoId.equals("ESRI")){ |
115 |
repo = new EsriRepositoryGT();
|
116 |
crs = repo.getCrs(crsCode); |
117 |
if (crs==null) { |
118 |
repo = new EsriRepository();
|
119 |
crs = repo.getCrs(crsCode); |
120 |
} |
121 |
}else if (repoId.equals("USR")){ |
122 |
repo = new UsrRepositoryGT();
|
123 |
crs = repo.getCrs(crsCode); |
124 |
if (crs==null) { |
125 |
repo = new UsrRepository();
|
126 |
crs = repo.getCrs(crsCode); |
127 |
} |
128 |
} |
129 |
} |
130 |
else{
|
131 |
String sourceParams = null; |
132 |
String targetParams = null; |
133 |
|
134 |
crsCode = code.substring(0,code.indexOf(":",code.indexOf(":")+1)); |
135 |
if (code.indexOf("@")==-1){ |
136 |
crsCode=crsCode.substring(0, crsCode.indexOf(",")); |
137 |
}else{
|
138 |
sourceParams = code.substring(code.indexOf("@")+1,code.lastIndexOf("@")); |
139 |
targetParams = code.substring(code.lastIndexOf("@")+1); |
140 |
|
141 |
if (sourceParams.equals("")) |
142 |
sourceParams = null;
|
143 |
else if (targetParams.equals("1")){ // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas. |
144 |
targetParams = sourceParams; |
145 |
sourceParams = "";
|
146 |
} |
147 |
if (targetParams.equals("")||targetParams.equals("0")) // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas. |
148 |
targetParams = null;
|
149 |
} |
150 |
crs = getCRS(crsCode); |
151 |
crs.setTransformationParams(sourceParams,targetParams); |
152 |
} |
153 |
|
154 |
/*code = crs.getAbrev();
|
155 |
|
156 |
data.put(code, crs);*/
|
157 |
|
158 |
return crs;
|
159 |
|
160 |
/*if (data.containsKey(code))
|
161 |
return (Crs) data.get(code);
|
162 |
|
163 |
Crs crs = new Crs(code);
|
164 |
|
165 |
// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
166 |
// mejor hecho.
|
167 |
code = crs.getAbrev();
|
168 |
|
169 |
data.put(code, crs);
|
170 |
|
171 |
return crs;*/
|
172 |
} |
173 |
|
174 |
/**
|
175 |
*
|
176 |
* @param epsg_code
|
177 |
* @param code
|
178 |
* @return
|
179 |
* @throws CrsException
|
180 |
*/
|
181 |
public ICrs getCRS(int epsg_code, String code) throws CrsException { |
182 |
/*if (data.containsKey(code))
|
183 |
return (Crs) data.get(code);*/
|
184 |
|
185 |
Crs crs = new Crs(epsg_code, code);
|
186 |
|
187 |
// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
188 |
// mejor hecho.
|
189 |
/*code = crs.getAbrev();
|
190 |
|
191 |
data.put(code, crs);*/
|
192 |
|
193 |
return crs;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
*
|
198 |
* @param epsg_code
|
199 |
* @param code
|
200 |
* @param params
|
201 |
* @return
|
202 |
* @throws CrsException
|
203 |
*/
|
204 |
public ICrs getCRS(int epsg_code, String code, String params) throws CrsException { |
205 |
/*if (data.containsKey(code))
|
206 |
return (Crs) data.get(code);*/
|
207 |
|
208 |
Crs crs = new Crs(epsg_code, code,params);
|
209 |
|
210 |
// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
211 |
// mejor hecho.
|
212 |
/*code = crs.getAbrev();
|
213 |
|
214 |
data.put(code, crs);*/
|
215 |
|
216 |
return crs;
|
217 |
} |
218 |
|
219 |
/**
|
220 |
*
|
221 |
*/
|
222 |
public IProjection get(String name) { |
223 |
// TODO Auto-generated method stub
|
224 |
try {
|
225 |
return getCRS(name);
|
226 |
} catch (CrsException e) {
|
227 |
// TODO Auto-generated catch block
|
228 |
e.printStackTrace(); |
229 |
} |
230 |
return null; |
231 |
} |
232 |
|
233 |
/**
|
234 |
*
|
235 |
*/
|
236 |
public boolean doesRigurousTransformations() { |
237 |
return true; |
238 |
} |
239 |
} |