org.opengis.referencing.operation.CoordinateOperationFactory Java Examples
The following examples show how to use
org.opengis.referencing.operation.CoordinateOperationFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractUTMCrsProvider.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
CoordinateReferenceSystem createCrs(String crsName, OperationMethod method, ParameterValueGroup parameters, GeodeticDatum datum) throws FactoryException { final CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null); final CoordinateOperationFactory coFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(null); final HashMap<String, Object> projProperties = new HashMap<String, Object>(); projProperties.put("name", crsName + " / " + datum.getName().getCode()); final Conversion conversion = coFactory.createDefiningConversion(projProperties, method, parameters); final HashMap<String, Object> baseCrsProperties = new HashMap<String, Object>(); baseCrsProperties.put("name", datum.getName().getCode()); final GeographicCRS baseCrs = crsFactory.createGeographicCRS(baseCrsProperties, datum, DefaultEllipsoidalCS.GEODETIC_2D); return crsFactory.createProjectedCRS(projProperties, baseCrs, conversion, DefaultCartesianCS.PROJECTED); }
Example #2
Source File: MTFactory.java From sis with Apache License 2.0 | 6 votes |
/** * Parses the given Well Known Text (version 1) into a math transform. */ @Override public synchronized MathTransform createFromWKT(final String wkt) throws FactoryException { ArgumentChecks.ensureNonEmpty("wkt", wkt); if (parser == null) { parser = new WKTFormat(null, null); parser.setFactory(CRSAuthorityFactory.class, this); parser.setFactory(MathTransformFactory.class, this); parser.setFactory(CoordinateOperationFactory.class, this); } try { return (MathTransform) parser.parseObject(wkt); } catch (ParseException | ClassCastException e) { throw new FactoryException(e); } }
Example #3
Source File: CoordinateOperations.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the coordinate operation factory to use for the given properties and math transform factory. * If the given properties are empty and the {@code mtFactory} is the system default, then this method * returns the system default {@code CoordinateOperationFactory} instead of creating a new one. * * <p>It is okay to set all parameters to {@code null} in order to get the system default factory.</p> * * @param properties the default properties. * @param mtFactory the math transform factory to use. * @param crsFactory the factory to use if the operation factory needs to create CRS for intermediate steps. * @param csFactory the factory to use if the operation factory needs to create CS for intermediate steps. * @return the coordinate operation factory to use. */ public static CoordinateOperationFactory getCoordinateOperationFactory(Map<String,?> properties, final MathTransformFactory mtFactory, final CRSFactory crsFactory, final CSFactory csFactory) { if (Containers.isNullOrEmpty(properties)) { if (DefaultFactories.isDefaultInstance(MathTransformFactory.class, mtFactory) && DefaultFactories.isDefaultInstance(CRSFactory.class, crsFactory) && DefaultFactories.isDefaultInstance(CSFactory.class, csFactory)) { return CoordinateOperations.factory(); } properties = Collections.emptyMap(); } final HashMap<String,Object> p = new HashMap<>(properties); p.putIfAbsent(ReferencingFactoryContainer.CRS_FACTORY, crsFactory); p.putIfAbsent(ReferencingFactoryContainer.CS_FACTORY, csFactory); properties = p; return new DefaultCoordinateOperationFactory(properties, mtFactory); }
Example #4
Source File: ReferencingServices.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the default coordinate operation factory. * * @return the coordinate operation factory to use. */ public CoordinateOperationFactory getCoordinateOperationFactory() { final CoordinateOperationFactory factory = DefaultFactories.forClass(CoordinateOperationFactory.class); if (factory != null) { return factory; } else { throw moduleNotFound(); } }
Example #5
Source File: ReferencingFactoryContainer.java From sis with Apache License 2.0 | 5 votes |
/** * Creates a new instance which will use the given factories. * Any factory given in argument may be {@code null} if lazy instantiation is desired. * * @param defaultProperties default properties to give to the objects to create (will not be cloned). * @param crsFactory the factory to use for creating coordinate reference systems. * @param csFactory the factory to use for creating coordinate systems. * @param datumFactory the factory to use for creating datum. * @param operationFactory the factory to use for creating (defining) conversions. * @param mtFactory the factory to use for creating transform objects. */ public ReferencingFactoryContainer(final Map<String,?> defaultProperties, final CRSFactory crsFactory, final CSFactory csFactory, final DatumFactory datumFactory, final CoordinateOperationFactory operationFactory, final MathTransformFactory mtFactory) { this.defaultProperties = defaultProperties; this.crsFactory = crsFactory; this.csFactory = csFactory; this.datumFactory = datumFactory; this.operationFactory = (DefaultCoordinateOperationFactory) operationFactory; // Because of GeoAPI 3.0 limitation. this.mtFactory = mtFactory; }
Example #6
Source File: ReferencingFactoryContainer.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the factory for fetching operation methods and creating defining conversions. * This is needed only for user-defined projected coordinate reference system. * The factory is fetched when first needed. * * @return the Coordinate Operation factory (never {@code null}). */ public final DefaultCoordinateOperationFactory getCoordinateOperationFactory() { if (operationFactory == null) { CoordinateOperationFactory op = CoordinateOperations.getCoordinateOperationFactory(defaultProperties, mtFactory, crsFactory, csFactory); defaultProperties = null; // Not needed anymore. if (op instanceof DefaultCoordinateOperationFactory) { operationFactory = (DefaultCoordinateOperationFactory) op; } else { operationFactory = CoordinateOperations.factory(); } } return operationFactory; }
Example #7
Source File: CoordinateOperations.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the factory. * * @return the system-wide factory. */ public static DefaultCoordinateOperationFactory factory() { DefaultCoordinateOperationFactory c = factory; if (c == null) { // DefaultFactories.forBuildin(…) performs the necessary synchronization. factory = c = DefaultFactories.forBuildin(CoordinateOperationFactory.class, DefaultCoordinateOperationFactory.class); } return c; }
Example #8
Source File: WKTFormat.java From sis with Apache License 2.0 | 5 votes |
/** * Verifies if the given type is a valid key for the {@link #factories} map. */ private void ensureValidFactoryType(final Class<?> type) throws IllegalArgumentException { ArgumentChecks.ensureNonNull("type", type); if (type != CRSFactory.class && type != CSFactory.class && type != DatumFactory.class && type != MathTransformFactory.class && type != CoordinateOperationFactory.class) { throw new IllegalArgumentException(Errors.getResources(getLocale()) .getString(Errors.Keys.IllegalArgumentValue_2, "type", type)); } }
Example #9
Source File: Proj4ParserTest.java From sis with Apache License 2.0 | 4 votes |
/** * Creates a new test. */ public Proj4ParserTest() { opFactory = DefaultFactories.forBuildin(CoordinateOperationFactory.class, DefaultCoordinateOperationFactory.class); }
Example #10
Source File: ServicesForMetadata.java From sis with Apache License 2.0 | 4 votes |
/** * Implementation of the public {@code setBounds(…, DefaultGeographicBoundingBox, …)} methods for * the horizontal extent. If the {@code crs} argument is null, then it is caller's responsibility * to ensure that the given envelope is two-dimensional. * * <p>If {@code findOpCaller} is non-null, then this method will be executed in optional mode: * some failures will cause this method to return {@code null} instead than throwing an exception. * Note that {@link TransformException} may still be thrown but not directly by this method. * Warning may be logged, but in such case this method presumes that public caller is the named * method from {@link Envelopes} — typically {@link Envelopes#findOperation(Envelope, Envelope)}.</p> * * @param envelope the source envelope. * @param target the target bounding box, or {@code null} for creating it automatically. * @param crs the envelope CRS, or {@code null} if unknown. * @param normalizedCRS the horizontal component of the given CRS, or null if the {@code crs} argument is null. * @param findOpCaller non-null for replacing some (not all) exceptions by {@code null} return value. * @return the bounding box or {@code null} on failure. Never {@code null} if {@code findOpCaller} argument is {@code null}. * @throws TransformException if the given envelope can not be transformed. */ private static DefaultGeographicBoundingBox setGeographicExtent(Envelope envelope, DefaultGeographicBoundingBox target, final CoordinateReferenceSystem crs, final GeographicCRS normalizedCRS, final String findOpCaller) throws TransformException { if (normalizedCRS != null) { // No need to check for dimension, since GeodeticCRS can not have less than 2. final CoordinateSystem cs1 = crs.getCoordinateSystem(); final CoordinateSystem cs2 = normalizedCRS.getCoordinateSystem(); if (!Utilities.equalsIgnoreMetadata(cs2.getAxis(0), cs1.getAxis(0)) || !Utilities.equalsIgnoreMetadata(cs2.getAxis(1), cs1.getAxis(1))) { final CoordinateOperation operation; final CoordinateOperationFactory factory = CoordinateOperations.factory(); try { operation = factory.createOperation(crs, normalizedCRS); } catch (FactoryException e) { if (findOpCaller != null) { // See javadoc for the assumption that optional mode is used by Envelopes.findOperation(…). Logging.recoverableException(Logging.getLogger(Modules.REFERENCING), Envelopes.class, findOpCaller, e); return null; } throw new TransformException(Resources.format(Resources.Keys.CanNotTransformEnvelopeToGeodetic), e); } envelope = Envelopes.transform(operation, envelope); } } /* * At this point, the envelope should use (longitude, latitude) coordinates in degrees. * The envelope may cross the anti-meridian if the envelope implementation is an Apache SIS one. * For other implementations, the longitude range may be conservatively expanded to [-180 … 180]°. */ double westBoundLongitude, eastBoundLongitude; double southBoundLatitude, northBoundLatitude; if (envelope instanceof AbstractEnvelope) { final AbstractEnvelope ae = (AbstractEnvelope) envelope; westBoundLongitude = ae.getLower(0); eastBoundLongitude = ae.getUpper(0); // Cross anti-meridian if eastBoundLongitude < westBoundLongitude. southBoundLatitude = ae.getLower(1); northBoundLatitude = ae.getUpper(1); } else { westBoundLongitude = envelope.getMinimum(0); eastBoundLongitude = envelope.getMaximum(0); // Expanded to [-180 … 180]° if it was crossing the anti-meridian. southBoundLatitude = envelope.getMinimum(1); northBoundLatitude = envelope.getMaximum(1); } /* * The envelope transformation at the beginning of this method intentionally avoided to apply datum shift. * This implies that the prime meridian has not been changed and may be something else than Greenwich. * We need to take it in account manually. * * Note that there is no need to normalize the longitudes back to the [-180 … +180]° range after the rotation, or * to verify if the longitude span is 360°. Those verifications will be done automatically by target.setBounds(…). */ if (normalizedCRS != null) { final double rotation = CRS.getGreenwichLongitude(normalizedCRS); westBoundLongitude += rotation; eastBoundLongitude += rotation; } /* * In the particular case where this method is invoked (indirectly) for Envelopes.findOperation(…) purposes, * replace NaN values by the whole world. We do that only for Envelopes.findOperation(…) since we know that * the geographic bounding box will be used for choosing a CRS, and a conservative approach is to select the * CRS valid in the widest area. If this method is invoked for other usages, then we keep NaN values because * we don't know the context (union, intersection, something else?). */ if (findOpCaller != null) { if (Double.isNaN(southBoundLatitude)) southBoundLatitude = Latitude.MIN_VALUE; if (Double.isNaN(northBoundLatitude)) northBoundLatitude = Latitude.MAX_VALUE; if (Double.isNaN(eastBoundLongitude) || Double.isNaN(westBoundLongitude)) { // Conservatively set the two bounds because may be spanning the anti-meridian. eastBoundLongitude = Longitude.MIN_VALUE; westBoundLongitude = Longitude.MAX_VALUE; } } if (target == null) { target = new DefaultGeographicBoundingBox(); } target.setBounds(westBoundLongitude, eastBoundLongitude, southBoundLatitude, northBoundLatitude); target.setInclusion(Boolean.TRUE); return target; }
Example #11
Source File: PositionTransformer.java From sis with Apache License 2.0 | 3 votes |
/** * Creates a new position which will contain the result of coordinate transformations to the given CRS. * The {@linkplain #getCoordinateReferenceSystem() CRS associated with this position} will be initially * set to {@code targetCRS}. * * @param defaultCRS the CRS to take as the source when <code>{@link #transform transform}(position)</code> * is invoked with a position without associated CRS. If {@code null}, default to {@code targetCRS}. * @param targetCRS the {@linkplain #getCoordinateReferenceSystem() CRS associated with this position}. Will be the target * of {@linkplain #transform coordinate transformations} until the next call to {@link #setCoordinateReferenceSystem * setCoordinateReferenceSystem(…)} or {@link #setLocation(DirectPosition) setLocation}. Can not be null. * @param factory the factory to use for creating coordinate operations, or {@code null} for the default. */ public PositionTransformer(final CoordinateReferenceSystem defaultCRS, final CoordinateReferenceSystem targetCRS, final CoordinateOperationFactory factory) { super(targetCRS); ArgumentChecks.ensureNonNull("targetCRS", targetCRS); this.defaultCRS = (defaultCRS != null) ? defaultCRS : targetCRS; this.factory = (factory != null) ? factory : DefaultFactories.forBuildin(CoordinateOperationFactory.class); }
Example #12
Source File: ServicesForMetadata.java From sis with Apache License 2.0 | 3 votes |
/** * Returns the coordinate operation method for the given classification. * This method checks if the given {@code opFactory} is a SIS implementation * before to fallback on a slower fallback. * * <p>This method is actually not needed anymore for {@code sis-metadata} module, * but is still defined here for historical reason. This method is removed on SIS * branches using a GeoAPI versions more recent than 3.0.</p> * * @param opFactory The coordinate operation factory to use if it is a SIS implementation. * @param mtFactory The math transform factory to use as a fallback. * @param identifier The name or identifier of the operation method to search. * @return The coordinate operation method for the given name or identifier. * @throws FactoryException if an error occurred which searching for the given method. * * @since 0.6 */ public static OperationMethod getOperationMethod(final CoordinateOperationFactory opFactory, final MathTransformFactory mtFactory, final String identifier) throws FactoryException { if (opFactory instanceof DefaultCoordinateOperationFactory) { ((DefaultCoordinateOperationFactory) opFactory).getOperationMethod(identifier); } final OperationMethod method = getOperationMethod(mtFactory.getAvailableMethods(SingleOperation.class), identifier); if (method != null) { return method; } throw new NoSuchIdentifierException("No such operation method: " + identifier, identifier); }
Example #13
Source File: ReferencingFactoryContainer.java From sis with Apache License 2.0 | 3 votes |
/** * Sets one of the factories managed by this container. * The given {@code type} argument can be one of the following values: * * <ul> * <li><code>{@linkplain CRSFactory}.class</code></li> * <li><code>{@linkplain CSFactory}.class</code></li> * <li><code>{@linkplain DatumFactory}.class</code></li> * <li><code>{@linkplain CoordinateOperationFactory}.class</code></li> * <li><code>{@linkplain MathTransformFactory}.class</code></li> * </ul> * * Note that authority factories are not yet handled by this method * for consistency with {@link #getFactory(Class)}. * * @param <T> the compile-time type of the {@code type} argument. * @param type the factory type. * @param factory the factory to use for the given type, or {@code null} for the default. * @return {@code true} if the factory changed as a result of this method call. * @throws IllegalArgumentException if the {@code type} argument is not one of the valid values. */ public final <T extends Factory> boolean setFactory(final Class<T> type, final T factory) { if (type == CRSFactory.class) return crsFactory != (crsFactory = (CRSFactory) factory); if (type == CSFactory.class) return csFactory != (csFactory = (CSFactory) factory); if (type == DatumFactory.class) return datumFactory != (datumFactory = (DatumFactory) factory); if (type == CoordinateOperationFactory.class) return operationFactory != (operationFactory = (DefaultCoordinateOperationFactory) factory); if (type == MathTransformFactory.class) return mtFactory != (mtFactory = (MathTransformFactory) factory); throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "type", type)); }
Example #14
Source File: ReferencingFactoryContainer.java From sis with Apache License 2.0 | 3 votes |
/** * Returns one of the factories managed by this container. * The given {@code type} argument can be one of the following values: * * <ul> * <li><code>{@linkplain CRSFactory}.class</code></li> * <li><code>{@linkplain CSFactory}.class</code></li> * <li><code>{@linkplain DatumFactory}.class</code></li> * <li><code>{@linkplain CoordinateOperationFactory}.class</code></li> * <li><code>{@linkplain MathTransformFactory}.class</code></li> * </ul> * * Note that authority factories are not yet handled by this method, since we would have to expose * the current restriction to EPSG geodetic dataset and to handle {@link FactoryException}. * * @param <T> the compile-time type of the {@code type} argument. * @param type the factory type. * @return the factory for the given type. * @throws IllegalArgumentException if the {@code type} argument is not one of the valid values. */ public final <T extends Factory> T getFactory(final Class<T> type) { final Factory f; if (type == CRSFactory.class) f = getCRSFactory(); else if (type == CSFactory.class) f = getCSFactory(); else if (type == DatumFactory.class) f = getDatumFactory(); else if (type == CoordinateOperationFactory.class) f = getCoordinateOperationFactory(); else if (type == MathTransformFactory.class) f = getMathTransformFactory(); else { throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "type", type)); } return type.cast(f); }
Example #15
Source File: ServicesForMetadata.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the default coordinate operation factory. * * @return the coordinate operation factory to use. */ @Override public CoordinateOperationFactory getCoordinateOperationFactory() { return CoordinateOperations.factory(); }
Example #16
Source File: EllipsoidalHeightCombiner.java From sis with Apache License 2.0 | 2 votes |
/** * Creates a new combiner which will use the given factories. * Any factory given in argument may be {@code null} if lazy instantiation is desired. * * @param crsFactory the factory to use for creating compound or three-dimensional geographic CRS. * @param csFactory the factory to use for creating three-dimensional ellipsoidal CS, if needed. * @param opFactory the factory to use for creating defining conversions, if needed. */ public EllipsoidalHeightCombiner(final CRSFactory crsFactory, final CSFactory csFactory, final CoordinateOperationFactory opFactory) { factories = new ReferencingFactoryContainer(null, crsFactory, csFactory, null, opFactory, null); }