root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.jcrs.lib / src / main / java / org / gvsig / crs / CrsFactory.java @ 229
History | View | Annotate | Download (8.75 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 |
package org.gvsig.crs; |
41 |
|
42 |
import java.io.File; |
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 |
import org.gvsig.tools.dispose.Disposable; |
59 |
import org.slf4j.Logger; |
60 |
import org.slf4j.LoggerFactory; |
61 |
|
62 |
/**
|
63 |
* Clase que consigue el CRS a trav?s del c?digo de la EPSG o de
|
64 |
* la cadena WKT
|
65 |
*
|
66 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
67 |
*
|
68 |
*/
|
69 |
public class CrsFactory implements ICRSFactory { |
70 |
|
71 |
private static Logger logger = LoggerFactory.getLogger(CrsFactory.class); |
72 |
static TreeMap data = new TreeMap(); |
73 |
|
74 |
private static File databaseFolder = null; |
75 |
private static File projLibFolder = null; |
76 |
|
77 |
public CrsFactory() {
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Obtiene un CRS a partir de su c?digo (p.e. EPSG:23030).
|
82 |
*
|
83 |
* @param code
|
84 |
* @return
|
85 |
* @throws CrsException
|
86 |
*/
|
87 |
public ICrs getCRS(String code) throws CrsException { |
88 |
|
89 |
/*if (data.containsKey(code))
|
90 |
return (ICrs) data.get(code);*/
|
91 |
String repoId = ""; |
92 |
String crsCode = ""; |
93 |
ICrs crs = null;
|
94 |
ICrsRepository repo = null;
|
95 |
|
96 |
try {
|
97 |
if ( code.indexOf(":", code.indexOf(":") + 1) < 0 ) { |
98 |
repoId = code.substring(0, code.indexOf(":")); |
99 |
crsCode = code.substring(code.indexOf(":") + 1); |
100 |
|
101 |
if ( repoId.equals("EPSG") ) { |
102 |
repo = new EpsgRepositoryGT();
|
103 |
crs = repo.getCrs(crsCode); |
104 |
if ( crs == null ) { |
105 |
repo = new EpsgRepository();
|
106 |
crs = repo.getCrs(crsCode); |
107 |
} |
108 |
} else if ( repoId.equals("IAU2000") ) { |
109 |
repo = new Iau2000RepositoryGT();
|
110 |
crs = repo.getCrs(crsCode); |
111 |
if ( crs == null ) { |
112 |
repo = new Iau2000Repository();
|
113 |
crs = repo.getCrs(crsCode); |
114 |
} |
115 |
} else if ( repoId.equals("CRS") ) { |
116 |
repo = new NoAuthRepositoryGT();
|
117 |
crs = repo.getCrs(crsCode); |
118 |
if ( crs == null ) { |
119 |
repo = new NoAuthRepository();
|
120 |
crs = repo.getCrs(crsCode); |
121 |
} |
122 |
} else if ( repoId.equals("ESRI") ) { |
123 |
repo = new EsriRepositoryGT();
|
124 |
crs = repo.getCrs(crsCode); |
125 |
if ( crs == null ) { |
126 |
repo = new EsriRepository();
|
127 |
crs = repo.getCrs(crsCode); |
128 |
} |
129 |
} else if ( repoId.equals("USR") ) { |
130 |
repo = new UsrRepositoryGT();
|
131 |
crs = repo.getCrs(crsCode); |
132 |
if ( crs == null ) { |
133 |
repo = new UsrRepository();
|
134 |
crs = repo.getCrs(crsCode); |
135 |
} |
136 |
} |
137 |
} else {
|
138 |
String sourceParams = null; |
139 |
String targetParams = null; |
140 |
|
141 |
crsCode = code.substring(0, code.indexOf(":", code.indexOf(":") + 1)); |
142 |
if ( code.indexOf("@") == -1 ) { |
143 |
crsCode = crsCode.substring(0, crsCode.indexOf(",")); |
144 |
} else {
|
145 |
sourceParams = code.substring(code.indexOf("@") + 1, code.lastIndexOf("@")); |
146 |
targetParams = code.substring(code.lastIndexOf("@") + 1); |
147 |
|
148 |
if ( sourceParams.equals("") ) { |
149 |
sourceParams = null;
|
150 |
} else if ( targetParams.equals("1") ) { // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas. |
151 |
targetParams = sourceParams; |
152 |
sourceParams = "";
|
153 |
} |
154 |
if ( targetParams.equals("") || targetParams.equals("0") ) // Compativilidad con versiones de libJCrs sin soporte para transf. compuestas. |
155 |
{ |
156 |
targetParams = null;
|
157 |
} |
158 |
} |
159 |
crs = getCRS(crsCode); |
160 |
if ( crs != null ) { |
161 |
crs.setTransformationParams(sourceParams, targetParams); |
162 |
} |
163 |
|
164 |
} |
165 |
|
166 |
/*code = crs.getAbrev();
|
167 |
|
168 |
data.put(code, crs);*/
|
169 |
if ( crs == null ) { |
170 |
logger.debug("Can't find CRS '" + code + "' in available repositories."); |
171 |
} else {
|
172 |
logger.debug("Found CRS '" + code + "' in repository '" + |
173 |
(repo == null ? "unknow" : (repo.getClass().getSimpleName())) + "'."); |
174 |
} |
175 |
return crs;
|
176 |
} finally {
|
177 |
if( repo instanceof Disposable ) { |
178 |
((Disposable)repo).dispose(); |
179 |
} |
180 |
} |
181 |
/*if (data.containsKey(code))
|
182 |
return (Crs) data.get(code);
|
183 |
|
184 |
Crs crs = new Crs(code);
|
185 |
|
186 |
// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
187 |
// mejor hecho.
|
188 |
code = crs.getAbrev();
|
189 |
|
190 |
data.put(code, crs);
|
191 |
|
192 |
return crs;*/
|
193 |
} |
194 |
|
195 |
/**
|
196 |
*
|
197 |
* @param epsg_code
|
198 |
* @param code
|
199 |
* @return
|
200 |
* @throws CrsException
|
201 |
*/
|
202 |
public ICrs getCRS(int epsg_code, String code) throws CrsException { |
203 |
/*if (data.containsKey(code))
|
204 |
return (Crs) data.get(code);*/
|
205 |
|
206 |
Crs crs = new Crs(epsg_code, code);
|
207 |
|
208 |
// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
209 |
// mejor hecho.
|
210 |
/*code = crs.getAbrev();
|
211 |
|
212 |
data.put(code, crs);*/
|
213 |
return crs;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
*
|
218 |
* @param epsg_code
|
219 |
* @param code
|
220 |
* @param params
|
221 |
* @return
|
222 |
* @throws CrsException
|
223 |
*/
|
224 |
public ICrs getCRS(int epsg_code, String code, String params) throws CrsException { |
225 |
/*if (data.containsKey(code))
|
226 |
return (Crs) data.get(code);*/
|
227 |
|
228 |
Crs crs = new Crs(epsg_code, code, params);
|
229 |
|
230 |
// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
231 |
// mejor hecho.
|
232 |
/*code = crs.getAbrev();
|
233 |
|
234 |
data.put(code, crs);*/
|
235 |
return crs;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
*
|
240 |
*/
|
241 |
public IProjection get(String name) { |
242 |
try {
|
243 |
return getCRS(name);
|
244 |
} catch (CrsException e) {
|
245 |
logger.error("Can't cget CRS name '" + name + "'.", e); |
246 |
} |
247 |
return null; |
248 |
} |
249 |
|
250 |
/**
|
251 |
*
|
252 |
*/
|
253 |
public boolean doesRigurousTransformations() { |
254 |
return true; |
255 |
} |
256 |
|
257 |
public static File getDataBaseFolder() { |
258 |
return databaseFolder;
|
259 |
} |
260 |
|
261 |
public static void setDataBaseFolder(File folder) { |
262 |
databaseFolder = folder; |
263 |
} |
264 |
|
265 |
public static File getProjLibFolder() { |
266 |
return projLibFolder;
|
267 |
} |
268 |
|
269 |
public static void setProjLibFolder(File folder) { |
270 |
projLibFolder = folder; |
271 |
} |
272 |
} |