/** * Returns the datum of the specified CRS, or {@code null} if none. * * @param crs The coordinate reference system for which to get the datum. May be {@code null}. * @return The datum in the given CRS, or {@code null} if none. */ public static Datum getDatum(final CoordinateReferenceSystem crs) { return (crs instanceof SingleCRS) ? ((SingleCRS) crs).getDatum() : null; }
/** * Constructs a new coordinate reference system with the same values than the specified one. * This copy constructor provides a way to wrap an arbitrary implementation into a Geotools one * or a user-defined one (as a subclass), usually in order to leverage some * implementation-specific API. This constructor performs a shallow copy, i.e. the properties * are not cloned. * * @param crs The coordinate reference system to copy. * @since 2.2 */ public AbstractSingleCRS(final SingleCRS crs) { super(crs); datum = crs.getDatum(); }
/** * Work around for RFE #4093999 in Sun's bug database ("Relax constraint on placement of * this()/super() call in constructors"). * * @todo What to do if {@code base} is not an instance of {@link SingleCRS}? */ private static Datum getDatum(final CoordinateReferenceSystem base) { ensureNonNull("base", base); return (base instanceof SingleCRS) ? ((SingleCRS) base).getDatum() : null; }
final List<SingleCRS> sourceCRS, final SingleCRS targetCRS) { final boolean targetGeodetic; final Datum targetDatum = targetCRS.getDatum(); if (targetDatum instanceof GeodeticDatum) { targetGeodetic = true; boolean shift = false; for (final SingleCRS crs : sourceCRS) { final Datum sourceDatum = crs.getDatum(); final boolean sourceGeodetic; if (sourceDatum instanceof GeodeticDatum) {
where = "SOURCE_GEOGCRS_CODE"; } else if (object instanceof SingleCRS) { dependency = ((SingleCRS) object).getDatum(); where = "DATUM_CODE"; } else if (object instanceof GeodeticDatum) {
where = "SOURCE_GEOGCRS_CODE"; } else if (object instanceof SingleCRS) { dependency = ((SingleCRS) object).getDatum(); where = "DATUM_CODE"; } else if (object instanceof GeodeticDatum) {
/** * Creates a new identifier with the same values than the given identifier, * and store the given horizontal component for information purpose. * * @param identifier The identifier to copy. * @param horizontalCRS The horizontal component of the 3D CRS. */ private Identifier3D(final Identifier identifier, final SingleCRS horizontalCRS) { super(identifier); this.horizontalCRS = horizontalCRS; assert horizontalCRS.getDatum() instanceof GeodeticDatum : horizontalCRS; }
/** * Returns the datum, or {@code null} if none. * * This property does not exist in {@code CoordinateReferenceSystem} interface — it is defined in the * {@link SingleCRS} sub-interface instead. But Apache SIS does not define an {@code AbstractSingleCRS} class * in order to simplify our class hierarchy, so we provide a datum getter in this class has a hidden property. * Subclasses implementing {@code SingleCRS} (basically all SIS subclasses except {@link DefaultCompoundCRS}) * will override this method with public access and more specific return type. * * @return the datum, or {@code null} if none. */ Datum getDatum() { /* * User could provide his own CRS implementation outside this SIS package, so we have * to check for SingleCRS interface. But all SIS classes override this implementation. */ return (this instanceof SingleCRS) ? ((SingleCRS) this).getDatum() : null; }
/** * Returns the datum, or {@code null} if none. * * This property does not exist in {@code CoordinateReferenceSystem} interface — it is defined in the * {@link SingleCRS} sub-interface instead. But Apache SIS does not define an {@code AbstractSingleCRS} class * in order to simplify our class hierarchy, so we provide a datum getter in this class has a hidden property. * Subclasses implementing {@code SingleCRS} (basically all SIS subclasses except {@link DefaultCompoundCRS}) * will override this method with public access and more specific return type. * * @return the datum, or {@code null} if none. */ Datum getDatum() { /* * User could provide his own CRS implementation outside this SIS package, so we have * to check for SingleCRS interface. But all SIS classes override this implementation. */ return (this instanceof SingleCRS) ? ((SingleCRS) this).getDatum() : null; }
return DefaultGeographicCRS.WGS84; final Datum datum = ((SingleCRS) crs).getDatum(); if (!(datum instanceof GeodeticDatum)) { return DefaultGeographicCRS.WGS84;
/** * Returns the datum of the {@linkplain #getBaseCRS() base CRS}. * * @return the datum of the base CRS. */ @Override public Datum getDatum() { return getBaseCRS().getDatum(); }
/** * Returns the datum of the {@linkplain #getBaseCRS() base CRS}. * * @return the datum of the base CRS. */ @Override public Datum getDatum() { return getBaseCRS().getDatum(); }
/** * Ensures that the {@code actual} CRS uses a datum which is equals, ignoring metadata, * to the datum of the {@code expected} CRS. * * @param param the parameter name, used only in case of error. * @param expected the CRS containing the expected datum, or {@code null}. * @param actual the CRS for which to check the datum, or {@code null}. * @throws MismatchedDatumException if the two CRS use different datum. */ private static void ensureCompatibleDatum(final String param, final CoordinateReferenceSystem expected, final CoordinateReferenceSystem actual) { if ((expected instanceof SingleCRS) && (actual instanceof SingleCRS)) { final Datum datum = ((SingleCRS) expected).getDatum(); if (datum != null && !Utilities.equalsIgnoreMetadata(datum, ((SingleCRS) actual).getDatum())) { throw new MismatchedDatumException(Resources.format( Resources.Keys.IncompatibleDatum_2, datum.getName(), param)); } } }
/** * Ensures that the {@code actual} CRS uses a datum which is equals, ignoring metadata, * to the datum of the {@code expected} CRS. * * @param param the parameter name, used only in case of error. * @param expected the CRS containing the expected datum, or {@code null}. * @param actual the CRS for which to check the datum, or {@code null}. * @throws MismatchedDatumException if the two CRS use different datum. */ private static void ensureCompatibleDatum(final String param, final CoordinateReferenceSystem expected, final CoordinateReferenceSystem actual) { if ((expected instanceof SingleCRS) && (actual instanceof SingleCRS)) { final Datum datum = ((SingleCRS) expected).getDatum(); if (datum != null && !Utilities.equalsIgnoreMetadata(datum, ((SingleCRS) actual).getDatum())) { throw new MismatchedDatumException(Resources.format( Resources.Keys.IncompatibleDatum_2, datum.getName(), param)); } } }
final Datum oldDatum, datum; if (crs instanceof SingleCRS) { oldDatum = ((SingleCRS) crs).getDatum(); datum = replace(oldDatum); } else {
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * <div class="note"><b>Note:</b> * the unmarshalled CRS may be of {@code GeodeticCRS} type, which is not the most specific GeoAPI type. * But the {@code GeographicCRS} and {@code GeocentricCRS} sub-types are currently not part of ISO 19111. * We could substitute the CRS by a more specific type here, but this would break the references specified * by {@code xlink:href} attributes. For now we live with the {@code GeodeticCRS} as-is — most of Apache SIS * should be able to work with that.</div> * * @param crs the unmarshalled element. */ public void setElement(final AbstractCRS crs) { metadata = crs; if (crs.getCoordinateSystem() == null) { incomplete((crs instanceof CompoundCRS) ? "componentReferenceSystem" : "coordinateSystem"); } if (crs instanceof SingleCRS && ((SingleCRS) crs).getDatum() == null) { incomplete("datum"); } } }
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * <div class="note"><b>Note:</b> * the unmarshalled CRS may be of {@code GeodeticCRS} type, which is not the most specific GeoAPI type. * But the {@code GeographicCRS} and {@code GeocentricCRS} sub-types are currently not part of ISO 19111. * We could substitute the CRS by a more specific type here, but this would break the references specified * by {@code xlink:href} attributes. For now we live with the {@code GeodeticCRS} as-is — most of Apache SIS * should be able to work with that.</div> * * @param crs the unmarshalled element. */ public void setElement(final AbstractCRS crs) { metadata = crs; if (crs.getCoordinateSystem() == null) { incomplete((crs instanceof CompoundCRS) ? "componentReferenceSystem" : "coordinateSystem"); } if (crs instanceof SingleCRS && ((SingleCRS) crs).getDatum() == null) { incomplete("datum"); } } }
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * <div class="note"><b>Note:</b> * the unmarshalled CRS may be of {@code GeodeticCRS} type, which is not the most specific GeoAPI type. * See {@link SC_CRS#setElement(AbstractCRS)} for more discussion.</div> * * @param crs the unmarshalled element. * @throws IllegalArgumentException if the unmarshalled CRS is not a single CRS. */ public void setElement(final AbstractCRS crs) { if (!(crs instanceof SingleCRS)) { throw new IllegalArgumentException(Errors.format(Errors.Keys.UnexpectedValueInElement_2, "baseCRS", IdentifiedObjects.getName(crs, null))); } metadata = (SingleCRS) crs; if (crs.getCoordinateSystem() == null) incomplete("coordinateSystem"); if (((SingleCRS) crs).getDatum() == null) incomplete("datum"); } }
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * <div class="note"><b>Note:</b> * the unmarshalled CRS may be of {@code GeodeticCRS} type, which is not the most specific GeoAPI type. * See {@link SC_CRS#setElement(AbstractCRS)} for more discussion.</div> * * @param crs the unmarshalled element. * @throws IllegalArgumentException if the unmarshalled CRS is not a single CRS. */ public void setElement(final AbstractCRS crs) { if (!(crs instanceof SingleCRS)) { throw new IllegalArgumentException(Errors.format(Errors.Keys.UnexpectedValueInElement_2, "baseCRS", IdentifiedObjects.getName(crs, null))); } metadata = (SingleCRS) crs; if (crs.getCoordinateSystem() == null) incomplete("coordinateSystem"); if (((SingleCRS) crs).getDatum() == null) incomplete("datum"); } }
/** * If the given CRS is two-dimensional, append an ellipsoidal height to it. * It is caller's responsibility to ensure that the given CRS is geographic. */ private CoordinateReferenceSystem toGeodetic3D(CoordinateReferenceSystem crs, final CoordinateReferenceSystem candidate) throws FactoryException { assert (crs instanceof GeodeticCRS) && (crs.getCoordinateSystem() instanceof EllipsoidalCS) : crs; if (crs.getCoordinateSystem().getDimension() != 2) { return crs; } /* * The check for same class is a cheap way to ensure that the two CRS implement the same GeoAPI interface. * This test is stricter than necessary, but the result should still not wrong if we miss an opportunity * to return the existing instance. */ if (crs.getClass() == candidate.getClass() && candidate.getCoordinateSystem().getDimension() == 3) { if (Utilities.equalsIgnoreMetadata(((SingleCRS) crs).getDatum(), ((SingleCRS) candidate).getDatum())) { return candidate; // Keep the existing instance since it may contain useful metadata. } } return toAuthorityDefinition(CoordinateReferenceSystem.class, new CompoundCRSBuilder(factory, factorySIS).createCompoundCRS(derivedFrom(crs), crs, CommonCRS.Vertical.ELLIPSOIDAL.crs())); }