root / org.gvsig.sis.proj / trunk / org.gvsig.sis.proj / org.gvsig.sis.proj.catalog.impl / src / main / java / org / gvsig / sis / proj / catalog / SisCRSCatalogManager.java @ 813
History | View | Annotate | Download (7.99 KB)
1 |
package org.gvsig.sis.proj.catalog; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Iterator; |
6 |
import java.util.List; |
7 |
import java.util.ServiceLoader; |
8 |
import java.util.Set; |
9 |
|
10 |
import org.apache.sis.referencing.CRS; |
11 |
import org.gvsig.proj.catalog.CRSCatalogManager; |
12 |
import org.gvsig.proj.catalog.CRSDefinition; |
13 |
import org.gvsig.proj.catalog.TransformationDefinition; |
14 |
import org.gvsig.proj.catalog.exception.CRSCatalogException; |
15 |
import org.gvsig.proj.catalog.exception.CoordinateReferenceSystemNotFoundException; |
16 |
import org.gvsig.proj.catalog.exception.IncompatibleDefinitionException; |
17 |
import org.opengis.referencing.NoSuchAuthorityCodeException; |
18 |
import org.opengis.referencing.crs.CRSAuthorityFactory; |
19 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
20 |
import org.opengis.referencing.operation.CoordinateOperation; |
21 |
import org.opengis.util.FactoryException; |
22 |
|
23 |
public class SisCRSCatalogManager implements CRSCatalogManager { |
24 |
|
25 |
public SisCRSCatalogManager() {
|
26 |
} |
27 |
|
28 |
@Override
|
29 |
public List<String> getAuthorityNames() { |
30 |
ArrayList<String> authNames = new ArrayList<String>(); |
31 |
ServiceLoader<CRSAuthorityFactory> loader = (ServiceLoader<CRSAuthorityFactory>) ServiceLoader.load(CRSAuthorityFactory.class); |
32 |
Iterator<CRSAuthorityFactory> iterator = loader.iterator();
|
33 |
CRSAuthorityFactory factory; |
34 |
while (iterator.hasNext()) {
|
35 |
factory = iterator.next(); |
36 |
authNames.add(factory.getAuthority().getTitle().toString()); |
37 |
} |
38 |
return authNames;
|
39 |
} |
40 |
|
41 |
@Override
|
42 |
public List<String> getCodes() { |
43 |
ArrayList<String> codes = new ArrayList<String>(); |
44 |
ServiceLoader<CRSAuthorityFactory> loader = (ServiceLoader<CRSAuthorityFactory>) ServiceLoader.load(CRSAuthorityFactory.class); |
45 |
Iterator<CRSAuthorityFactory> iterator = loader.iterator();
|
46 |
CRSAuthorityFactory factory; |
47 |
while (iterator.hasNext()) {
|
48 |
factory = iterator.next(); |
49 |
Set<String> authCodes; |
50 |
try {
|
51 |
authCodes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); |
52 |
for (String code: authCodes) { |
53 |
codes.add(code); |
54 |
} |
55 |
} catch (FactoryException e) {
|
56 |
// TODO Auto-generated catch block
|
57 |
e.printStackTrace(); |
58 |
} |
59 |
|
60 |
} |
61 |
return codes;
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public List<String> getCodes(String authorityName) { |
66 |
ArrayList<String> codes = new ArrayList<String>(); |
67 |
try {
|
68 |
CRSAuthorityFactory factory = CRS.getAuthorityFactory(authorityName); |
69 |
Set<String> authCodes; |
70 |
authCodes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); |
71 |
for (String code: authCodes) { |
72 |
codes.add(code); |
73 |
} |
74 |
} catch (FactoryException e) {
|
75 |
// TODO Auto-generated catch block
|
76 |
e.printStackTrace(); |
77 |
} |
78 |
|
79 |
return codes;
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public List<String> search(String searchString) { |
84 |
// TODO Auto-generated method stub
|
85 |
return null; |
86 |
} |
87 |
|
88 |
@Override
|
89 |
public List<String> search(String authority, String searchString) { |
90 |
// TODO Auto-generated method stub
|
91 |
return null; |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public CRSDefinition getCRSDefinition(String code) throws CoordinateReferenceSystemNotFoundException { |
96 |
CoordinateReferenceSystem crs; |
97 |
try {
|
98 |
crs = CRS.forCode(code); |
99 |
} catch (NoSuchAuthorityCodeException e) {
|
100 |
throw new CoordinateReferenceSystemNotFoundException(code, e); |
101 |
} catch (FactoryException e) {
|
102 |
// FIXME: authoritynotfoundexception;
|
103 |
throw new CoordinateReferenceSystemNotFoundException(code, e); |
104 |
} |
105 |
return new DefaultCRSDefinition(crs); |
106 |
} |
107 |
|
108 |
public CRSDefinition getCRSDefinition(CoordinateReferenceSystem crs) throws CoordinateReferenceSystemNotFoundException { |
109 |
return new DefaultCRSDefinition(crs); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public CRSDefinition getCRSDefinitionFromWKT(String wkt) throws CoordinateReferenceSystemNotFoundException { |
114 |
CoordinateReferenceSystem crs; |
115 |
try {
|
116 |
crs = CRS.fromWKT(wkt); |
117 |
} catch (NoSuchAuthorityCodeException e) {
|
118 |
// FIXME: unsupported crs type; // FIXME: failed parsing??
|
119 |
throw new CoordinateReferenceSystemNotFoundException(wkt, e); |
120 |
} catch (FactoryException e) {
|
121 |
// FIXME: authoritynotfoundexception;
|
122 |
throw new CoordinateReferenceSystemNotFoundException(wkt, e); |
123 |
} |
124 |
return new DefaultCRSDefinition(crs); |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public CRSDefinition getCompoundCRS(CRSDefinition... crsList) throws IncompatibleDefinitionException { |
129 |
DefaultCRSDefinition[] defs = (DefaultCRSDefinition[]) crsList; |
130 |
ArrayList<CoordinateReferenceSystem> components = new ArrayList<CoordinateReferenceSystem>(); |
131 |
for (CRSDefinition def: defs) {
|
132 |
if (def instanceof DefaultCRSDefinition) { |
133 |
components.add(((DefaultCRSDefinition)def).getInternalCRS()); |
134 |
} |
135 |
else {
|
136 |
throw new IncompatibleDefinitionException(); |
137 |
} |
138 |
|
139 |
} |
140 |
CoordinateReferenceSystem compoundCRS; |
141 |
try {
|
142 |
compoundCRS = CRS.compound(components.toArray(new CoordinateReferenceSystem[components.size()]));
|
143 |
return new DefaultCRSDefinition(compoundCRS); |
144 |
} catch (FactoryException e) {
|
145 |
// FIXME: which kind of exception
|
146 |
throw new IncompatibleDefinitionException(e); |
147 |
} |
148 |
} |
149 |
|
150 |
@Override
|
151 |
public TransformationDefinition getTransformationDefinition(String code) { |
152 |
// TODO Auto-generated method stub
|
153 |
return null; |
154 |
} |
155 |
|
156 |
public TransformationDefinition getTransformationDefinition(CoordinateOperation operation, boolean inverse) { |
157 |
// TODO Auto-generated method stub
|
158 |
return null; |
159 |
} |
160 |
|
161 |
@Override
|
162 |
public TransformationDefinition getTransformationDefinitionFromWKT(String wkt) { |
163 |
// TODO Auto-generated method stub
|
164 |
return null; |
165 |
} |
166 |
|
167 |
@Override
|
168 |
public String registerCoordinateReferenceSystem(String wktDefinition, String description) { |
169 |
// TODO Auto-generated method stub
|
170 |
return null; |
171 |
} |
172 |
|
173 |
@Override
|
174 |
public String registerTransformation(String wktDefinition, String description) { |
175 |
// TODO Auto-generated method stub
|
176 |
return null; |
177 |
} |
178 |
|
179 |
@Override
|
180 |
public String registerCoordinateTransformationPVT(String sourceCRS, String targetCRS, String description, |
181 |
float xTraslation, float yTraslation, float zTraslation, float xRotation, float yRotation, float zRotation, |
182 |
float scaleDifference) {
|
183 |
// TODO Auto-generated method stub
|
184 |
return null; |
185 |
} |
186 |
|
187 |
@Override
|
188 |
public String registerCoordinateTransformationCFR(String sourceCRS, String targetCRS, String description, |
189 |
float xTraslation, float yTraslation, float zTraslation, float xRotation, float yRotation, float zRotation, |
190 |
float scaleDifference) {
|
191 |
// TODO Auto-generated method stub
|
192 |
return null; |
193 |
} |
194 |
|
195 |
@Override
|
196 |
public String registerCoordinateTransformation(String sourceCRS, String targetCRS, String description, |
197 |
File ntv2Grid) {
|
198 |
// TODO Auto-generated method stub
|
199 |
return null; |
200 |
} |
201 |
|
202 |
@Override
|
203 |
public List<TransformationDefinition> getCoordinateTransformations(CRSDefinition source, CRSDefinition target) throws CRSCatalogException { |
204 |
ArrayList<TransformationDefinition> transforms = new ArrayList<TransformationDefinition>(); |
205 |
try {
|
206 |
CoordinateReferenceSystem sourceCRS = ((DefaultCRSDefinition)source).getInternalCRS(); |
207 |
CoordinateReferenceSystem targetCRS = ((DefaultCRSDefinition)target).getInternalCRS(); |
208 |
DefaultTransformationDefinition def = new DefaultTransformationDefinition(CRS.findOperation(sourceCRS, targetCRS, null)); |
209 |
transforms.add(def); |
210 |
} catch (NoSuchAuthorityCodeException e) {
|
211 |
// TODO Auto-generated catch block
|
212 |
e.printStackTrace(); |
213 |
} catch (FactoryException e) {
|
214 |
// TODO Auto-generated catch block
|
215 |
e.printStackTrace(); |
216 |
} catch (ClassCastException e) { |
217 |
throw new IncompatibleDefinitionException(e); |
218 |
} |
219 |
return transforms;
|
220 |
} |
221 |
|
222 |
@Override
|
223 |
public List<TransformationDefinition> getCoordinateTransformations(String source, String target) { |
224 |
ArrayList<TransformationDefinition> transforms = new ArrayList<TransformationDefinition>(); |
225 |
try {
|
226 |
CoordinateReferenceSystem sourceCRS = CRS.forCode(source); |
227 |
CoordinateReferenceSystem targetCRS = CRS.forCode(target); |
228 |
DefaultTransformationDefinition def = new DefaultTransformationDefinition(CRS.findOperation(sourceCRS, targetCRS, null)); |
229 |
transforms.add(def); |
230 |
} catch (NoSuchAuthorityCodeException e) {
|
231 |
// TODO Auto-generated catch block
|
232 |
e.printStackTrace(); |
233 |
} catch (FactoryException e) {
|
234 |
// TODO Auto-generated catch block
|
235 |
e.printStackTrace(); |
236 |
} |
237 |
return transforms;
|
238 |
} |
239 |
|
240 |
} |