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!"); } }
(MathTransform2D) ReferencingFactoryFinder .getCoordinateOperationFactory(hints) .createOperation(crs, target) .getMathTransform();
/** * Returns the {@linkplain CoordinateOperationFactory coordinate operation factory} singleton. * * @throws FactoryNotFoundException if no factory was found for the requested type. * @throws FactoryRegistryException if the factory can't be obtained for an other reason. */ public CoordinateOperationFactory getCoordinateOperationFactory() throws FactoryRegistryException { return ReferencingFactoryFinder.getCoordinateOperationFactory(hints); }
/** Returns a backing factory from the specified hints. */ private static CoordinateOperationFactory getBackingFactory(final Hints hints) { for (final CoordinateOperationFactory candidate : ReferencingFactoryFinder.getCoordinateOperationFactories(hints)) { if (!(candidate instanceof BufferedCoordinateOperationFactory)) { return candidate; } } // The following is likely to thrown a FactoryNotFoundException, // which is the intended behavior. return ReferencingFactoryFinder.getCoordinateOperationFactory(hints); }
/** * Returns a coordinate operation factory for this adapter. This method will try to fetch this * information from the coordinate operation authority factory, or will returns the default one * if no explicit factory were found. */ final CoordinateOperationFactory getCoordinateOperationFactory() throws FactoryException { if (operationFactory instanceof Factory) { final Factory factory = (Factory) operationFactory; final Map hints = factory.getImplementationHints(); final Object candidate = hints.get(Hints.COORDINATE_OPERATION_FACTORY); if (candidate instanceof CoordinateOperationFactory) { return (CoordinateOperationFactory) candidate; } } return ReferencingFactoryFinder.getCoordinateOperationFactory(hints()); }
/** * Returns the coordinate operation factory used by {@link * #findMathTransform(CoordinateReferenceSystem, CoordinateReferenceSystem) findMathTransform} * convenience methods. * * @param lenient {@code true} if the coordinate operations should be created even when there is * no information available for a datum shift. * @since 2.4 */ public static CoordinateOperationFactory getCoordinateOperationFactory(final boolean lenient) { CoordinateOperationFactory factory = (lenient) ? lenientFactory : strictFactory; if (factory == null) { synchronized (CRS.class) { factory = (lenient) ? lenientFactory : strictFactory; if (factory == null) { final Hints hints = GeoTools.getDefaultHints(); if (lenient) { hints.put(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE); } factory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints); if (lenient) { lenientFactory = factory; } else { strictFactory = factory; } } } } return factory; }
ensureNonNull("targetCRS", targetCRS); defaultCRS = CRS.equalsIgnoreMetadata(sourceCRS, targetCRS) ? null : sourceCRS; factory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints);
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); }
/** Prints the math transforms between every pairs of the specified authority code. */ private void transform(final PrintWriter out, final String[] args) throws FactoryException { if (!(factory instanceof CRSAuthorityFactory)) { return; } final CRSAuthorityFactory factory = (CRSAuthorityFactory) this.factory; final CoordinateOperationFactory opFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(HINTS); char[] separator = null; for (int i = 0; i < args.length; i++) { final CoordinateReferenceSystem crs1 = factory.createCoordinateReferenceSystem(args[i]); for (int j = i + 1; j < args.length; j++) { final CoordinateReferenceSystem crs2 = factory.createCoordinateReferenceSystem(args[j]); final CoordinateOperation op; try { op = opFactory.createOperation(crs1, crs2); } catch (OperationNotFoundException exception) { out.println(exception.getLocalizedMessage()); continue; } if (separator == null) { separator = getSeparator(); } else { out.println(separator); } out.println(formatter.format(op.getMathTransform())); } } }
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); }
/** Setup the factories using the hints provided by {@link #getHintsForTesting}. */ @Before public final void setUpFactories() { Hints hints = getHintsForTesting(); datumFactory = ReferencingFactoryFinder.getDatumFactory(hints); crsFactory = ReferencingFactoryFinder.getCRSFactory(hints); mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); opFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints); }
/** * Make sure that a factory can be find in the presence of some global hints. * * @see http://jira.codehaus.org/browse/GEOT-1618 */ @Test public void testFactoryWithHints() { final Hints hints = new Hints(); hints.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); hints.put(Hints.FORCE_STANDARD_AXIS_DIRECTIONS, Boolean.TRUE); hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.TRUE); final CoordinateOperationFactory factory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints); assertSame(opFactory, factory); }
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); }
final CoordinateOperation operation; final CoordinateOperationFactory factory; factory = ReferencingFactoryFinder.getCoordinateOperationFactory(LENIENT); try { operation = factory.createOperation(crs, standardCRS);
/** 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); }
t = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform();
ReferencingFactoryFinder.getCoordinateOperationFactory(hints); assertNotSame(opFactory, lenientFactory); operation = lenientFactory.createOperation(sourceCRS, targetCRS);
/** Tests the transformation of a single coordinate. */ @Test public void testTransformCoordinate() throws FactoryException, TransformException { Coordinate coord = new Coordinate(10, 10); AffineTransform at = AffineTransform.getScaleInstance(0.5, 1); MathTransform2D t = (MathTransform2D) ReferencingFactoryFinder.getMathTransformFactory(null) .createAffineTransform(new GeneralMatrix(at)); coord = JTS.transform(coord, coord, t); assertEquals(new Coordinate(5, 10), coord); coord = JTS.transform(coord, coord, t.inverse()); assertEquals(new Coordinate(10, 10), coord); CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(UTM_ZONE_10N); t = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform(); coord = new Coordinate(-123, 55); coord = JTS.transform(coord, coord, t); coord = JTS.transform(coord, coord, t.inverse()); assertEquals(-123, coord.x, EPS); assertEquals(55, coord.y, EPS); }
t = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform();