Class Importer

java.lang.Object
org.locationtech.proj4j.geoapi.Importer

public class Importer extends Object
Builder of PROJ4J objects from GeoAPI objects. If the GeoAPI object has been created by a call to a Wrappers.geoapi(…) method, then the wrapped object is returned directly. Otherwise, this class tries to creates new PROJ4J instances using the information provided in the GeoAPI object. It may fail, in which case an UnconvertibleInstanceException is thrown.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final Importer
    Default instance used by Wrappers.proj4j(…) methods.
    private static final String[]
    Possible name spaces for OGC parameters, case-insensitive.
    private static final String[]
    Possible name spaces for PROJ4J operation methods, case-insensitive.
    protected Registry
    A registry for creating Projection instances if needed.
    private static final Set<org.opengis.referencing.cs.AxisDirection>
    Axis directions supported by PROJ4J.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default instance.
    Importer(Registry registry)
    Creates an importer which will use the given registry.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static String
    axisOrder(org.opengis.referencing.cs.CoordinateSystem cs)
    Returns the axis order of the given coordinate system.
    convert(org.opengis.parameter.ParameterValueGroup src)
    Returns the given parameters as a PROJ4J implementation.
    convert(org.opengis.referencing.crs.CRSAuthorityFactory src)
    Returns the given authority factory as a PROJ4J implementation.
    convert(org.opengis.referencing.crs.SingleCRS src)
    Returns the given CRS as a PROJ4J implementation.
    convert(org.opengis.referencing.datum.Ellipsoid src)
    Returns the given ellipsoid as a PROJ4J implementation.
    convert(org.opengis.referencing.datum.GeodeticDatum src)
    Returns the given datum as a PROJ4J implementation.
    convert(org.opengis.referencing.datum.PrimeMeridian src)
    Returns the given prime meridian as a PROJ4J implementation.
    convert(org.opengis.referencing.operation.CoordinateOperation src)
    Returns the given coordinate operation as a PROJ4J implementation.
    convert(org.opengis.referencing.operation.CoordinateOperationFactory src)
    Returns the given coordinate operation factory as a PROJ4J implementation.
    private static String
    getAlias(org.opengis.referencing.IdentifiedObject src, String scope)
    Returns the first alias of the given identified object which is in the given scope.
    private static String
    getName(org.opengis.referencing.IdentifiedObject src)
    Returns the name of the given identified object.
    private static String
    getNameOrAlias(org.opengis.referencing.IdentifiedObject src, String[] scopes)
    Returns the primary name or the first alias having one of the the given name spaces.
    Returns the registry to use for creating PROJ4J objects from a name.
    private static String
    getVendorName(org.opengis.util.Factory factory)
    Returns the name of the implementer of the given factory.

    Methods inherited from class Object

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

    • PROJ_NAMESPACES

      private static final String[] PROJ_NAMESPACES
      Possible name spaces for PROJ4J operation methods, case-insensitive.
    • OGC_NAMESPACES

      private static final String[] OGC_NAMESPACES
      Possible name spaces for OGC parameters, case-insensitive. ESRI parameters are usually the same as OGC parameters except for the case.
    • SUPPORTED_AXIS_DIRECTIONS

      private static final Set<org.opengis.referencing.cs.AxisDirection> SUPPORTED_AXIS_DIRECTIONS
      Axis directions supported by PROJ4J. The PROJ4J code for each axis direction is the first letter of the name of code list value, converted to lower case.
    • registry

      protected Registry registry
      A registry for creating Projection instances if needed. If null, a default instance will be created when first needed.
      See Also:
    • DEFAULT

      static final Importer DEFAULT
      Default instance used by Wrappers.proj4j(…) methods.
  • Constructor Details

    • Importer

      public Importer()
      Creates a default instance.
    • Importer

      public Importer(Registry registry)
      Creates an importer which will use the given registry.
      Parameters:
      registry - a registry for creating Projection instances, or null for default
  • Method Details

    • getRegistry

      public Registry getRegistry()
      Returns the registry to use for creating PROJ4J objects from a name.. If no registry was specified at construction time, a default instance is created the first time that this method is invoked.
      Returns:
      the registry to use for creating PROJ4J objects from a name
    • convert

      public CRSFactory convert(org.opengis.referencing.crs.CRSAuthorityFactory src)
      Returns the given authority factory as a PROJ4J implementation. This method returns the backing implementation. If the given factory is not backed by a PROJ4J implementation, then the current implementation throws an exception.
      Parameters:
      src - the object to unwrap or convert, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • convert

      public CoordinateReferenceSystem convert(org.opengis.referencing.crs.SingleCRS src)
      Returns the given CRS as a PROJ4J implementation. This method tries to return the backing implementation if possible, or otherwise copies the properties in a new PROJ4J instance.
      Parameters:
      src - the object to unwrap or convert, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • axisOrder

      static String axisOrder(org.opengis.referencing.cs.CoordinateSystem cs)
      Returns the axis order of the given coordinate system.
      Parameters:
      cs - the coordinate system for which to get the axis order
      Returns:
      the 3-letters code of axis order to be given to AxisOrder.fromString(String).
      Throws:
      UnconvertibleInstanceException - if the coordinate system uses an unsupported axis order
    • convert

      public Datum convert(org.opengis.referencing.datum.GeodeticDatum src)
      Returns the given datum as a PROJ4J implementation. This method tries to return the backing implementation if possible, or otherwise copies the properties in a new PROJ4J instance.
      Parameters:
      src - the object to unwrap or convert, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • convert

      public Ellipsoid convert(org.opengis.referencing.datum.Ellipsoid src)
      Returns the given ellipsoid as a PROJ4J implementation. This method tries to return the backing implementation if possible, or otherwise copies the properties in a new PROJ4J instance.
      Parameters:
      src - the object to unwrap or convert, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • convert

      public PrimeMeridian convert(org.opengis.referencing.datum.PrimeMeridian src)
      Returns the given prime meridian as a PROJ4J implementation. This method tries to return the backing implementation if possible, or an equivalent PROJ4J instance otherwise.
      Parameters:
      src - the object to unwrap, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • convert

      public Projection convert(org.opengis.parameter.ParameterValueGroup src)
      Returns the given parameters as a PROJ4J implementation. This method tries to return the backing implementation if possible, or an equivalent PROJ4J instance otherwise.
      Parameters:
      src - the object to unwrap, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • convert

      public CoordinateTransformFactory convert(org.opengis.referencing.operation.CoordinateOperationFactory src)
      Returns the given coordinate operation factory as a PROJ4J implementation. This method returns the backing implementation. If the given factory is not backed by a PROJ4J implementation, then the current implementation throws an exception.
      Parameters:
      src - the object to unwrap or convert, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • convert

      public CoordinateTransform convert(org.opengis.referencing.operation.CoordinateOperation src)
      Returns the given coordinate operation as a PROJ4J implementation. This method returns the backing implementation. If the given factory is not backed by a PROJ4J implementation, then the current implementation throws an exception.
      Parameters:
      src - the object to unwrap or convert, or null
      Returns:
      the PROJ4J implementation, or null if the given object was null
      Throws:
      UnconvertibleInstanceException - if the given object cannot be unwrapped or converted
    • getVendorName

      private static String getVendorName(org.opengis.util.Factory factory)
      Returns the name of the implementer of the given factory. This is used for error messages.
      Parameters:
      factory - the factory for which to get the implementer name
      Returns:
      name of the implementer of the given factory
    • getName

      private static String getName(org.opengis.referencing.IdentifiedObject src)
      Returns the name of the given identified object.. This method is null-safe. Null safety is theoretically not necessary because the name is mandatory, but we try to be safe.
      Parameters:
      src - the object for which to get the name, or null
      Returns:
      the name of the given identified object
    • getAlias

      private static String getAlias(org.opengis.referencing.IdentifiedObject src, String scope)
      Returns the first alias of the given identified object which is in the given scope. Aliases are often used for abbreviations.
      Parameters:
      src - the object for which to get an alias, or null
      scope - scope of the alias to get, or null for the first alias regardless is scope
      Returns:
      the first alias, or null if none
    • getNameOrAlias

      private static String getNameOrAlias(org.opengis.referencing.IdentifiedObject src, String[] scopes)
      Returns the primary name or the first alias having one of the the given name spaces. If no name or alias is found, then the first non-null name or alias is returned.
      Parameters:
      src - the object for which to get a name or alias in the given name spaces
      scopes - the desired name spaces, case-insensitive
      Returns:
      the first name in one of the given name space if any, or an arbitrary name otherwise