createFromUserInput(String)— for creating aCoordinateReferenceSystemfrom an EPSG code, a WKT string, etc.createCoordinateOperation(…)— for creating theCoordinateOperationcapable to transform coordinate values from one CRS to another.
getAuthorityFactory(String) and getOperationFactory(CoordinateOperationContext)
methods provide similar functionality in a more implementation neutral way, at the cost of one indirection level
(need to fetch the factory before invoking methods on it).- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareEquivalent(Object obj1, Object obj2, ComparisonCriterion criterion) Returnstrueif the given objects are equivalent according the given criterion.static CoordinateOperationcreateCoordinateOperation(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, CoordinateOperationContext context) Returns an operation for conversion or transformation between two coordinate reference systems, taking in account the given context.static List<CoordinateOperation>createCoordinateOperations(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, CoordinateOperationContext context) Returns operations for conversion or transformation between two coordinate reference systems, taking in account the given context.static IdentifiedObjectcreateFromUserInput(String text) Instantiate a geodetic object from a user specified text.static DirectPositioncreatePosition(CoordinateReferenceSystem crs, double... coordinates) Creates a position with the given coordinate values and an optional CRS.static CRSAuthorityFactorygetAuthorityFactory(String authority) Returns a factory for creating coordinate reference systems from codes allocated by the given authority.static <F extends Factory>
FgetFactory(Class<F> type) Returns a factory of the given type.static CoordinateOperationFactoryCreates a new operation factory for the given context.static CoordinateOperationnormalizeForVisualization(CoordinateOperation operation) Returns a coordinate operation with axis order such as the east direction is first and the north direction is second, if possible.version()Returns the version number of the PROJ library.
-
Method Details
-
version
Returns the version number of the PROJ library. If the PROJ library is not installed on the current system, then this method logs an error message and returns an empty value. This method can be used as a way to check if the library is present.- Returns:
- the PROJ release string, or an empty value if the native library is not found.
-
getAuthorityFactory
Returns a factory for creating coordinate reference systems from codes allocated by the given authority. The authority is typically "EPSG", but not necessarily; other authorities like "IAU" are also allowed. Typical values are:"EPSG"— de facto standard for coordinate reference systems on Earth."IAU"— extraterrestrial coordinate reference systems.""(empty string) — PROJ default set of authorities.
createCoordinateReferenceSystem(…)method can be invoked to create a CRS from an authority code. For example the code below creates the "WGS 84" coordinate reference system for the "EPSG::4326" code. In that example, only the first line is PROJ-specific; the remaining lines can be executed with any GeoAPI implementation:
The factory returned by this method is safe for concurrent use in multi-threads environment. The object returned by this method also implements theCRSAuthorityFactory factory = Proj.getAuthorityFactory("EPSG"); CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("4326"); System.out.println(crs.toWKT());CSAuthorityFactory,DatumAuthorityFactoryandCoordinateOperationAuthorityFactoryinterfaces (so it can be cast to any of those interfaces), but typically only theCRSAuthorityFactoryinterface is used.- Parameters:
authority- authority name of the factory (e.g."EPSG").- Returns:
- the
CRSAuthorityFactory,CSAuthorityFactory,DatumAuthorityFactoryandCoordinateOperationAuthorityFactoryfor the given authority. - Throws:
NullPointerException- ifauthorityisnull.
-
getOperationFactory
Creates a new operation factory for the given context. The context is an optional argument which allows specifying the area of interest and desired accuracy. The returned factory can be used for creatingCoordinateOperations for given pairs ofCoordinateReferenceSystems. Example:CoordinateReferenceSystem sourceCRS = ...; CoordinateReferenceSystem targetCRS = ...; CoordinateOperationFactory opFactory = Proj.getOperationFactory(null); CoordinateOperation operation = opFactory.createOperation(sourceCRS, targetCRS); System.out.println(operation.toWKT());
- Parameters:
context- in which coordinate operations are to be used, ornullfor the default setting.- Returns:
- a factory for creating coordinate operations in the given context.
-
getFactory
Returns a factory of the given type. This method recognizes three groups of factories:-
CRSAuthorityFactory,CSAuthorityFactory,DatumAuthorityFactoryandCoordinateOperationAuthorityFactory: equivalent to the factories returned bygetAuthorityFactory(""). -
CRSFactory,CSFactoryandDatumFactory: no equivalence. Those factories allow to create customized CRS from components such as axes, datum, map projection parameters, etc. -
CoordinateOperationFactory: equivalent to the factory returned bygetOperationFactory(null).
- Type Parameters:
F- compile-time value oftypeargument.- Parameters:
type- type of factory desired.- Returns:
- factory of the given type.
- Throws:
IllegalArgumentException- if the specified type is not one of the above-listed types.
-
-
createFromUserInput
Instantiate a geodetic object from a user specified text. The returned object will typically by a subtype ofCoordinateReferenceSystem. The text can be a:- WKT string.
- PROJ string.
- database code, prefixed by its authority. Example:
“EPSG:4326”. - OGC URN. Examples:
“urn:ogc:def:crs:EPSG::4326”,“urn:ogc:def:coordinateOperation:EPSG::1671”,“urn:ogc:def:ellipsoid:EPSG::7001”or“urn:ogc:def:datum:EPSG::6326”. - OGC URN combining references for compound coordinate reference systems. Examples:
“urn:ogc:def:crs,crs:EPSG::2393,crs:EPSG::5717”. We also accept a custom abbreviated syntax“EPSG:2393+5717”. - OGC URN combining references for references for projected or derived CRSs.
Example for Projected 3D CRS “UTM zone 31N / WGS 84 (3D)”:
“urn:ogc:def:crs,crs:EPSG::4979,cs:PROJ::ENh,coordinateOperation:EPSG::16031”. - OGC URN combining references for concatenated operations. Example:
“urn:ogc:def:coordinateOperation,coordinateOperation:EPSG::3895,coordinateOperation:EPSG::1618”. - An Object name. Example: “WGS 84”, “WGS 84 / UTM zone 31N”. In that case as uniqueness is not guaranteed, the function may apply heuristics to determine the appropriate best match.
- PROJJSON string.
- Parameters:
text- one of the above mentioned text format.- Returns:
- a coordinate reference system or other kind of object created from the given text.
- Throws:
FactoryException- if the given text can not be parsed.- See Also:
-
createCoordinateOperation
public static CoordinateOperation createCoordinateOperation(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, CoordinateOperationContext context) throws FactoryException Returns an operation for conversion or transformation between two coordinate reference systems, taking in account the given context. If more than one operation exists, the preferred one is returned. If no operation exists, then an exception is thrown.The context is an optional argument which specifying the area of interest and desired accuracy. If this argument is
null, then the default setting is:- Coordinate operations from any authority will be searched,
with the restrictions set in the
"authority_to_authority_preference"database table. - Area of interest is unknown.
- Desired accuracy is best accuracy available.
- Source and target CRS extents use is
SourceTargetCRSExtentUse.SMALLEST. - Criterion for comparing areas of validity is
SpatialCriterion.STRICT_CONTAINMENT. - Grid availability use is
USE_FOR_SORTING. - Use of intermediate pivot CRS is allowed.
- Parameters:
sourceCRS- input coordinate reference system.targetCRS- output coordinate reference system.context- context in which the coordinate operation is to be used.- Returns:
- coordinate operations from
sourceCRStotargetCRS. - Throws:
NullPointerException- ifsourceCRSortargetCRSisnull.UnsupportedImplementationException- if a CRS is not a PROJ-JNI implementation.FactoryException- if the operation creation failed.- See Also:
- Coordinate operations from any authority will be searched,
with the restrictions set in the
-
createCoordinateOperations
public static List<CoordinateOperation> createCoordinateOperations(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, CoordinateOperationContext context) throws FactoryException Returns operations for conversion or transformation between two coordinate reference systems, taking in account the given context. If no coordinate operation is found, then this method returns an empty list.The context is an optional argument which allows specifying the area of interest and desired accuracy. If this argument is
null, then the default values are documented here.- Parameters:
sourceCRS- input coordinate reference system.targetCRS- output coordinate reference system.context- context in which the coordinate operation is to be used.- Returns:
- coordinate operations from
sourceCRStotargetCRS. - Throws:
NullPointerException- ifsourceCRSortargetCRSisnull.UnsupportedImplementationException- if a CRS is not a PROJ-JNI implementation.FactoryException- if the operation creation failed.
-
createPosition
Creates a position with the given coordinate values and an optional CRS.At least one of
crsandcoordinatesarguments must be non-null. If both arguments are non-null, then the number of dimensions of the given CRS must match the number of coordinate values.A
DirectPositioninstance can be transformed to another CRS by a call tofactory.createOperation(position.getCoordinateReferenceSystem())for fetching the coordinate operation, thenoperation.getMathTransform().transform(position, null)for executing that operation. However those steps are costly and should be applied for only a small number of points. For large number of points, consider using coordinate tuples infloat[]ordouble[]arrays instead.Serialization
TheDirectPositionreturned by this method is serializable, but the CRS is lost in the serialization process because we do not serialize native PROJ objects.- Parameters:
crs- the coordinate reference system, ornullis unspecified.coordinates- the coordinate values, ornullfor initializing the position to zero.- Returns:
- a direct position for the given coordinate values and optional CRS.
- Throws:
NullPointerException- if bothcrsandcoordinatesarenull.UnsupportedImplementationException- if the given CRS is not a PROJ-JNI implementation.MismatchedDimensionException- if the given CRS is non-null but its number of dimensions is not equal to the length of thecoordinatesarray.- See Also:
-
normalizeForVisualization
Returns a coordinate operation with axis order such as the east direction is first and the north direction is second, if possible.- Parameters:
operation- the operation for which to adjust axis order.- Returns:
- an operation with axis order convenient for visualization.
-
areEquivalent
Returnstrueif the given objects are equivalent according the given criterion. If the two given objects arenull, this method returnstrue. If one object is null and the other object is non-null, this method returnsfalse.- Parameters:
obj1- first object to compare, ornull.obj2- second object to compare, ornull.criterion- the comparison criterion, which can be strict or relaxed.- Returns:
- whether the given objects are equivalent according the given criterion.
-