Class CRSBuilder


final class CRSBuilder extends ReferencingFactoryContainer
Helper class for building a CoordinateReferenceSystem from information found in TIFF tags. GeoKeys are loaded by GeoKeysLoader and consumed by this class.
Since:
0.8
Version:
1.2
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) boolean
    true when an exception has been thrown but this CRSBuilder already reported a warning, so there is no need for the caller to report a warning again.
    org.opengis.metadata.spatial.CellGeometry
    POINT if GeoKeys.RasterType is GeoCodes.RasterPixelIsPoint, AREA if it is GeoCodes.RasterPixelIsArea, or null if unspecified.
    (package private) static final int
    Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian.
    Suggested value for a general description of the transformation form grid coordinates to "real world" coordinates.
    (package private) static final int
    Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian.
    (package private) static final int
    Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian.
    private final Map<Short,Object>
    All values found in the GeoKeyDirectory after the header.
    private org.opengis.metadata.Identifier
    Name of the last object created.
    private short
    Version of the set of keys declared in the GeoKeyDirectory header.
    private static final int
    Minimal length that a key in a name must have before we compare them to the NAME_KEYS.
    private short
    Version of the set of keys declared in the GeoKeyDirectory header.
    private final Set<String>
    Missing GeoKeys, used for avoiding to report the same warning twice.
    private static final String[]
    Keys that may be used in the value associated to GeoKeys.GeogCitation.
    private static final short[][]
    Map projection parameters to be considered as aliases.
    (package private) static final int
    Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian.
    private final Reader
    The reader for which we will create coordinate reference systems.

    Fields inherited from class org.apache.sis.internal.referencing.ReferencingFactoryContainer

    CRS_FACTORY, CS_FACTORY, DATUM_FACTORY, MT_FACTORY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new builder of coordinate reference systems.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    Updates a mapping from GeoTIFF numerical identifiers to parameter names by adding parameter aliases.
    org.opengis.referencing.crs.CoordinateReferenceSystem
    Decodes all the given GeoTIFF keys, then creates a coordinate reference system.
    private org.opengis.referencing.operation.Conversion
    createConversion(String name, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit)
    Creates a defining conversion from an EPSG code or from user-defined parameters.
    private org.opengis.referencing.datum.Ellipsoid
    createEllipsoid(String[] names, javax.measure.Unit<javax.measure.quantity.Length> unit)
    Creates an ellipsoid from an EPSG code or from user-defined parameters.
    private org.opengis.referencing.crs.GeocentricCRS
    Creates a geocentric CRS from user-defined parameters.
    private org.opengis.referencing.datum.GeodeticDatum
    createGeodeticDatum(String[] names, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit)
    Creates a geodetic datum from an EPSG code or from user-defined parameters.
    private org.opengis.referencing.crs.GeographicCRS
    Creates the main CRS in the case where that CRS is geographic.
    private org.opengis.referencing.crs.GeographicCRS
    createGeographicCRS(boolean rightHanded, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit)
    Creates a geographic CRS from an EPSG code or from user-defined parameters.
    private org.opengis.referencing.datum.PrimeMeridian
    createPrimeMeridian(String[] names, javax.measure.Unit<javax.measure.quantity.Angle> unit)
    Creates a prime meridian from an EPSG code or from user-defined parameters.
    private org.opengis.referencing.crs.ProjectedCRS
    Creates a projected CRS from an EPSG code or from user-defined parameters.
    private <Q extends javax.measure.Quantity<Q>>
    javax.measure.Unit<Q>
    createUnit(short codeKey, short scaleKey, Class<Q> quantity, javax.measure.Unit<Q> defaultValue)
    Creates units of measurement for projected or geographic coordinate reference systems.
    private org.opengis.referencing.crs.VerticalCRS
    Creates an optional vertical CRS, or returns null if no vertical CRS definition is found.
    private org.opengis.referencing.datum.VerticalDatum
    Creates a vertical datum.
    private double
    getAsDouble(short key)
    Removes and returns a GeoKeys value as a floating point number, or NaN if none.
    private int
    getAsInteger(short key)
    Removes and returns a GeoKeys value as an integer.
    private String
    getAsString(short key)
    Removes and returns a GeoKeys value as a character string, or null if none.
    private double
    getMandatoryDouble(short key)
    Removes and returns a GeoKeys value as a floating point number, or throws an exception if none.
    private String
    getMandatoryString(short key)
    Removes and returns a GeoKeys value as a character string, or throws an exception if none.
    private static String
    getOrDefault(String[] names, int component)
    Returns the name at the given index if non-null.
    private Object
    getSingleton(short key)
    Removes and returns the value for the given key as a singleton (not an array).
    private void
    invalidValue(short key, Object value)
    Reports a warning about an invalid value for the given key.
    (package private) final String
    missingValue(short key)
    Reports a warning about missing value for the given key.
    private Map<String,?>
    Returns a map with the given name associated to "name".
    private Short[]
    Returns all remaining keys, sorted in increasing order.
    private org.opengis.referencing.cs.EllipsoidalCS
    replaceAngularUnit(org.opengis.referencing.cs.EllipsoidalCS cs, javax.measure.Unit<javax.measure.quantity.Angle> unit)
    Returns a coordinate system (CS) with the same axis directions than the given CS but potentially different units.
    private org.opengis.referencing.cs.CartesianCS
    replaceLinearUnit(org.opengis.referencing.cs.CartesianCS cs, javax.measure.Unit<javax.measure.quantity.Length> unit)
    Returns a coordinate system (CS) with the same axis directions than the given CS but potentially different units.
    (package private) static String[]
    Splits the GeoKeys.GeogCitation value into its prime meridian, ellipsoid, datum and CRS name components.
    final String
    Returns a string representation of the keys and associated values in this CRSBuilder.
    private void
    verify(org.opengis.referencing.crs.GeocentricCRS crs)
    Verifies if the user-defined CRS created from GeoTIFF values matches the given CRS created from the EPSG geodetic dataset.
    private void
    verify(org.opengis.referencing.crs.GeographicCRS crs, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit)
    Verifies if the user-defined CRS created from GeoTIFF values matches the given CRS created from the EPSG geodetic dataset.
    private void
    verify(org.opengis.referencing.crs.ProjectedCRS crs)
    Verifies if the user-defined CRS created from GeoTIFF values matches the given CRS created from the EPSG geodetic dataset.
    private void
    verify(org.opengis.referencing.datum.Ellipsoid ellipsoid, javax.measure.Unit<javax.measure.quantity.Length> unit)
    Verifies if the user-defined ellipsoid created from GeoTIFF values matches the given ellipsoid created from the EPSG geodetic dataset.
    private void
    verify(org.opengis.referencing.datum.GeodeticDatum datum, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit)
    Verifies if the user-defined datum created from GeoTIFF values matches the given datum created from the EPSG geodetic dataset.
    private void
    verify(org.opengis.referencing.datum.PrimeMeridian pm, javax.measure.Unit<javax.measure.quantity.Angle> unit)
    Verifies if the user-defined prime meridian created from GeoTIFF values matches the given prime meridian created from the EPSG geodetic dataset.
    private void
    verify(org.opengis.referencing.IdentifiedObject epsg, double expected, short key, javax.measure.Unit<?> unit)
    Verifies that a value found in the GeoTIFF file is approximately equal to the expected value.
    private void
    verify(org.opengis.referencing.operation.Conversion projection, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit)
    Verifies if the user-defined conversion created from GeoTIFF values matches the given conversion created from the EPSG geodetic dataset.
    private void
    verifyIdentifier(org.opengis.referencing.IdentifiedObject parent, org.opengis.referencing.IdentifiedObject epsg, short key)
    Verifies that the EPSG code found in the GeoTIFF file is equal to the expected value.
    (package private) final void
    warning(short key, Object... args)
    Reports a warning with a message built from the given resource keys and arguments.

    Methods inherited from class java.lang.Object

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

    • PRIMEM

      static final int PRIMEM
      Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian. The GeoTIFF specification has only one key, GeoKeys.GeogCitation, for the geographic CRS and its components. But some GeoTIFF files encode the names of all components in the value associated to that key, as in the following example: In such case, we will split the name into the components names to be stored in an array at indices given by GCRS, DATUM, ELLIPSOID and PRIMEM.
      See Also:
    • ELLIPSOID

      static final int ELLIPSOID
      Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian. The GeoTIFF specification has only one key, GeoKeys.GeogCitation, for the geographic CRS and its components. But some GeoTIFF files encode the names of all components in the value associated to that key, as in the following example: In such case, we will split the name into the components names to be stored in an array at indices given by GCRS, DATUM, ELLIPSOID and PRIMEM.
      See Also:
    • DATUM

      static final int DATUM
      Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian. The GeoTIFF specification has only one key, GeoKeys.GeogCitation, for the geographic CRS and its components. But some GeoTIFF files encode the names of all components in the value associated to that key, as in the following example: In such case, we will split the name into the components names to be stored in an array at indices given by GCRS, DATUM, ELLIPSOID and PRIMEM.
      See Also:
    • GCRS

      static final int GCRS
      Index where to store the name of the geodetic CRS, the datum, the ellipsoid and the prime meridian. The GeoTIFF specification has only one key, GeoKeys.GeogCitation, for the geographic CRS and its components. But some GeoTIFF files encode the names of all components in the value associated to that key, as in the following example: In such case, we will split the name into the components names to be stored in an array at indices given by GCRS, DATUM, ELLIPSOID and PRIMEM.
      See Also:
    • NAME_KEYS

      private static final String[] NAME_KEYS
      Keys that may be used in the value associated to GeoKeys.GeogCitation. For each element in this array at index i, the i/2 value is equal to the DATUM, ELLIPSOID or PRIMEM constant for the corresponding type.
    • MIN_KEY_LENGTH

      private static final int MIN_KEY_LENGTH
      Minimal length that a key in a name must have before we compare them to the NAME_KEYS. For example, a value of 5 means that splitName(String) will accept "Ellip", "Ellips", "Ellipso" and "Ellipsoi" as if they were "Ellipsoid". This length shall not be greater than the length of the shortest string in NAME_KEYS.
      See Also:
    • reader

      private final Reader reader
      The reader for which we will create coordinate reference systems. This is used for reporting warnings.
    • majorRevision

      private short majorRevision
      Version of the set of keys declared in the GeoKeyDirectory header.
    • minorRevision

      private short minorRevision
      Version of the set of keys declared in the GeoKeyDirectory header.
    • geoKeys

      private final Map<Short,Object> geoKeys
      All values found in the GeoKeyDirectory after the header. Each value shall be used at most once. This allow us to remove value after usage, so we can easily detect at the end of the parsing process which GeoTIFF keys were unrecognized or ignored.
    • missingGeoKeys

      private final Set<String> missingGeoKeys
      Missing GeoKeys, used for avoiding to report the same warning twice.
      See Also:
    • lastName

      private org.opengis.metadata.Identifier lastName
      Name of the last object created. This is used by properties(Object) for reusing existing instance if possible. This is useful in GeoTIFF files since the same name is used for different geodetic components, for example the datum and the ellipsoid.
    • description

      public String description
      Suggested value for a general description of the transformation form grid coordinates to "real world" coordinates. This is computed by
      invalid reference
      #build(Vector, Vector, String)
      and made available as additional information to the caller.
    • cellGeometry

      public org.opengis.metadata.spatial.CellGeometry cellGeometry
      POINT if GeoKeys.RasterType is GeoCodes.RasterPixelIsPoint, AREA if it is GeoCodes.RasterPixelIsArea, or null if unspecified. This is computed by
      invalid reference
      #build(Vector, Vector, String)
      and made available to the caller.
    • alreadyReported

      boolean alreadyReported
      true when an exception has been thrown but this CRSBuilder already reported a warning, so there is no need for the caller to report a warning again. CRSBuilder sometimes reports warnings itself when it can provide a better warning message than what the caller can do.
    • PARAMETER_ALIASES

      private static final short[][] PARAMETER_ALIASES
      Map projection parameters to be considered as aliases. This table is used for reading GeoTIFF files that are not really well-formed, but for which we can reasonably guess what was the producer intent and which parameters were confused. See aliases(Map) for more explanation.
  • Constructor Details

    • CRSBuilder

      CRSBuilder(Reader reader)
      Creates a new builder of coordinate reference systems.
      Parameters:
      reader - where to report warnings if any.
  • Method Details

    • warning

      final void warning(short key, Object... args)
      Reports a warning with a message built from the given resource keys and arguments.
      Parameters:
      key - one of the Resources.Keys constants.
      args - arguments for the log message.
      See Also:
    • properties

      private Map<String,?> properties(Object name)
      Returns a map with the given name associated to "name". The given name shall be either an instance of String or Identifier. This is an helper method for creating geodetic objects with ReferencingFactoryContainer.getCRSFactory().
    • getSingleton

      private Object getSingleton(short key)
      Removes and returns the value for the given key as a singleton (not an array). If the value was an array, a warning is reported and the first element is returned.

      The given element is removed from the map so that each element is used only once (for example it would be redundant to have the verify(…) methods to compare the same values than the ones we used at geodetic object construction time). It also allow us to check which GeoKeys were ignored by looking at what is remaining in the map after CRS creation.

      Parameters:
      key - the GeoTIFF key for which to get a value.
      Returns:
      the singleton value for the given key, or null if none.
    • getAsString

      private String getAsString(short key)
      Removes and returns a GeoKeys value as a character string, or null if none. Value for the given key should be a sequence of characters. If it is one or more numbers instead, then this method formats those numbers in a comma-separated list. Such sequence of numbers would be unusual, but we do see strange GeoTIFF files in practice.

      See getSingleton(short) for a discussion about why the value is removed from the map.

      Parameters:
      key - the GeoTIFF key for which to get a value.
      Returns:
      a string representation of the value for the given key, or null if the key was not found.
    • getAsInteger

      private int getAsInteger(short key)
      Removes and returns a GeoKeys value as an integer. This is used for fetching enumeration values. The value returned by this method is typically one of the GeoCodes values.

      See getSingleton(short) for a discussion about why the value is removed from the map.

      Parameters:
      key - the GeoTIFF key for which to get a value.
      Returns:
      the integer value for the given key, or GeoCodes.undefined if the key was not found.
      Throws:
      NumberFormatException - if the value was stored as a string and cannot be parsed.
    • getAsDouble

      private double getAsDouble(short key)
      Removes and returns a GeoKeys value as a floating point number, or NaN if none. See getSingleton(short) for a discussion about why the value is removed from the map.
      Parameters:
      key - the GeoTIFF key for which to get a value.
      Returns:
      the floating point value for the given key, or Double.NaN if the key was not found.
      Throws:
      NumberFormatException - if the value was stored as a string and cannot be parsed.
    • getMandatoryString

      private String getMandatoryString(short key)
      Removes and returns a GeoKeys value as a character string, or throws an exception if none. A warning is reported before to throw the exception. There is no attempt to provide a good message in the exception since is should be caught by ImageFileDirectory.
      Parameters:
      key - the GeoTIFF key for which to get a value.
      Returns:
      a string representation of the value for the given key.
      Throws:
      NoSuchElementException - if no value has been found.
    • getMandatoryDouble

      private double getMandatoryDouble(short key)
      Removes and returns a GeoKeys value as a floating point number, or throws an exception if none. A warning is reported before to throw the exception. There is no attempt to provide a good message in the exception since is should be caught by ImageFileDirectory.
      Parameters:
      key - the GeoTIFF key for which to get a value.
      Returns:
      the floating point value for the given key.
      Throws:
      NoSuchElementException - if no value has been found.
      NumberFormatException - if the value was stored as a string and cannot be parsed.
    • missingValue

      final String missingValue(short key)
      Reports a warning about missing value for the given key. The key name is opportunistically returned for building the NoSuchElementException message, but it is not the main purpose of this method.
      See Also:
    • invalidValue

      private void invalidValue(short key, Object value)
      Reports a warning about an invalid value for the given key.
    • verify

      private void verify(org.opengis.referencing.IdentifiedObject epsg, double expected, short key, javax.measure.Unit<?> unit)
      Verifies that a value found in the GeoTIFF file is approximately equal to the expected value. This method is invoked when a CRS component is defined both explicitly and by EPSG code, in which case we expect the given value to be equal to the value fetched from the EPSG database. If the values do not match, a warning is reported and the caller should use the EPSG value.
      Parameters:
      epsg - the EPSG object, to be used for formatting the warning in case of mismatched values.
      expected - the expected value for an object identified by the epsg code.
      key - the GeoTIFF key of the user-defined value to compare with the expected one.
      unit - the unit of measurement for expected and actual, or null if none.
    • verifyIdentifier

      private void verifyIdentifier(org.opengis.referencing.IdentifiedObject parent, org.opengis.referencing.IdentifiedObject epsg, short key)
      Verifies that the EPSG code found in the GeoTIFF file is equal to the expected value. This method is invoked when a CRS component is defined by an EPSG code, in which case there is no need to specify the EPSG codes of the components, but the file still supply those EPSG codes. If the values do not match, a warning is reported.
      Parameters:
      parent - the parent which contains the epsg object
      epsg - the object created from the EPSG geodetic dataset.
      key - the GeoTIFF key for the EPSG code of the given epsg object.
    • build

      public org.opengis.referencing.crs.CoordinateReferenceSystem build(GeoKeysLoader source) throws org.opengis.util.FactoryException
      Decodes all the given GeoTIFF keys, then creates a coordinate reference system. An overview of the key directory structure is given in class javadoc. The description and cellGeometry fields are set as a side-effect. A warning is emitted if any GeoTIFF tags were ignored.
      Parameters:
      source - the keyDirectory, numericParameters and asciiParameters tags.
      Returns:
      the coordinate reference system created from the given GeoTIFF keys, or null if undefined.
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
    • remainingKeys

      private Short[] remainingKeys()
      Returns all remaining keys, sorted in increasing order.
    • replaceLinearUnit

      private org.opengis.referencing.cs.CartesianCS replaceLinearUnit(org.opengis.referencing.cs.CartesianCS cs, javax.measure.Unit<javax.measure.quantity.Length> unit) throws org.opengis.util.FactoryException
      Returns a coordinate system (CS) with the same axis directions than the given CS but potentially different units. If a coordinate system exists in the EPSG database with the requested characteristics, that CS will be returned in order to have a richer set of metadata (name, minimal and maximal values, etc). Otherwise an CS with an arbitrary name will be returned.
      Throws:
      org.opengis.util.FactoryException
      See Also:
    • replaceAngularUnit

      private org.opengis.referencing.cs.EllipsoidalCS replaceAngularUnit(org.opengis.referencing.cs.EllipsoidalCS cs, javax.measure.Unit<javax.measure.quantity.Angle> unit) throws org.opengis.util.FactoryException
      Returns a coordinate system (CS) with the same axis directions than the given CS but potentially different units. If a coordinate system exists in the EPSG database with the requested characteristics, that CS will be returned in order to have a richer set of metadata (name, minimal and maximal values, etc). Otherwise an CS with an arbitrary name will be returned.
      Throws:
      org.opengis.util.FactoryException
      See Also:
    • createUnit

      private <Q extends javax.measure.Quantity<Q>> javax.measure.Unit<Q> createUnit(short codeKey, short scaleKey, Class<Q> quantity, javax.measure.Unit<Q> defaultValue) throws org.opengis.util.FactoryException
      Creates units of measurement for projected or geographic coordinate reference systems. The units may either be specified as a standard EPSG recognized unit, or may be user defined. If the first case (EPSG code), the keyUser is ignored. In the second case (user-defined), the unit of measurement is defined by a conversion factor from metre or radian base unit.
      Parameters:
      codeKey - the GeoKeys for a unit of measurement defined by an EPSG code.
      scaleKey - the GeoKeys for a unit of measurement defined by a scale applied on a base unit.
      quantity - Length for a linear unit, or Angle for an angular unit.
      defaultValue - the unit of measurement to return if no value is found in the GeoTIFF file.
      Returns:
      the unit of measurement associated to the given GeoKeys, or the default value.
      Throws:
      NoSuchElementException - if keyEPSG value is GeoCodes.userDefined and no value is associated to keyUser.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if the unit of measurement identified by the EPSG code is not of the expected quantity.
      org.opengis.util.FactoryException
    • createPrimeMeridian

      private org.opengis.referencing.datum.PrimeMeridian createPrimeMeridian(String[] names, javax.measure.Unit<javax.measure.quantity.Angle> unit) throws org.opengis.util.FactoryException
      Creates a prime meridian from an EPSG code or from user-defined parameters. The GeoTIFF values used by this method are: If no prime-meridian is defined, then the default is Greenwich as per GeoTIFF specification.
      Parameters:
      names - the component names to use if the prime meridian is user-defined.
      unit - the angular unit of the longitude value relative to Greenwich.
      Returns:
      a prime meridian created from the given Unit and the above-cited GeoTIFF keys.
      Throws:
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
    • verify

      private void verify(org.opengis.referencing.datum.PrimeMeridian pm, javax.measure.Unit<javax.measure.quantity.Angle> unit)
      Verifies if the user-defined prime meridian created from GeoTIFF values matches the given prime meridian created from the EPSG geodetic dataset. This method does not verify the EPSG code.
      Parameters:
      pm - the prime meridian created from the EPSG geodetic dataset.
      unit - the unit of measurement declared in the GeoTIFF file.
    • createEllipsoid

      private org.opengis.referencing.datum.Ellipsoid createEllipsoid(String[] names, javax.measure.Unit<javax.measure.quantity.Length> unit) throws org.opengis.util.FactoryException
      Creates an ellipsoid from an EPSG code or from user-defined parameters. The GeoTIFF values used by this method are:
      Parameters:
      names - the component names to use if the ellipsoid is user-defined.
      unit - the linear unit of the semi-axis lengths.
      Returns:
      an ellipsoid created from the given Unit and the above-cited GeoTIFF keys.
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
    • verify

      private void verify(org.opengis.referencing.datum.Ellipsoid ellipsoid, javax.measure.Unit<javax.measure.quantity.Length> unit)
      Verifies if the user-defined ellipsoid created from GeoTIFF values matches the given ellipsoid created from the EPSG geodetic dataset. This method does not verify the EPSG code.
      Parameters:
      ellipsoid - the ellipsoid created from the EPSG geodetic dataset.
      unit - the unit of measurement declared in the GeoTIFF file.
    • createGeodeticDatum

      private org.opengis.referencing.datum.GeodeticDatum createGeodeticDatum(String[] names, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit) throws org.opengis.util.FactoryException
      Creates a geodetic datum from an EPSG code or from user-defined parameters. The GeoTIFF values used by this method are:
      Parameters:
      names - the component names to use if the geodetic datum is user-defined.
      angularUnit - the angular unit of the longitude value relative to Greenwich.
      linearUnit - the linear unit of the ellipsoid semi-axis lengths.
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
      See Also:
    • verify

      private void verify(org.opengis.referencing.datum.GeodeticDatum datum, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit)
      Verifies if the user-defined datum created from GeoTIFF values matches the given datum created from the EPSG geodetic dataset. This method does not verify the EPSG code of the given datum.
      Parameters:
      datum - the datum created from the EPSG geodetic dataset.
      angularUnit - unit of measurement declared in the GeoTIFF file.
      linearUnit - unit of measurement declared in the GeoTIFF file.
    • splitName

      static String[] splitName(String name)
      Splits the GeoKeys.GeogCitation value into its prime meridian, ellipsoid, datum and CRS name components. This method is intended to parse geographic CRS names written like below: The keywords of both Well Known Text (WKT) version 1 and 2 are accepted as keys for the datum, ellipsoid and prime meridian names. All other keys are presumed to be for the geographic CRS name. If the given string does not contain the pipe ('|') separator, then the whole string is presumed to be the geographic CRS name.

      This method returns an array where component names are stored at index PRIMEM, ELLIPSOID, DATUM and GCRS. Any array element can be null if no name were found for that component.

    • getOrDefault

      private static String getOrDefault(String[] names, int component)
      Returns the name at the given index if non-null. If that name is null, search for a name in a sister element (e.g. the datum name or the geographic CRS name). If none is found, returns null.
    • createGeographicCRS

      private org.opengis.referencing.crs.GeographicCRS createGeographicCRS() throws org.opengis.util.FactoryException
      Creates the main CRS in the case where that CRS is geographic.
      Throws:
      org.opengis.util.FactoryException
    • createGeographicCRS

      private org.opengis.referencing.crs.GeographicCRS createGeographicCRS(boolean rightHanded, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit) throws org.opengis.util.FactoryException
      Creates a geographic CRS from an EPSG code or from user-defined parameters. The GeoTIFF values used by this method are:
      Parameters:
      rightHanded - whether to force longitude before latitude axis.
      angularUnit - the angular unit of the latitude and longitude values.
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
      See Also:
    • verify

      private void verify(org.opengis.referencing.crs.GeographicCRS crs, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit) throws org.opengis.util.FactoryException
      Verifies if the user-defined CRS created from GeoTIFF values matches the given CRS created from the EPSG geodetic dataset. This method does not verify the EPSG code of the given CRS.
      Parameters:
      crs - the CRS created from the EPSG geodetic dataset.
      angularUnit - the angular unit of the latitude and longitude values.
      Throws:
      org.opengis.util.FactoryException
    • createGeocentricCRS

      private org.opengis.referencing.crs.GeocentricCRS createGeocentricCRS() throws org.opengis.util.FactoryException
      Creates a geocentric CRS from user-defined parameters. The GeoTIFF values used by this method are the same than the ones used by createGeographicCRS(…).
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
      See Also:
    • verify

      private void verify(org.opengis.referencing.crs.GeocentricCRS crs) throws org.opengis.util.FactoryException
      Verifies if the user-defined CRS created from GeoTIFF values matches the given CRS created from the EPSG geodetic dataset. This method does not verify the EPSG code of the given CRS.
      Parameters:
      crs - the CRS created from the EPSG geodetic dataset.
      Throws:
      org.opengis.util.FactoryException
    • aliases

      private static void aliases(Map<Integer,String> mapping)
      Updates a mapping from GeoTIFF numerical identifiers to parameter names by adding parameter aliases. This method adds to the given map some GeoTIFF keys to be considered synonymous to an existing key. Those "synonymous" parameters are strictly speaking not for the map projection that we are parsing, but it is common to see GeoTIFF files with "wrong" projection parameter codes. For example:
      • The "CT_LambertConfConic_1SP" projection uses a "NatOriginLong" parameter.
      • The "CT_LambertConfConic_2SP" projection uses a "FalseOriginLong" parameter.
      but we sometimes see "NatOriginLong" parameter used for the "CT_LambertConfConic_2SP" projection. Semantically those two parameters are for two different things but mathematically they are used in the same way. Those "synonymous" will be invisible to the user; the map projection that (s)he will get uses the names defined in the descriptor (not in the GeoTIFF file).
    • createProjectedCRS

      private org.opengis.referencing.crs.ProjectedCRS createProjectedCRS() throws org.opengis.util.FactoryException
      Creates a projected CRS from an EPSG code or from user-defined parameters. Some GeoTIFF values used by this method are:
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
      See Also:
    • verify

      private void verify(org.opengis.referencing.crs.ProjectedCRS crs) throws org.opengis.util.FactoryException
      Verifies if the user-defined CRS created from GeoTIFF values matches the given CRS created from the EPSG geodetic dataset. This method does not verify the EPSG code of the given CRS.
      Parameters:
      crs - the CRS created from the EPSG geodetic dataset.
      Throws:
      org.opengis.util.FactoryException
    • createConversion

      private org.opengis.referencing.operation.Conversion createConversion(String name, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit) throws org.opengis.util.FactoryException
      Creates a defining conversion from an EPSG code or from user-defined parameters.
      Parameters:
      angularUnit - the angular unit of the latitude and longitude values.
      linearUnit - the linear unit of easting and northing values.
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      org.opengis.parameter.ParameterNotFoundException - if the GeoTIFF file defines an unexpected map projection parameter.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
    • verify

      private void verify(org.opengis.referencing.operation.Conversion projection, javax.measure.Unit<javax.measure.quantity.Angle> angularUnit, javax.measure.Unit<javax.measure.quantity.Length> linearUnit) throws org.opengis.util.FactoryException
      Verifies if the user-defined conversion created from GeoTIFF values matches the given conversion created from the EPSG geodetic dataset. This method does not verify the EPSG code of the given conversion.
      Parameters:
      projection - the conversion created from the EPSG geodetic dataset.
      Throws:
      org.opengis.util.FactoryException
    • createVerticalDatum

      private org.opengis.referencing.datum.VerticalDatum createVerticalDatum() throws org.opengis.util.FactoryException
      Creates a vertical datum.
      Throws:
      org.opengis.util.FactoryException
    • createVerticalCRS

      private org.opengis.referencing.crs.VerticalCRS createVerticalCRS() throws org.opengis.util.FactoryException
      Creates an optional vertical CRS, or returns null if no vertical CRS definition is found. This method is different from the other createFooCRS() methods in that the vertical CRS may be defined in addition of another CRS. Some GeoTIFF values used by this method are:
      Throws:
      NoSuchElementException - if a mandatory value is missing.
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
      ClassCastException - if an object defined by an EPSG code is not of the expected type.
      org.opengis.util.FactoryException - if an error occurred during objects creation with the factories.
    • toString

      public final String toString()
      Returns a string representation of the keys and associated values in this CRSBuilder.
      Overrides:
      toString in class Object