root / org.gvsig.geotools.proj / trunk / org.gvsig.geotools.proj / org.gvsig.geotools.proj.lib.impl / src / main / java / org / gvsig / geotools / proj / lib / DefaultTransformation.java @ 867
History | View | Annotate | Download (4.07 KB)
1 | 828 | cmartinez | package org.gvsig.geotools.proj.lib; |
---|---|---|---|
2 | |||
3 | import java.text.ParseException; |
||
4 | import java.util.HashSet; |
||
5 | import java.util.Set; |
||
6 | |||
7 | import org.geotools.referencing.wkt.Parser; |
||
8 | import org.gvsig.geotools.proj.catalog.DefaultCRSDefinition; |
||
9 | import org.gvsig.geotools.proj.catalog.DefaultTransformationDefinition; |
||
10 | import org.gvsig.proj.CoordinateReferenceSystem; |
||
11 | import org.gvsig.proj.CoordinateReferenceSystemLocator; |
||
12 | import org.gvsig.proj.CoordinateTransformation; |
||
13 | import org.gvsig.proj.catalog.CRSDefinition; |
||
14 | import org.gvsig.proj.catalog.TextSerialization.Format; |
||
15 | import org.gvsig.proj.catalog.TextSerialization.WKTConvention; |
||
16 | import org.gvsig.proj.catalog.TransformationDefinition; |
||
17 | import org.gvsig.proj.catalog.exception.NoninvertibleTransformException; |
||
18 | import org.gvsig.proj.catalog.exception.TransformationException; |
||
19 | import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
||
20 | 853 | cmartinez | import org.gvsig.proj.catalog.extent.Extent; |
21 | 828 | cmartinez | import org.opengis.referencing.ReferenceIdentifier; |
22 | import org.opengis.referencing.operation.CoordinateOperation; |
||
23 | import org.opengis.referencing.operation.MathTransform; |
||
24 | import org.opengis.referencing.operation.TransformException; |
||
25 | import org.opengis.referencing.operation.Transformation; |
||
26 | |||
27 | public class DefaultTransformation implements |
||
28 | CoordinateTransformation { |
||
29 | 831 | cmartinez | final protected MathTransform mathTransform ; |
30 | final protected DefaultCRS source; |
||
31 | final protected DefaultCRS target; |
||
32 | 828 | cmartinez | final protected TransformationDefinition definition; |
33 | |||
34 | 831 | cmartinez | public DefaultTransformation(MathTransform transform,
|
35 | TransformationDefinition definition, |
||
36 | DefaultCRS source, |
||
37 | DefaultCRS target) { |
||
38 | this.mathTransform = transform;
|
||
39 | 828 | cmartinez | this.definition = definition;
|
40 | 831 | cmartinez | this.source = source;
|
41 | this.target = target;
|
||
42 | 828 | cmartinez | } |
43 | |||
44 | 831 | cmartinez | /*
|
45 | 828 | cmartinez | public DefaultTransformation(DefaultTransformationDefinition definition)
|
46 | throws UnsupportedOperationException, ParseException {
|
||
47 | this.definition = definition;
|
||
48 | this.operation = definition.getInternalOperation();
|
||
49 | this.inverse = false;
|
||
50 | 831 | cmartinez | }*/
|
51 | 828 | cmartinez | |
52 | 831 | cmartinez | /*
|
53 | 828 | cmartinez | public DefaultTransformation(CoordinateOperation operation, TransformationDefinition definition, boolean inverse) {
|
54 | this.operation = operation;
|
||
55 | this.definition = definition;
|
||
56 | this.inverse = inverse;
|
||
57 | 831 | cmartinez | }*/
|
58 | 828 | cmartinez | |
59 | @Override
|
||
60 | 831 | cmartinez | public DefaultCRS getSourceCRS() {
|
61 | 828 | cmartinez | return source;
|
62 | } |
||
63 | |||
64 | @Override
|
||
65 | 831 | cmartinez | public DefaultCRS getTargetCRS() {
|
66 | 828 | cmartinez | return target;
|
67 | } |
||
68 | |||
69 | @Override
|
||
70 | public void apply(double[] point) throws TransformationException { |
||
71 | try {
|
||
72 | getMathTransform().transform(point, 0, point, 0, 1); |
||
73 | } catch (TransformException e) {
|
||
74 | throw new TransformationException(getDefinition().getIdentifier(), e); |
||
75 | |||
76 | } |
||
77 | } |
||
78 | |||
79 | @Override
|
||
80 | public void apply(double[] srcPoint, double[] dstPoint) throws TransformationException { |
||
81 | try {
|
||
82 | getMathTransform().transform(srcPoint, 0, dstPoint, 0, 1); |
||
83 | } catch (TransformException e) {
|
||
84 | throw new TransformationException(getDefinition().getIdentifier(), e); |
||
85 | |||
86 | } |
||
87 | } |
||
88 | |||
89 | |||
90 | @Override
|
||
91 | public void apply(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformationException { |
||
92 | try {
|
||
93 | getMathTransform().transform(srcPts, srcOff, dstPts, dstOff, numPts); |
||
94 | } catch (TransformException e) {
|
||
95 | throw new TransformationException(getDefinition().getIdentifier(), e); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | protected MathTransform getMathTransform() throws TransformationException { |
||
100 | return mathTransform;
|
||
101 | } |
||
102 | |||
103 | @Override
|
||
104 | public CoordinateTransformation getInverse() throws NoninvertibleTransformException { |
||
105 | 831 | cmartinez | try {
|
106 | return new DefaultTransformation(this.mathTransform.inverse(), this.definition, this.target, this.source); |
||
107 | } catch (org.opengis.referencing.operation.NoninvertibleTransformException e) {
|
||
108 | throw new NoninvertibleTransformException(e); |
||
109 | 828 | cmartinez | } |
110 | } |
||
111 | |||
112 | @Override
|
||
113 | public TransformationDefinition getDefinition() {
|
||
114 | return definition;
|
||
115 | } |
||
116 | |||
117 | @Override
|
||
118 | public boolean isIdentity() throws TransformationException { |
||
119 | return getMathTransform().isIdentity();
|
||
120 | } |
||
121 | |||
122 | @Override
|
||
123 | protected DefaultTransformation clone() throws CloneNotSupportedException { |
||
124 | 831 | cmartinez | return new DefaultTransformation(this.mathTransform, this.definition, this.source, this.target); |
125 | 828 | cmartinez | } |
126 | 867 | cmartinez | |
127 | @Override
|
||
128 | public String toString() { |
||
129 | return getDefinition().toString();
|
||
130 | } |
||
131 | 828 | cmartinez | |
132 | } |