01: package org.geotools.data.store;
02:
03: import java.util.Iterator;
04:
05: import org.geotools.data.crs.ReprojectFeatureResults;
06: import org.geotools.feature.Feature;
07: import org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer;
08: import org.geotools.referencing.CRS;
09: import org.geotools.referencing.ReferencingFactoryFinder;
10: import org.opengis.feature.simple.SimpleFeature;
11: import org.opengis.referencing.crs.CoordinateReferenceSystem;
12: import org.opengis.referencing.operation.MathTransform2D;
13:
14: import com.vividsolutions.jts.geom.LineString;
15: import com.vividsolutions.jts.geom.Point;
16:
17: public class ReprojectFeatureResultsTest extends
18: FeatureCollectionWrapperTestSupport {
19:
20: CoordinateReferenceSystem target;
21: GeometryCoordinateSequenceTransformer transformer;
22:
23: protected void setUp() throws Exception {
24: super .setUp();
25:
26: target = CRS
27: .parseWKT("PROJCS[\"BC_Albers\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101],TOWGS84[0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Albers_Conic_Equal_Area\"],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],AUTHORITY[\"EPSG\",\"42102\"]]");
28:
29: MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder
30: .getCoordinateOperationFactory(null).createOperation(
31: crs, target).getMathTransform();
32: transformer = new GeometryCoordinateSequenceTransformer();
33: transformer.setMathTransform(tx);
34: transformer.setCoordinateReferenceSystem(target);
35: }
36:
37: public void testNormal() throws Exception {
38:
39: Iterator reproject = new ReprojectFeatureResults(delegate,
40: target).iterator();
41: Iterator reader = delegate.iterator();
42:
43: while (reader.hasNext()) {
44: Feature normal = (Feature) reader.next();
45: Feature reprojected = (Feature) reproject.next();
46:
47: Point p1 = (Point) normal.getAttribute("defaultGeom");
48: Point p2 = (Point) reprojected.getAttribute("defaultGeom");
49:
50: if (p1 != null) {
51: assertEquals(crs, p1.getUserData());
52: assertEquals(target, p2.getUserData());
53:
54: p1 = (Point) transformer.transform(p1);
55: assertTrue(p1.equals(p2));
56: } else {
57: assertNull(p2);
58: }
59:
60: LineString l1 = (LineString) normal
61: .getAttribute("otherGeom");
62: LineString l2 = (LineString) reprojected
63: .getAttribute("otherGeom");
64: if (l1 != null) {
65: l1 = (LineString) transformer.transform(l1);
66: assertTrue(l1.equals(l2));
67: } else {
68: assertNull(l2);
69: }
70: }
71:
72: }
73:
74: public void testBounds() throws Exception {
75: ReprojectFeatureResults rfr = new ReprojectFeatureResults(
76: delegate, target);
77: rfr.getBounds();
78: }
79: }
|