Class PROJFormatter

Object
PROJFormatter

public class PROJFormatter extends Object
A Formatter that formats PROJFormattable objects as PROJ strings. Supported PROJ formattable are normally IdentifiedObject as well.

Call toPROJ(PROJFormattable) to get the associated proj String.

  • Field Details

  • Constructor Details

    • PROJFormatter

      public PROJFormatter()
      Creates a new instance of the PROJFormatter.
  • Method Details

    • isProjectedCRS

      public boolean isProjectedCRS()
    • isDatumProvided

      public boolean isDatumProvided()
    • isEllipsoidProvided

      public boolean isEllipsoidProvided()
    • isPrimeMeridianProvided

      public boolean isPrimeMeridianProvided()
    • append

      public void append(PROJFormattable formattable)
    • append

      public void append(GeneralParameterValue parameter)
      Appends a PROJ string representation of the given parameter to the internal buffer.

      This method is part of a PROJFormatter that converts GeneralParameterValue objects (such as parameters for projection operations) into PROJ format strings. It handles both individual parameters and groups of parameters.

      If the parameter is a ParameterValueGroup, the method recursively processes each contained GeneralParameterValue. For each ParameterValue, it appends a formatted key-value pair to the buffer, with the key based on the parameter descriptor's name and the value based on the parameter's value, converted to a double if possible.

      Parameters:
      parameter - the GeneralParameterValue to format and append. This may be an individual ParameterValue or a group of parameters in a ParameterValueGroup.
      Throws:
      ClassCastException - if parameter is not an instance of ParameterValueGroup or ParameterValue, as only these types are supported.
    • append

      public void append(Unit<?> unit)
      Appends the PROJ string representation of the specified unit to the internal buffer.

      This method adds the unit symbol to the buffer in a format compatible with PROJ, typically as a `+units=` key-value pair. If the unit's symbol is not available, it uses the unit's string representation instead.

      Parameters:
      unit - the Unit to format and append. If unit is null, nothing is appended to the buffer.

      Example:

       +units=m
       
    • append

      public void append(String key, String value)
      Appends a PROJ-compatible key-value pair to the internal buffer, where the value is a string.

      This method formats the key and value in the style expected by PROJ. The result format is `+key=value`.

      Parameters:
      key - the key to be appended, representing the parameter name.
      value - the value to be appended, represented as a string.

      Example:

       +proj=longlat
       
    • append

      public void append(String key, double number)
      Appends a PROJ-compatible key-value pair to the internal buffer, where the value is a double.

      This method formats the key and numeric value in a style compatible with PROJ. The result format is `+key=value`, with the value formatted to the appropriate precision using format(double).

      Parameters:
      key - the key to be appended, representing the parameter name.
      number - the value to be appended, represented as a double.

      Example:

       +rf=299.1528128
       
    • getName

      public String getName(IdentifiedObject info)
      Returns the preferred name for the specified object. If the specified object contains a name from the preferred authority then this name is returned. Otherwise, it will be added to not parseable list
      Parameters:
      info - The object to looks for a preferred name.
      Returns:
      The preferred name.
    • getIdentifier

      public Identifier getIdentifier(IdentifiedObject info)
      Retrieves the identifier for a given IdentifiedObject.
      Parameters:
      info - the IdentifiedObject from which to retrieve an identifier. May be null, in which case this method returns null.
      Returns:
      the Identifier with the authority Citations.PROJ if found, or the first identifier in the collection if no match with Citations.PROJ is found. Returns null if info is null or has no identifiers.
    • clear

      public void clear()
      Clears the internal state of the formatter to allow for reuse.

      This method resets the internal buffer and all tracking flags, preparing the formatter for a new PROJ string generation. It can be used to reuse the same formatter instance for multiple formatting operations.

      This is useful when the formatter instance needs to be reused for different projections or coordinate reference systems without creating a new instance each time.

    • toPROJ

      public String toPROJ(PROJFormattable formattable)
      That's the main method to get the PROJ String out of a PROJFormattable.
      Parameters:
      formattable - the identified object to be formatted
      Returns: