root / org.gvsig.geotools.proj / trunk / org.gvsig.geotools.proj / org.gvsig.geotools.proj.lib.impl / src / main / java / org / cresques / cts / CRSAdapter.java @ 828
History | View | Annotate | Download (2.59 KB)
1 |
package org.cresques.cts; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
|
5 |
import org.cresques.cts.ICoordTrans; |
6 |
import org.cresques.cts.IProjection; |
7 |
import org.gvsig.geotools.proj.lib.GtCRSManager; |
8 |
import org.gvsig.proj.CoordinateReferenceSystem; |
9 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
10 |
import org.gvsig.proj.CoordinateTransformation; |
11 |
import org.gvsig.proj.catalog.CRSType; |
12 |
import org.gvsig.proj.catalog.datum.Ellipsoid; |
13 |
import org.gvsig.proj.catalog.exception.TransformationException; |
14 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
15 |
|
16 |
public class CRSAdapter implements IProjection { |
17 |
CoordinateReferenceSystem crs; |
18 |
CRSAdapter transformationTargetCrs = null;
|
19 |
CoordinateTransformation coordTrans = null;
|
20 |
|
21 |
public CRSAdapter(CoordinateReferenceSystem crs) {
|
22 |
this.crs = crs;
|
23 |
} |
24 |
|
25 |
public CRSAdapter(CoordinateReferenceSystem crs,
|
26 |
CoordinateTransformation coordTransformation, |
27 |
CoordinateReferenceSystem transformationTargetCrs) { |
28 |
this.crs = crs;
|
29 |
this.coordTrans = coordTransformation;
|
30 |
this.transformationTargetCrs = new CRSAdapter(transformationTargetCrs); |
31 |
} |
32 |
|
33 |
@Override
|
34 |
public String export(String format) { |
35 |
// TODO Auto-generated method stub
|
36 |
return null; |
37 |
} |
38 |
|
39 |
@Override
|
40 |
public String getAbrev() { |
41 |
return crs.getDefinition().getIdentifier();
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
public String getFullCode() { |
46 |
// TODO Auto-generated method stub
|
47 |
return getAbrev();
|
48 |
} |
49 |
|
50 |
@Override
|
51 |
public ICoordTrans getCT(IProjection dest) {
|
52 |
if (coordTrans!=null && |
53 |
dest.getCoordinateReferenceSystem().equals(transformationTargetCrs)) { |
54 |
return new CoordTransAdapter( |
55 |
coordTrans, |
56 |
this,
|
57 |
this.transformationTargetCrs);
|
58 |
} |
59 |
return null; |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public Point2D toGeo(Point2D pt) { |
64 |
double[] point = new double[2]; |
65 |
point[0] = pt.getX();
|
66 |
point[1] = pt.getY();
|
67 |
try {
|
68 |
point = crs.toGeo(point); |
69 |
} catch (TransformationException e) {
|
70 |
throw new RuntimeException(e); |
71 |
} |
72 |
return new Point2D.Double(point[0], point[1]); |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public boolean isProjected() { |
77 |
return this.crs.isProjected(); |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public double getScale(double minX, double maxX, double width, double dpi) { |
82 |
// TODO Auto-generated method stub
|
83 |
return 0; |
84 |
} |
85 |
|
86 |
@Override
|
87 |
public CoordinateReferenceSystem getCoordinateReferenceSystem() {
|
88 |
return crs;
|
89 |
} |
90 |
|
91 |
public Object clone() { |
92 |
return new CRSAdapter(this.crs); |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public IDatum getDatum() {
|
97 |
Ellipsoid ellipsoid = this.crs.getDefinition().getDatum().getEllipsoid();
|
98 |
if (ellipsoid!=null) { |
99 |
return new DatumAdapter(ellipsoid); |
100 |
} |
101 |
throw new UnsupportedOperationException("Datum is not available for non-geodetic CRSs"); |
102 |
} |
103 |
|
104 |
} |