01: package org.geotools.data.store;
02:
03: import java.util.Iterator;
04:
05: import org.geotools.feature.Feature;
06: import org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer;
07: import org.geotools.referencing.CRS;
08: import org.geotools.referencing.ReferencingFactoryFinder;
09: import org.opengis.referencing.crs.CoordinateReferenceSystem;
10: import org.opengis.referencing.operation.MathTransform2D;
11:
12: import com.vividsolutions.jts.geom.LineString;
13: import com.vividsolutions.jts.geom.Point;
14:
15: public class ReprojectingFeatureCollectionTest extends
16: FeatureCollectionWrapperTestSupport {
17:
18: CoordinateReferenceSystem target;
19: GeometryCoordinateSequenceTransformer transformer;
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23:
24: target = CRS
25: .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\"]]");
26:
27: MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder
28: .getCoordinateOperationFactory(null).createOperation(
29: crs, target).getMathTransform();
30: transformer = new GeometryCoordinateSequenceTransformer();
31: transformer.setMathTransform(tx);
32: }
33:
34: public void testNormal() throws Exception {
35:
36: Iterator reproject = new ReprojectingFeatureCollection(
37: delegate, target).iterator();
38: Iterator reader = delegate.iterator();
39:
40: while (reader.hasNext()) {
41: Feature normal = (Feature) reader.next();
42: Feature reprojected = (Feature) reproject.next();
43:
44: Point p1 = (Point) normal.getAttribute("defaultGeom");
45: Point p2 = (Point) reprojected.getAttribute("defaultGeom");
46: if (p1 != null) {
47: p1 = (Point) transformer.transform(p1);
48: assertTrue(p1.equals(p2));
49: } else {
50: assertNull(p2);
51: }
52:
53: LineString l1 = (LineString) normal
54: .getAttribute("otherGeom");
55: LineString l2 = (LineString) reprojected
56: .getAttribute("otherGeom");
57: if (l1 != null) {
58: l1 = (LineString) transformer.transform(l1);
59: assertTrue(l1.equals(l2));
60: } else {
61: assertNull(l2);
62: }
63: }
64:
65: }
66:
67: public void testBounds() throws Exception {
68: ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(
69: delegate, target);
70: rfc.getBounds();
71: }
72: }
|