001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.renderer.shape;
017:
018: import java.awt.geom.AffineTransform;
019:
020: import junit.framework.TestCase;
021:
022: import org.geotools.data.shapefile.shp.ShapeType;
023: import org.geotools.referencing.ReferencingFactoryFinder;
024: import org.geotools.referencing.operation.matrix.GeneralMatrix;
025: import org.opengis.referencing.operation.MathTransform;
026: import org.opengis.referencing.operation.Matrix;
027: import org.opengis.referencing.operation.NoninvertibleTransformException;
028: import org.opengis.referencing.operation.TransformException;
029: import org.opengis.geometry.DirectPosition;
030: import org.opengis.geometry.MismatchedDimensionException;
031:
032: /**
033: *
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/test/java/org/geotools/renderer/shape/GeometryHandlerUtilitiesTest.java $
035: */
036: public class GeometryHandlerUtilitiesTest extends TestCase {
037: private static final double ACCURACY = 0.00000001;
038: public static final AffineTransform at = AffineTransform
039: .getScaleInstance(2, .5);
040: public static final String ALBERS = "PROJCS[\"BC_Albers\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101],TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Albers\"],PARAMETER[\"False_Easting\",1000000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-126],PARAMETER[\"Standard_Parallel_1\",50],PARAMETER[\"Standard_Parallel_2\",58.5],PARAMETER[\"Latitude_Of_Origin\",45],UNIT[\"Meter\",1]]";
041: public static final MathTransform CANT_TRANSFORM_3RD_ELEMENT = new MathTransform() {
042: public int getDimSource() {
043: // TODO Auto-generated method stub
044: return 0;
045: }
046:
047: public int getSourceDimensions() {
048: // TODO Auto-generated method stub
049: return 0;
050: }
051:
052: public int getDimTarget() {
053: // TODO Auto-generated method stub
054: return 0;
055: }
056:
057: public int getTargetDimensions() {
058: // TODO Auto-generated method stub
059: return 0;
060: }
061:
062: public DirectPosition transform(DirectPosition arg0,
063: DirectPosition arg1)
064: throws MismatchedDimensionException, TransformException {
065: // TODO Auto-generated method stub
066: return null;
067: }
068:
069: public void transform(double[] arg0, int arg1, double[] arg2,
070: int arg3, int arg4) throws TransformException {
071: if (arg1 == 2) {
072: throw new TransformException("boom");
073: }
074: }
075:
076: public void transform(float[] arg0, int arg1, float[] arg2,
077: int arg3, int arg4) throws TransformException {
078: // TODO Auto-generated method stub
079: }
080:
081: public Matrix derivative(DirectPosition arg0)
082: throws MismatchedDimensionException, TransformException {
083: // TODO Auto-generated method stub
084: return null;
085: }
086:
087: public MathTransform inverse()
088: throws NoninvertibleTransformException {
089: // TODO Auto-generated method stub
090: return null;
091: }
092:
093: public boolean isIdentity() {
094: // TODO Auto-generated method stub
095: return false;
096: }
097:
098: public String toWKT() throws UnsupportedOperationException {
099: // TODO Auto-generated method stub
100: return null;
101: }
102: };
103:
104: public static final MathTransform CANT_TRANSFORM_FIRST_ELEMENT = new MathTransform() {
105: public int getDimSource() {
106: // TODO Auto-generated method stub
107: return 0;
108: }
109:
110: public int getSourceDimensions() {
111: // TODO Auto-generated method stub
112: return 0;
113: }
114:
115: public int getDimTarget() {
116: // TODO Auto-generated method stub
117: return 0;
118: }
119:
120: public int getTargetDimensions() {
121: // TODO Auto-generated method stub
122: return 0;
123: }
124:
125: public DirectPosition transform(DirectPosition arg0,
126: DirectPosition arg1)
127: throws MismatchedDimensionException, TransformException {
128: // TODO Auto-generated method stub
129: return null;
130: }
131:
132: public void transform(double[] arg0, int arg1, double[] arg2,
133: int arg3, int arg4) throws TransformException {
134: if ((arg1 < 3) || (arg1 == (arg2.length - 2))) {
135: throw new TransformException("boom");
136: }
137: }
138:
139: public void transform(float[] arg0, int arg1, float[] arg2,
140: int arg3, int arg4) throws TransformException {
141: // TODO Auto-generated method stub
142: }
143:
144: public Matrix derivative(DirectPosition arg0)
145: throws MismatchedDimensionException, TransformException {
146: // TODO Auto-generated method stub
147: return null;
148: }
149:
150: public MathTransform inverse()
151: throws NoninvertibleTransformException {
152: // TODO Auto-generated method stub
153: return null;
154: }
155:
156: public boolean isIdentity() {
157: // TODO Auto-generated method stub
158: return false;
159: }
160:
161: public String toWKT() throws UnsupportedOperationException {
162: // TODO Auto-generated method stub
163: return null;
164: }
165: };
166:
167: public static final MathTransform NEVER_TRANSFORM = new MathTransform() {
168: public int getDimSource() {
169: // TODO Auto-generated method stub
170: return 0;
171: }
172:
173: public int getSourceDimensions() {
174: // TODO Auto-generated method stub
175: return 0;
176: }
177:
178: public int getDimTarget() {
179: // TODO Auto-generated method stub
180: return 0;
181: }
182:
183: public int getTargetDimensions() {
184: // TODO Auto-generated method stub
185: return 0;
186: }
187:
188: public DirectPosition transform(DirectPosition arg0,
189: DirectPosition arg1)
190: throws MismatchedDimensionException, TransformException {
191: // TODO Auto-generated method stub
192: return null;
193: }
194:
195: public void transform(double[] arg0, int arg1, double[] arg2,
196: int arg3, int arg4) throws TransformException {
197: throw new TransformException("exception");
198: }
199:
200: public void transform(float[] arg0, int arg1, float[] arg2,
201: int arg3, int arg4) throws TransformException {
202: // TODO Auto-generated method stub
203: }
204:
205: public Matrix derivative(DirectPosition arg0)
206: throws MismatchedDimensionException, TransformException {
207: // TODO Auto-generated method stub
208: return null;
209: }
210:
211: public MathTransform inverse()
212: throws NoninvertibleTransformException {
213: // TODO Auto-generated method stub
214: return null;
215: }
216:
217: public boolean isIdentity() {
218: // TODO Auto-generated method stub
219: return false;
220: }
221:
222: public String toWKT() throws UnsupportedOperationException {
223: // TODO Auto-generated method stub
224: return null;
225: }
226: };
227:
228: public void testTransform() throws Exception {
229: double[] src = new double[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
230: double[] dest = new double[8];
231:
232: MathTransform mt = ReferencingFactoryFinder
233: .getMathTransformFactory(null).createAffineTransform(
234: new GeneralMatrix(at));
235: GeometryHandlerUtilities
236: .transform(ShapeType.ARC, mt, src, dest);
237:
238: assertEquals(2d, dest[0], ACCURACY);
239: assertEquals(.5d, dest[1], ACCURACY);
240: assertEquals(4d, dest[2], ACCURACY);
241: assertEquals(1d, dest[3], ACCURACY);
242: assertEquals(6d, dest[4], ACCURACY);
243: assertEquals(1.5d, dest[5], ACCURACY);
244: assertEquals(8d, dest[6], ACCURACY);
245: assertEquals(2d, dest[7], ACCURACY);
246:
247: src = new double[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
248: dest = new double[8];
249: mt = NEVER_TRANSFORM;
250:
251: try {
252: GeometryHandlerUtilities.transform(ShapeType.ARC, mt, src,
253: dest);
254: assertFalse("Shouldn't get here", true);
255: } catch (Exception e) {
256: //correct
257: }
258:
259: dest = new double[] { 1, 1, 2, 2, 3, 3, 4, 4 };
260: mt = CANT_TRANSFORM_FIRST_ELEMENT;
261: GeometryHandlerUtilities.transform(ShapeType.POLYGON, mt, src,
262: dest);
263:
264: assertEquals(3d, dest[0], ACCURACY);
265: assertEquals(3d, dest[1], ACCURACY);
266: assertEquals(3d, dest[2], ACCURACY);
267: assertEquals(3d, dest[3], ACCURACY);
268: assertEquals(3d, dest[4], ACCURACY);
269: assertEquals(3d, dest[5], ACCURACY);
270: assertEquals(3d, dest[6], ACCURACY);
271: assertEquals(3d, dest[7], ACCURACY);
272:
273: dest = new double[] { 1, 1, 2, 2, 3, 3, 4, 4 };
274: mt = CANT_TRANSFORM_3RD_ELEMENT;
275: GeometryHandlerUtilities.transform(ShapeType.POLYGON, mt, src,
276: dest);
277: assertEquals(1d, dest[0], ACCURACY);
278: assertEquals(1d, dest[1], ACCURACY);
279: assertEquals(1d, dest[2], ACCURACY);
280: assertEquals(1d, dest[3], ACCURACY);
281: assertEquals(3d, dest[4], ACCURACY);
282: assertEquals(3d, dest[5], ACCURACY);
283: assertEquals(4d, dest[6], ACCURACY);
284: assertEquals(4d, dest[7], ACCURACY);
285: }
286: }
|