root / branches / F2 / libraries / libJCRS / src / org / gvsig / crs / CrsFactory.java @ 11135
History | View | Annotate | Download (4.1 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 | 9204 | jlgomez | import org.gvsig.crs.repository.EsriRepository; |
49 | 8486 | dguerrero | import org.gvsig.crs.repository.ICrsRepository; |
50 | import org.gvsig.crs.repository.Iau2000Repository; |
||
51 | 7624 | dguerrero | |
52 | 8878 | jlgomez | /**
|
53 | * Clase que consigue el CRS a trav?s del c?digo de la EPSG o de
|
||
54 | * la cadena WKT
|
||
55 | *
|
||
56 | * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
||
57 | *
|
||
58 | */
|
||
59 | |||
60 | 7704 | luisw | public class CrsFactory implements ICRSFactory { |
61 | 6813 | mgarcia | static TreeMap data = new TreeMap(); |
62 | 7624 | dguerrero | |
63 | 6813 | mgarcia | public CrsFactory() {
|
64 | } |
||
65 | /**
|
||
66 | * Obtiene un CRS a partir de su c?digo (p.e. EPSG:23030).
|
||
67 | * @param code
|
||
68 | * @return
|
||
69 | * @throws CrsException
|
||
70 | */
|
||
71 | public ICrs getCRS(String code) throws CrsException { |
||
72 | 8433 | dguerrero | |
73 | 6813 | mgarcia | if (data.containsKey(code))
|
74 | return (Crs) data.get(code);
|
||
75 | |||
76 | 8486 | dguerrero | String repoId = code.substring(0, code.indexOf(":")); |
77 | String crsCode = code.substring(code.indexOf(":")+1); |
||
78 | |||
79 | ICrsRepository repo = null;
|
||
80 | Crs crs = null;
|
||
81 | |||
82 | if(repoId.equals("EPSG")){ |
||
83 | repo = new EpsgRepository();
|
||
84 | crs = (Crs)repo.getCrs(crsCode); |
||
85 | }else if (repoId.equals("IAU2000")){ |
||
86 | repo = new Iau2000Repository();
|
||
87 | crs = (Crs)repo.getCrs(crsCode); |
||
88 | 9204 | jlgomez | }else if (repoId.equals("ESRI")){ |
89 | repo = new EsriRepository();
|
||
90 | crs = (Crs)repo.getCrs(crsCode); |
||
91 | 8486 | dguerrero | } |
92 | |||
93 | // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
||
94 | // mejor hecho.
|
||
95 | code = crs.getAbrev(); |
||
96 | |||
97 | data.put(code, crs); |
||
98 | |||
99 | return crs;
|
||
100 | |||
101 | /*if (data.containsKey(code))
|
||
102 | return (Crs) data.get(code);
|
||
103 | |||
104 | 6813 | mgarcia | Crs crs = new Crs(code);
|
105 | |||
106 | // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
||
107 | // mejor hecho.
|
||
108 | code = crs.getAbrev();
|
||
109 | |||
110 | data.put(code, crs);
|
||
111 | |||
112 | 8486 | dguerrero | return crs;*/
|
113 | 6813 | mgarcia | } |
114 | 6820 | jlgomez | |
115 | 9204 | jlgomez | /**
|
116 | *
|
||
117 | * @param epsg_code
|
||
118 | * @param code
|
||
119 | * @return
|
||
120 | * @throws CrsException
|
||
121 | */
|
||
122 | 6820 | jlgomez | public ICrs getCRS(int epsg_code, String code) throws CrsException { |
123 | if (data.containsKey(code))
|
||
124 | return (Crs) data.get(code);
|
||
125 | |||
126 | Crs crs = new Crs(epsg_code, code);
|
||
127 | |||
128 | // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
||
129 | // mejor hecho.
|
||
130 | code = crs.getAbrev(); |
||
131 | |||
132 | data.put(code, crs); |
||
133 | |||
134 | return crs;
|
||
135 | } |
||
136 | 6927 | mgarcia | |
137 | 9204 | jlgomez | /**
|
138 | *
|
||
139 | * @param epsg_code
|
||
140 | * @param code
|
||
141 | * @param params
|
||
142 | * @return
|
||
143 | * @throws CrsException
|
||
144 | */
|
||
145 | 6927 | mgarcia | public ICrs getCRS(int epsg_code, String code, String params) throws CrsException { |
146 | if (data.containsKey(code))
|
||
147 | return (Crs) data.get(code);
|
||
148 | 7821 | jlgomez | |
149 | 6927 | mgarcia | Crs crs = new Crs(epsg_code, code,params);
|
150 | |||
151 | // LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
|
||
152 | // mejor hecho.
|
||
153 | code = crs.getAbrev(); |
||
154 | |||
155 | data.put(code, crs); |
||
156 | |||
157 | return crs;
|
||
158 | } |
||
159 | 7876 | jlgomez | |
160 | 9204 | jlgomez | /**
|
161 | *
|
||
162 | */
|
||
163 | 7704 | luisw | public IProjection get(String name) { |
164 | // TODO Auto-generated method stub
|
||
165 | try {
|
||
166 | return getCRS(name);
|
||
167 | } catch (CrsException e) {
|
||
168 | // TODO Auto-generated catch block
|
||
169 | e.printStackTrace(); |
||
170 | } |
||
171 | return null; |
||
172 | } |
||
173 | 9204 | jlgomez | |
174 | /**
|
||
175 | *
|
||
176 | */
|
||
177 | 9016 | luisw | public boolean doesRigurousTransformations() { |
178 | return true; |
||
179 | } |
||
180 | 6813 | mgarcia | } |