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
Author:
Martin Desruisseaux (Geomatys)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final org.opengis.referencing.crs.CoordinateReferenceSystem
    Recommended CRS.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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

    • 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
      invalid reference
      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.
  • 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).
    • 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.