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!"); } }
/** * Check we are actually using the EPSG database for anything not in override * * @throws TransformException */ @Test public void testFallbackOnEPSGDatabaseStd() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode("EPSG:3002"); CoordinateReferenceSystem target = CRS.decode("EPSG:4326"); CoordinateOperation co = CRS.getCoordinateOperationFactory(true).createOperation(source, target); ConcatenatedOperation cco = (ConcatenatedOperation) co; // the EPSG one only has two steps, the non EPSG one 4 assertEquals(2, cco.getOperations().size()); }
ReferencingFactoryFinder .getCoordinateOperationFactory(hints) .createOperation(crs, target) .getMathTransform(); } catch (Exception e) {
/** * 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(); } }
/** * Returns an operation for conversion or transformation between two coordinate reference * systems using the specified method. The current implementation delegates to the {@linkplain * CoordinateOperationFactory coordinate operation factory} specified at construction time with * no caching. * * @deprecated Will be removed. */ public CoordinateOperation createOperation( final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS, final OperationMethod method) throws OperationNotFoundException, FactoryException { return getBackingFactory().createOperation(sourceCRS, targetCRS, method); } }
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); }
public void testOperationSourceTarget() throws Exception { // flip one way CoordinateReferenceSystem source = CRS.decode("EPSG:32638", true); // lon/lat CoordinateReferenceSystem target = CRS.decode("EPSG:4326", false); // lat/lon CoordinateOperationFactory coordinateOperationFactory = CRS.getCoordinateOperationFactory(true); CoordinateOperation co = coordinateOperationFactory.createOperation(source, target); assertEquals(source, co.getSourceCRS()); assertEquals(target, co.getTargetCRS()); // flip the other source = CRS.decode("EPSG:32638", false); // lat/lon target = CRS.decode("EPSG:4326", true); // lon/lat co = coordinateOperationFactory.createOperation(source, target); assertEquals(source, co.getSourceCRS()); assertEquals(target, co.getTargetCRS()); }
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); }
/** Tests transformation between incompatible vertical CRS. */ @Test(expected = OperationNotFoundException.class) public void testIncompatibleVertical() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); assertNull(op); // We should not reach this point. }
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 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); }