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 | 8878 | jlgomez | /* 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 | 6813 | mgarcia | package org.gvsig.crs; |
42 | |||
43 | import java.util.TreeMap; |
||
44 | |||
45 | 7704 | luisw | import org.cresques.cts.ICRSFactory; |
46 | import org.cresques.cts.IProjection; |
||
47 | 8433 | dguerrero | import org.gvsig.crs.repository.EpsgRepository; |
48 | 11331 | jlgomez | import org.gvsig.crs.repository.EpsgRepositoryGT; |
49 | 9204 | jlgomez | import org.gvsig.crs.repository.EsriRepository; |
50 | 11460 | jlgomez | import org.gvsig.crs.repository.EsriRepositoryGT; |
51 | 8486 | dguerrero | import org.gvsig.crs.repository.ICrsRepository; |
52 | import org.gvsig.crs.repository.Iau2000Repository; |
||
53 | 11460 | jlgomez | import org.gvsig.crs.repository.Iau2000RepositoryGT; |
54 | 12359 | jlgomez | import org.gvsig.crs.repository.UsrRepository; |
55 | 11541 | jlgomez | import org.gvsig.crs.repository.UsrRepositoryGT; |
56 | 7624 | dguerrero | |
57 | 8878 | jlgomez | /**
|
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 | 7704 | luisw | public class CrsFactory implements ICRSFactory { |
66 | 6813 | mgarcia | static TreeMap data = new TreeMap(); |
67 | 7624 | dguerrero | |
68 | 6813 | mgarcia | 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 | 8433 | dguerrero | |
78 | 11639 | dguerrero | /*if (data.containsKey(code))
|
79 | return (ICrs) data.get(code);*/
|
||
80 | 6813 | mgarcia | |
81 | 12301 | dguerrero | String repoId = ""; |
82 | String crsCode = ""; |
||
83 | 11460 | jlgomez | ICrs crs = null;
|
84 | 8486 | dguerrero | |
85 | 12301 | dguerrero | if(code.indexOf(":", code.indexOf(":")+1)<0){ |
86 | repoId = code.substring(0, code.indexOf(":")); |
||
87 | crsCode = code.substring(code.indexOf(":")+1); |
||
88 | 8486 | dguerrero | |
89 | 12301 | dguerrero | 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 | 12359 | jlgomez | crs = repo.getCrs(crsCode); |
115 | if (crs==null) { |
||
116 | repo = new UsrRepository();
|
||
117 | crs = repo.getCrs(crsCode); |
||
118 | } |
||
119 | 12301 | dguerrero | } |
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 | 12406 | dguerrero | 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 | 12301 | dguerrero | targetParams = null;
|
137 | |||
138 | crs = getCRS(crsCode); |
||
139 | crs.setTransformationParams(sourceParams,targetParams); |
||
140 | } |
||
141 | |||
142 | 11639 | dguerrero | /*code = crs.getAbrev();
|
143 | 8486 | dguerrero | |
144 | 11639 | dguerrero | data.put(code, crs);*/
|
145 | 8486 | dguerrero | |
146 | return crs;
|
||
147 | |||
148 | /*if (data.containsKey(code))
|
||
149 | return (Crs) data.get(code);
|
||
150 | |||
151 | 6813 | mgarcia | 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 | 8486 | dguerrero | return crs;*/
|
160 | 6813 | mgarcia | } |
161 | 6820 | jlgomez | |
162 | 9204 | jlgomez | /**
|
163 | *
|
||
164 | * @param epsg_code
|
||
165 | * @param code
|
||
166 | * @return
|
||
167 | * @throws CrsException
|
||
168 | */
|
||
169 | 6820 | jlgomez | public ICrs getCRS(int epsg_code, String code) throws CrsException { |
170 | 11639 | dguerrero | /*if (data.containsKey(code))
|
171 | return (Crs) data.get(code);*/
|
||
172 | 6820 | jlgomez | |
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 | 11639 | dguerrero | /*code = crs.getAbrev();
|
178 | 6820 | jlgomez | |
179 | 11639 | dguerrero | data.put(code, crs);*/
|
180 | 6820 | jlgomez | |
181 | 11639 | dguerrero | return crs;
|
182 | 6820 | jlgomez | } |
183 | 6927 | mgarcia | |
184 | 9204 | jlgomez | /**
|
185 | *
|
||
186 | * @param epsg_code
|
||
187 | * @param code
|
||
188 | * @param params
|
||
189 | * @return
|
||
190 | * @throws CrsException
|
||
191 | */
|
||
192 | 6927 | mgarcia | public ICrs getCRS(int epsg_code, String code, String params) throws CrsException { |
193 | 11639 | dguerrero | /*if (data.containsKey(code))
|
194 | return (Crs) data.get(code);*/
|
||
195 | 7821 | jlgomez | |
196 | 6927 | mgarcia | 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 | 11639 | dguerrero | /*code = crs.getAbrev();
|
201 | 6927 | mgarcia | |
202 | 11639 | dguerrero | data.put(code, crs);*/
|
203 | 6927 | mgarcia | |
204 | return crs;
|
||
205 | } |
||
206 | 7876 | jlgomez | |
207 | 9204 | jlgomez | /**
|
208 | *
|
||
209 | */
|
||
210 | 7704 | luisw | 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 | 9204 | jlgomez | |
221 | /**
|
||
222 | *
|
||
223 | */
|
||
224 | 9016 | luisw | public boolean doesRigurousTransformations() { |
225 | return true; |
||
226 | } |
||
227 | 6813 | mgarcia | } |