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 |
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 |
import org.gvsig.proj.catalog.extent.Extent; |
21 |
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 |
final protected MathTransform mathTransform ; |
30 |
final protected DefaultCRS source; |
31 |
final protected DefaultCRS target; |
32 |
final protected TransformationDefinition definition; |
33 |
|
34 |
public DefaultTransformation(MathTransform transform,
|
35 |
TransformationDefinition definition, |
36 |
DefaultCRS source, |
37 |
DefaultCRS target) { |
38 |
this.mathTransform = transform;
|
39 |
this.definition = definition;
|
40 |
this.source = source;
|
41 |
this.target = target;
|
42 |
} |
43 |
|
44 |
/*
|
45 |
public DefaultTransformation(DefaultTransformationDefinition definition)
|
46 |
throws UnsupportedOperationException, ParseException {
|
47 |
this.definition = definition;
|
48 |
this.operation = definition.getInternalOperation();
|
49 |
this.inverse = false;
|
50 |
}*/
|
51 |
|
52 |
/*
|
53 |
public DefaultTransformation(CoordinateOperation operation, TransformationDefinition definition, boolean inverse) {
|
54 |
this.operation = operation;
|
55 |
this.definition = definition;
|
56 |
this.inverse = inverse;
|
57 |
}*/
|
58 |
|
59 |
@Override
|
60 |
public DefaultCRS getSourceCRS() {
|
61 |
return source;
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public DefaultCRS getTargetCRS() {
|
66 |
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 |
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 |
} |
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 |
return new DefaultTransformation(this.mathTransform, this.definition, this.source, this.target); |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public String toString() { |
129 |
return getDefinition().toString();
|
130 |
} |
131 |
|
132 |
} |