Class DefinitionVerifier
java.lang.Object
org.apache.sis.internal.referencing.DefinitionVerifier
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.
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
FieldsModifier and TypeFieldDescriptionprivate Object[]
The arguments to use together withresourceKey
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, ornull
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
IfwithAuthority(…)
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
ConstructorsModifierConstructorDescriptionprivate
DefinitionVerifier
(org.opengis.referencing.crs.CoordinateReferenceSystem recommendation, Locale locale) Creates the result of a call towithAuthority(…)
. -
Method Summary
Modifier and TypeMethodDescriptionprivate static DefinitionVerifier
compare
(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CoordinateReferenceSystem authoritative, boolean strictAxisOrder, boolean nullIfNoMatch, Locale locale) Implementation ofinvalid reference
#compare(CoordinateReferenceSystem, CoordinateReferenceSystem)
forAuthority(…)
methods.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.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, ornull
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.static DefinitionVerifier
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.
-
Field Details
-
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 recommendationRecommended CRS. May be the instance given to thewithAuthority(…)
method or an instance created from the authority factory. May also benull
if all CRS given to theinvalid reference
compare(…)
-
resourceKey
private short resourceKeyIfwithAuthority(…)
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 inarguments[0]
. -
arguments
The arguments to use together withresourceKey
for producing the warning message. -
locale
The locale for warning messages, ornull
for the system default. -
METHOD
private static final int METHODIndicates 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 toResources.Keys.NonConformCRS_3
.- See Also:
-
CONVERSION
private static final int CONVERSIONIndicates 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 toResources.Keys.NonConformCRS_3
.- See Also:
-
CS
private static final int CSIndicates 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 toResources.Keys.NonConformCRS_3
.- See Also:
-
DATUM
private static final int DATUMIndicates 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 toResources.Keys.NonConformCRS_3
.- See Also:
-
PRIME_MERIDIAN
private static final int PRIME_MERIDIANIndicates 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 toResources.Keys.NonConformCRS_3
.- See Also:
-
OTHER
private static final int OTHERIndicates 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 toResources.Keys.NonConformCRS_3
.- See Also:
-
-
Constructor Details
-
DefinitionVerifier
private DefinitionVerifier(org.opengis.referencing.crs.CoordinateReferenceSystem recommendation, Locale locale) Creates the result of a call towithAuthority(…)
.
-
-
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, ornull
for the default.lookup
- whether this method is allowed to useIdentifiedObjectFinder
.locale
- the locale for warning messages, ornull
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 whileauthoritative
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 withauthority
with only a change in axis order, a CRS derived fromauthority
but withcrs
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, ornull
.authoritative
- the presumed authoritative definition of the given CRS, ornull
.locale
- the locale for warning messages, ornull
for the system default.- Returns:
- verification result (never
null
).
- If one of given CRS is
-
compare
private static DefinitionVerifier compare(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.referencing.crs.CoordinateReferenceSystem authoritative, boolean strictAxisOrder, boolean nullIfNoMatch, Locale locale) Implementation ofinvalid reference
#compare(CoordinateReferenceSystem, CoordinateReferenceSystem)
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. Iftrue
, mismatched axis order will be reported as a warning. Iffalse
, they will be silently ignored.nullIfNoMatch
- whether to returnnull
if CRS do not match. Iffalse
, then this method never returnnull
.- Returns:
- verification result, possibly
null
ifnullIfNoMatch
istrue
.
-
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 ofCompoundCRS
. The returned value is one ofMETHOD
,CONVERSION
,CS
,DATUM
,PRIME_MERIDIAN
orOTHER
constants. -
warning
Returns the warning to log, ornull
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, orfalse
for only the warning level.- Returns:
- the warning to log, or
null
if none.
-