root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.lib / org.gvsig.proj.lib.api / src / test / java / org / gvsig / proj / CoordinateTransformationIT.java @ 807
History | View | Annotate | Download (5.54 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2012 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.proj; |
24 |
|
25 |
import org.gvsig.proj.catalog.TransformationDefinition; |
26 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
27 |
|
28 |
/**
|
29 |
* {@link CoordinateTransformation} API acceptance tests.
|
30 |
*
|
31 |
* @author gvSIG Team
|
32 |
*/
|
33 |
public abstract class CoordinateTransformationIT extends |
34 |
AbstractLibraryAutoInitTestCase { |
35 |
|
36 |
protected CoordinateReferenceSystem source;
|
37 |
protected CoordinateReferenceSystem target;
|
38 |
protected CoordinateTransformation transformation;
|
39 |
protected CoordinateReferenceSystemManager manager;
|
40 |
|
41 |
protected void doSetUp() throws Exception { |
42 |
manager = createProjectionManager(); |
43 |
source = createSourceProjection(); |
44 |
target = createTargetProjection(); |
45 |
transformation = createTransformationFromDefinition(); |
46 |
} |
47 |
|
48 |
/**
|
49 |
* Creates a {@link CoordinateReferenceSystemManager} instance.
|
50 |
*
|
51 |
* @return the {@link CoordinateReferenceSystemManager} instance
|
52 |
*/
|
53 |
protected abstract CoordinateReferenceSystemManager createProjectionManager(); |
54 |
|
55 |
/**
|
56 |
* Returns the transformation definition to create the CoordinateTransformation
|
57 |
* to test.
|
58 |
*
|
59 |
* @return the authority name
|
60 |
*/
|
61 |
protected abstract TransformationDefinition getTransformationDefinition(); |
62 |
|
63 |
/**
|
64 |
* Creates the transformation to be tested
|
65 |
*/
|
66 |
public CoordinateTransformation createTransformationFromDefinition() throws Exception { |
67 |
TransformationDefinition definition = getTransformationDefinition(); |
68 |
return manager.getCoordinateTransformation(definition);
|
69 |
} |
70 |
|
71 |
protected abstract CoordinateReferenceSystem createSourceProjection() |
72 |
throws Exception; |
73 |
|
74 |
protected abstract CoordinateReferenceSystem createTargetProjection() |
75 |
throws Exception; |
76 |
|
77 |
/**
|
78 |
* Test method for
|
79 |
* {@link org.gvsig.proj.CoordinateTransformation#getSource()}.
|
80 |
*/
|
81 |
public void testGetSourceProjection() { |
82 |
assertEquals(source, transformation.getSource()); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Test method for
|
87 |
* {@link org.gvsig.proj.CoordinateTransformation#getTarget()}.
|
88 |
*/
|
89 |
public void testGetTargetProjection() { |
90 |
assertEquals(target, transformation.getTarget()); |
91 |
} |
92 |
|
93 |
/**
|
94 |
* Test method for
|
95 |
* {@link org.gvsig.proj.CoordinateTransformation#getInverse()}.
|
96 |
*/
|
97 |
public void testGetReverse() { |
98 |
CoordinateTransformation reverseTransformation = |
99 |
transformation.getInverse(); |
100 |
assertEquals(target, reverseTransformation.getSource()); |
101 |
assertEquals(source, reverseTransformation.getTarget()); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* The input point to test the transformation
|
106 |
*
|
107 |
* @return
|
108 |
*/
|
109 |
public abstract double[] getInputPoint(); |
110 |
/**
|
111 |
* The output point to thest the transformation. This point
|
112 |
* should be a known result of applying the transformation on
|
113 |
* getInputPoint()
|
114 |
* @return
|
115 |
*/
|
116 |
public abstract double[] getResultPoint(); |
117 |
/**
|
118 |
* Gets the maximum numeric tolerance to accept the result of
|
119 |
* the transformation as valid
|
120 |
*
|
121 |
* @return
|
122 |
*/
|
123 |
public abstract double getResultTolerance(); |
124 |
|
125 |
/**
|
126 |
* Test method for
|
127 |
* {@link org.gvsig.proj.CoordinateTransformation#apply(double[])}.
|
128 |
*/
|
129 |
public void testApplyTransformationInline() { |
130 |
double[] input = getInputPoint(); |
131 |
transformation.apply(input); |
132 |
assertTrue(pointsEquals(getResultPoint(), input, getResultTolerance())); |
133 |
} |
134 |
|
135 |
public boolean pointsEquals(double[] point1, double[] point2, double tolerance) { |
136 |
for (int i=0; i<point1.length; i++) { |
137 |
if (Math.abs(point1[i]-point2[i])>tolerance) { |
138 |
return false; |
139 |
} |
140 |
} |
141 |
return true; |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Test method for
|
146 |
* {@link org.gvsig.proj.CoordinateTransformation#apply(double[])}.
|
147 |
*/
|
148 |
public void testApplyTransformation() { |
149 |
double[] input = getInputPoint(); |
150 |
double[] transformed = new double[input.length]; |
151 |
transformation.apply(input, transformed); |
152 |
assertTrue(pointsEquals(getResultPoint(), transformed, getResultTolerance())); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Test method for
|
157 |
* {@link org.gvsig.proj.CoordinateTransformation#getInverse()}
|
158 |
* and
|
159 |
* {@link org.gvsig.proj.CoordinateTransformation#apply(double[])}.
|
160 |
*/
|
161 |
public void testApplyInverseTransformation() { |
162 |
double[] input = getInputPoint(); |
163 |
double[] transformed = new double[input.length]; |
164 |
transformation.apply(input, transformed); |
165 |
CoordinateTransformation reverseTransformation = |
166 |
transformation.getInverse(); |
167 |
reverseTransformation.apply(transformed); |
168 |
assertTrue(pointsEquals(input, transformed, getResultTolerance())); |
169 |
} |
170 |
} |