Class DefinitionVerifier

java.lang.Object
org.apache.sis.internal.referencing.DefinitionVerifier

public final class DefinitionVerifier extends Object
Verifies the conformance of a given CRS with an authoritative description. For example if a Well Known Text (WKT) contains an EPSG code, this class verifies that the CRS created from the WKT is equivalent to the CRS identified by the authority code. DefinitionVerifier contains two information:
  • The recommended CRS to use. May be the given CRS or a CRS created from the authority factory.
  • Warnings if the given CRS does not match the authoritative description.
Note: ISO 19162 said about the Identifier keyword: "In the event of conflict in values given in the CRS WKT string and given by an authority through an object’s name or an identifier, reading software should throw an exception or give users a warning message. The WKT values should be assumed to prevail." In practice when such conflicts happen, we often see that the given WKT string contains mistakes and the provider intended to use the authoritative description. We nevertheless comply with ISO 19162 requirement, but provide a "recommended CRS" field for what we think is the intended CRS.
Since:
0.8
Version:
1.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Object[]
    The arguments to use together with resourceKey for producing the warning message.
    private static final int
    Indicates in which part of CRS description a difference has been found.
    private static final int
    Indicates in which part of CRS description a difference has been found.
    private static final int
    Indicates in which part of CRS description a difference has been found.
    private final Locale
    The locale for warning messages, or null for the system default.
    private static final int
    Indicates in which part of CRS description a difference has been found.
    private static final int
    Indicates in which part of CRS description a difference has been found.
    private static final int
    Indicates in which part of CRS description a difference has been found.
    final org.opengis.referencing.crs.CoordinateReferenceSystem
    Recommended CRS.
    private short
    If withAuthority(…) produced a localizable warning, the resource key for creating the actual message.
    private static final AxesConvention[]
    List of CRS variants to try if the given CRS does not match the expected description.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    DefinitionVerifier(org.opengis.referencing.crs.CoordinateReferenceSystem recommendation, Locale locale)
    Creates the result of a call to withAuthority(…).
  • Method Summary

    Modifier and Type
    Method
    Description
    private static DefinitionVerifier
    compare(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CoordinateReferenceSystem authoritative, boolean strictAxisOrder, boolean nullIfNoMatch, Locale locale)
    Implementation of #compare(CoordinateReferenceSystem, CoordinateReferenceSystem) and final step in forAuthority(…) methods.
    compare(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CoordinateReferenceSystem authoritative, Locale locale)
    Compares the given CRS with an authoritative definition of that CRS.
    private static int
    diffCode(Iterator<org.opengis.referencing.crs.SingleCRS> authoritative, Iterator<org.opengis.referencing.crs.SingleCRS> given)
    Returns a code indicating in which part the two given CRS differ.
    warning(boolean fine)
    Returns the warning to log, or null if none.
    static void
    withAuthority(org.opengis.referencing.crs.CoordinateReferenceSystem crs, String logger, Class<?> classe, String method)
    Compares the given CRS description with the authoritative description.
    withAuthority(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CRSAuthorityFactory factory, boolean lookup, Locale locale)
    Compares the given CRS description with the authoritative description.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • VARIANTS

      private static final AxesConvention[] VARIANTS
      List of CRS variants to try if the given CRS does not match the expected description. For performance reason, this list should be ordered with most probable variant first and less probable variant last.
    • recommendation

      public final org.opengis.referencing.crs.CoordinateReferenceSystem recommendation
      Recommended CRS. May be the instance given to the withAuthority(…) method or an instance created from the authority factory. May also be null if all CRS given to the compare(…) method were null. Note that ISO 19162 said "Should any attributes or values given in the cited identifier be in conflict with attributes or values given explicitly in the WKT description, the WKT values shall prevail." So we normally do not use this field.
    • resourceKey

      private short resourceKey
      If withAuthority(…) produced a localizable warning, the resource key for creating the actual message. A value of 0 means that the warning is already localized and stored in arguments[0].
    • arguments

      private Object[] arguments
      The arguments to use together with resourceKey for producing the warning message.
    • locale

      private final Locale locale
      The locale for warning messages, or null for the system default.
    • METHOD

      private static final int METHOD
      Indicates in which part of CRS description a difference has been found. Numerical values must match the number in the {choice} instruction in the message associated to Resources.Keys.NonConformCRS_3.
      See Also:
    • CONVERSION

      private static final int CONVERSION
      Indicates in which part of CRS description a difference has been found. Numerical values must match the number in the {choice} instruction in the message associated to Resources.Keys.NonConformCRS_3.
      See Also:
    • CS

      private static final int CS
      Indicates in which part of CRS description a difference has been found. Numerical values must match the number in the {choice} instruction in the message associated to Resources.Keys.NonConformCRS_3.
      See Also:
    • DATUM

      private static final int DATUM
      Indicates in which part of CRS description a difference has been found. Numerical values must match the number in the {choice} instruction in the message associated to Resources.Keys.NonConformCRS_3.
      See Also:
    • PRIME_MERIDIAN

      private static final int PRIME_MERIDIAN
      Indicates in which part of CRS description a difference has been found. Numerical values must match the number in the {choice} instruction in the message associated to Resources.Keys.NonConformCRS_3.
      See Also:
    • OTHER

      private static final int OTHER
      Indicates in which part of CRS description a difference has been found. Numerical values must match the number in the {choice} instruction in the message associated to Resources.Keys.NonConformCRS_3.
      See Also:
  • Constructor Details

    • DefinitionVerifier

      private DefinitionVerifier(org.opengis.referencing.crs.CoordinateReferenceSystem recommendation, Locale locale)
      Creates the result of a call to withAuthority(…).
  • Method Details

    • withAuthority

      public static void withAuthority(org.opengis.referencing.crs.CoordinateReferenceSystem crs, String logger, Class<?> classe, String method) throws org.opengis.util.FactoryException
      Compares the given CRS description with the authoritative description. If the comparison produces a warning, a message will be recorded to the given logger.
      Parameters:
      crs - the CRS to compare with the authoritative description.
      logger - the logger where to report warnings, if any.
      classe - the class to declare as the source of the warning.
      method - the method to declare as the source of the warning.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while querying the authority factory.
    • withAuthority

      public static DefinitionVerifier withAuthority(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CRSAuthorityFactory factory, boolean lookup, Locale locale) throws org.opengis.util.FactoryException
      Compares the given CRS description with the authoritative description. The authoritative description is inferred from the identifier, if any.
      Parameters:
      crs - the CRS to compare with the authoritative description.
      factory - the factory to use for fetching authoritative description, or null for the default.
      lookup - whether this method is allowed to use IdentifiedObjectFinder.
      locale - the locale for warning messages, or null for the system default.
      Returns:
      verification result, or null if the given CRS should be used as-is.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while querying the authority factory.
    • compare

      public static DefinitionVerifier compare(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CoordinateReferenceSystem authoritative, Locale locale)
      Compares the given CRS with an authoritative definition of that CRS. Typically, crs is parsed from a Well-Known Text (WKT) definition while authoritative is provided by a geodetic database from an authority code.

      The recommendation CRS is set as below:

      • If one of given CRS is null, then the other CRS (which may also be null) is selected.
      • Otherwise if crs is compatible with authority with only a change in axis order, a CRS derived from authority but with crs axis order is silently selected.
      • Otherwise authority is selected and a warning message is prepared.
      Parameters:
      crs - the CRS to compare against an authoritative definition, or null.
      authoritative - the presumed authoritative definition of the given CRS, or null.
      locale - the locale for warning messages, or null for the system default.
      Returns:
      verification result (never null).
    • compare

      private static DefinitionVerifier compare(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CoordinateReferenceSystem authoritative, boolean strictAxisOrder, boolean nullIfNoMatch, Locale locale)
      Implementation of #compare(CoordinateReferenceSystem, CoordinateReferenceSystem) and final step in forAuthority(…) methods. The boolean flags control the behavior in case of mismatched axis order or full mismatch.
      Parameters:
      strictAxisOrder - whether the CRS should comply with authoritative axis order. If true, mismatched axis order will be reported as a warning. If false, they will be silently ignored.
      nullIfNoMatch - whether to return null if CRS do not match. If false, then this method never return null.
      Returns:
      verification result, possibly null if nullIfNoMatch is true.
    • diffCode

      private static int diffCode(Iterator<org.opengis.referencing.crs.SingleCRS> authoritative, Iterator<org.opengis.referencing.crs.SingleCRS> given)
      Returns a code indicating in which part the two given CRS differ. The given iterators usually iterate over exactly one element, but may iterate over more elements if the CRS were instance of CompoundCRS. The returned value is one of METHOD, CONVERSION, CS, DATUM, PRIME_MERIDIAN or OTHER constants.
    • warning

      public LogRecord warning(boolean fine)
      Returns the warning to log, or null if none. The caller is responsible for setting the logger name, source class name and source method name.
      Parameters:
      fine - true for including warnings at fine level, or false for only the warning level.
      Returns:
      the warning to log, or null if none.