root / org.gvsig.geotools.proj / trunk / org.gvsig.geotools.proj / org.gvsig.geotools.proj.lib.impl / src / main / java / org / gvsig / geotools / proj / lib / DefaultCRS.java @ 828
History | View | Annotate | Download (3.47 KB)
1 |
package org.gvsig.geotools.proj.lib; |
---|---|
2 |
|
3 |
import javax.measure.Unit; |
4 |
import javax.measure.quantity.Length; |
5 |
|
6 |
import org.cresques.cts.CRSAdapter; |
7 |
import org.cresques.cts.IProjection; |
8 |
import org.gvsig.geotools.proj.catalog.DefaultCRSDefinition; |
9 |
import org.gvsig.geotools.proj.catalog.DefaultTransformationDefinition; |
10 |
import org.gvsig.geotools.proj.catalog.utils.DistanceCalculator; |
11 |
import org.gvsig.proj.catalog.CRSDefinition; |
12 |
import org.gvsig.proj.catalog.exception.CoordinateReferenceSystemException; |
13 |
import org.gvsig.proj.catalog.exception.TransformationException; |
14 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
15 |
import org.opengis.referencing.crs.GeneralDerivedCRS; |
16 |
import org.opengis.referencing.crs.GeographicCRS; |
17 |
import org.opengis.referencing.crs.ProjectedCRS; |
18 |
import org.opengis.referencing.operation.CoordinateOperation; |
19 |
|
20 |
public class DefaultCRS implements org.gvsig.proj.CoordinateReferenceSystem { |
21 |
final private CoordinateReferenceSystem crs; |
22 |
final private CRSDefinition definition; |
23 |
|
24 |
public DefaultCRS(DefaultCRSDefinition definition) {
|
25 |
this.definition = definition;
|
26 |
this.crs = definition.getInternalCRS();
|
27 |
} |
28 |
|
29 |
/*
|
30 |
public DefaultCRS(CoordinateReferenceSystem crs)
|
31 |
throws UnsupportedCoordinateReferenceSystemException {
|
32 |
this.crs = crs;
|
33 |
GtCoordinateReferenceSystemManager manager = (GtCoordinateReferenceSystemManager) CoordinateReferenceSystemLocator.getManager();
|
34 |
try {
|
35 |
// FIXME: crs.toString? crs.toWKT?
|
36 |
this.definition = manager.getCatalogManager().parseCRSDefinition(crs.toString());
|
37 |
} catch (ParseException e) {
|
38 |
throw new UnsupportedCoordinateReferenceSystemException(e);
|
39 |
}
|
40 |
}*/
|
41 |
|
42 |
DefaultCRS(CoordinateReferenceSystem crs, CRSDefinition definition) { |
43 |
this.crs = crs;
|
44 |
this.definition = definition;
|
45 |
} |
46 |
|
47 |
CoordinateReferenceSystem getInternalCRS() { |
48 |
return crs;
|
49 |
} |
50 |
|
51 |
@Override
|
52 |
public boolean isProjected() { |
53 |
return (crs instanceof ProjectedCRS |
54 |
|| (crs instanceof GeneralDerivedCRS &&
|
55 |
((GeneralDerivedCRS)crs).getBaseCRS() instanceof ProjectedCRS));
|
56 |
} |
57 |
|
58 |
|
59 |
@Override
|
60 |
public boolean isGeographic() { |
61 |
return (crs instanceof GeographicCRS |
62 |
|| (crs instanceof GeneralDerivedCRS &&
|
63 |
((GeneralDerivedCRS)crs).getBaseCRS() instanceof GeographicCRS));
|
64 |
} |
65 |
|
66 |
@Override
|
67 |
public double[] toGeo(double[] point) throws TransformationException { |
68 |
if (isProjected()) {
|
69 |
double[] transformedPoint = new double[point.length]; |
70 |
// FIXME: cache toGeoTransform?
|
71 |
CoordinateOperation toGeo = ((GeneralDerivedCRS)crs).getConversionFromBase(); |
72 |
DefaultTransformationDefinition toGeoTransform = new DefaultTransformationDefinition(toGeo, true); |
73 |
toGeoTransform.apply(point, transformedPoint); |
74 |
return point;
|
75 |
} |
76 |
if (isGeographic()) {
|
77 |
return point;
|
78 |
} |
79 |
throw new TransformationException(); |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public double getDistance(double[] point1, double[] point2, Unit<Length> targetUnit) throws CoordinateReferenceSystemException { |
84 |
return DistanceCalculator.getDistance(this.crs, point1, point2, true, targetUnit); |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public double getDistance(double[] point1, double[] point2, boolean useBaseCRS, Unit<Length> targetUnit) throws CoordinateReferenceSystemException { |
89 |
return DistanceCalculator.getDistance(this.crs, point1, point2, useBaseCRS, targetUnit); |
90 |
} |
91 |
|
92 |
@Override
|
93 |
public CRSDefinition getDefinition() {
|
94 |
return definition;
|
95 |
} |
96 |
|
97 |
@Override
|
98 |
public DefaultCRS clone() throws CloneNotSupportedException { |
99 |
return new DefaultCRS(this.crs, this.definition); |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public IProjection getIProjection() {
|
104 |
return new CRSAdapter(this); |
105 |
} |
106 |
} |