public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem target) throws SchemaException, OperationNotFoundException, FactoryRegistryException, FactoryException { super(delegate); this.target = target; this.schema = FeatureTypes.transform(delegate.getSchema(), target); // create transform cache transformers = new HashMap(); // cache "default" transform CoordinateReferenceSystem source = delegate.getSchema().getCoordinateReferenceSystem(); if (source != null) { MathTransform tx = ReferencingFactoryFinder.getCoordinateOperationFactory(hints) .createOperation(source, target) .getMathTransform(); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformers.put(source, transformer); } else { throw new RuntimeException( "Source was null in trying to create a reprojected feature collection!"); } }
.getCoordinateOperationFactory(hints) .createOperation(crs, target) .getMathTransform(); } catch (Exception e) { String msg = "Could not transform for crs: " + crs;
public MathTransform getMathTransform() { return delegate.getMathTransform(); } }
/** * Returns {@code true} if the specified operation is an identity conversion. This method always * returns {@code false} for transformations even if their associated math transform is an * identity one, because such transformations are usually datum shift and must be visible. */ private static boolean isIdentity(final CoordinateOperation operation) { return (operation instanceof Conversion) && operation.getMathTransform().isIdentity(); }
/** * Update the internal state after a change, before to apply transformation. The most important * change is to update the math transform, if needed. */ private void update() throws FactoryException { if (transform == null && sourceCRS != null && targetCRS != null) { transform = factory.createOperation(sourceCRS, targetCRS).getMathTransform(); } }
public ReprojectingFeatureIterator( SimpleFeatureIterator delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.target = target; this.schema = schema; tx = transformer; MathTransform transform = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(source, target) .getMathTransform(); tx.setMathTransform(transform); }
public ReprojectingIterator( Iterator<SimpleFeature> delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.target = target; this.schema = schema; tx = transformer; MathTransform transform = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(source, target) .getMathTransform(); tx.setMathTransform(transform); }
/** * Sets the {@link #sourceCRS} field and create the associated {@link #forward} transform. This * method do not create yet the {@link #inverse} transform, since it may not be needed. */ private void setSourceCRS(final CoordinateReferenceSystem crs) throws TransformException { final CoordinateReferenceSystem targetCRS = getCoordinateReferenceSystem(); final CoordinateOperation operation; try { operation = factory.createOperation(crs, targetCRS); } catch (FactoryException exception) { throw new TransformException(exception.getLocalizedMessage(), exception); } /* * Note: 'sourceCRS' must be set last, when we are sure that all other fields * are set to their correct value. This is in order to keep this instance in * a consistent state in case an exception is thrown. */ forward = operation.getMathTransform(); inverse = null; sourceCRS = crs; }
protected void setUp() throws Exception { super.setUp(); target = CRS.decode("EPSG:3005"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); }
protected void setUp() throws Exception { super.setUp(); target = CRS.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\"]]"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformer.setCoordinateReferenceSystem(target); }
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void testHtoH() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_H); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertFalse(mt.isIdentity()); assertInterfaced(mt); }
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void testHtoZ() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertFalse(mt.isIdentity()); assertInterfaced(mt); }
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void test2DtoH() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.NAD27); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_H); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); }
/** Tests transformation between vertical CRS. */ @Test public void testZIdentity() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertTrue(op instanceof Conversion); assertTrue(mt.isIdentity()); assertInterfaced(mt); }
/** Tests transformation between vertical CRS. */ @Test public void testHeightIdentity() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertTrue(op instanceof Conversion); assertTrue(mt.isIdentity()); assertInterfaced(mt); }
/** Tests a transformation on a {@link DirectPosition} object. */ @Test public void testDirectPositionTransform() throws FactoryException, TransformException { CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(WKT.UTM_10N); MathTransform t = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform(); DirectPosition position = new GeneralDirectPosition(-123, 55); position = t.transform(position, position); position = t.inverse().transform(position, position); assertEquals(-123, position.getOrdinate(0), 1E-6); assertEquals(55, position.getOrdinate(1), 1E-6); }
/** Tests transformation from 3D to vertical CRS. */ @Test public void test3D_to_Z() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); assertTransformEquals3_1(mt, 0, 0, 0, 0); assertTransformEquals3_1(mt, 5, 8, 20, 20); assertTransformEquals3_1(mt, -5, -8, 20, 20); }
/** Tests transformation from a 3D Geographic CRS to a single height. */ @Test public void test3D_to_H() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); assertTransformEquals3_1(mt, 0, 0, 0, 0); assertTransformEquals3_1(mt, 5, 8, 20, 20); assertTransformEquals3_1(mt, -5, -8, 20, 20); }
/** Tests transformation from 2D to 3D with Z above the ellipsoid. */ @Test public void test2D_to_3D() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.NAD27); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals2_3( mt, 0, 0, 0.001654978796746043, 0.0012755944235822696, 66.4042236590758); assertTransformEquals2_3( mt, 5, 8, 5.001262960018587, 8.001271733843957, 100.27929787896574); }
/** Tests transformation from 3D to 2D Geographic CRS. */ @Test public void test3D_to_2D() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.WGS84_DMHS); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertNotSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals3_2(mt, 0, 0, 0, 0.001654978796746043, 0.0012755944235822696); assertTransformEquals3_2(mt, 5, 8, 20, 5.0012629560319874, 8.001271729856333); assertTransformEquals3_2(mt, 5, 8, -20, 5.001262964005206, 8.001271737831601); }