forCode(String)
.
isHorizontalCRS(CoordinateReferenceSystem)
.
forCode(…)
,
fromWKT(…)
and
findOperation(…)
. An usage example is like below
(see the
Apache SIS™ Coordinate
Reference System (CRS) codes
page for the complete list of EPSG codes):
CoordinateReferenceSystem source = CRS.forCode("EPSG:4326"); // WGS 84
CoordinateReferenceSystem target = CRS.forCode("EPSG:3395"); // WGS 84 / World Mercator
CoordinateOperation operation = CRS.findOperation(source, target, null);
if (CRS.getLinearAccuracy(operation) > 100) {
// If the accuracy is coarser than 100 metres (or any other threshold at application choice)
// maybe the operation is not suitable. Decide here what to do (throw an exception, etc).
MathTransform mt = operation.getMathTransform();
DirectPosition position = new DirectPosition2D(20, 30); // 20°N 30°E (watch out axis order!)
position = mt.transform(position, position);
System.out.println(position);
getSingleComponents(CoordinateReferenceSystem)
method decomposes an arbitrary CRS into a flat
list of single components. In such flat list, vertical and temporal components can easily be identified by
instanceof
checks. But identifying the horizontal component is not as easy. The list below suggests
ways to classify the components:
if (crs instanceof TemporalCRS)
determines if the CRS is for the temporal component.
if (crs instanceof VerticalCRS)
determines if the CRS is for the vertical component.
if (CRS.
isHorizontalCRS
(crs))
determines if the CRS is for the horizontal component.
Defined in the
sis-referencing
module
static
CoordinateReferenceSystem
compound
(
CoordinateReferenceSystem
... components)
static
CoordinateOperation
findOperation
(
CoordinateReferenceSystem
sourceCRS,
CoordinateReferenceSystem
targetCRS,
GeographicBoundingBox
areaOfInterest)
static
List
<
CoordinateOperation
>
findOperations
(
CoordinateReferenceSystem
sourceCRS,
CoordinateReferenceSystem
targetCRS,
GeographicBoundingBox
areaOfInterest)
static
CoordinateReferenceSystem
static
CoordinateReferenceSystem
fromAuthority
(
CoordinateReferenceSystem
crs,
CRSAuthorityFactory
factory,
Filter
warningFilter)
static
CoordinateReferenceSystem
static
CoordinateReferenceSystem
static
CRSAuthorityFactory
getAuthorityFactory
(
String
authority)
forCode(String)
and other SIS methods.
static
CoordinateReferenceSystem
getComponentAt
(
CoordinateReferenceSystem
crs,
int lower,
int upper)
static
Envelope
null
if unknown.
static
GeographicBoundingBox
null
if unknown.
static
GeographicBoundingBox
getGeographicBoundingBox
(
CoordinateOperation
operation)
null
if unknown.
static double
static
SingleCRS
null
if there is
none.
static double
getLinearAccuracy
(
CoordinateOperation
operation)
NaN
if unknown.
static
List
<
SingleCRS
>
static
TemporalCRS
null
if there is none.
static
VerticalCRS
getVerticalComponent
(
CoordinateReferenceSystem
crs,
boolean allowCreateEllipsoidal)
null
if there is none.
static boolean
true
if the given CRS is horizontal.
static
CoordinateReferenceSystem
reduce
(
CoordinateReferenceSystem
crs,
int... dimensions)
static
CoordinateReferenceSystem
selectDimensions
(
CoordinateReferenceSystem
crs,
int... dimensions)
static
CoordinateReferenceSystem
suggestCommonTarget
(
GeographicBoundingBox
regionOfInterest,
CoordinateReferenceSystem
... sourceCRS)
NAD27
Geographic Like EPSG:4267 except for (
longitude
,
latitude
) axis order
CRS:83
NAD83
Geographic Like EPSG:4269 except for (
longitude
,
latitude
) axis order
CRS:84
WGS84
Geographic Like EPSG:4326 except for (
longitude
,
latitude
) axis order
CRS:88
NAVD88
VerticalNorth American Vertical Datum 1988 height
EPSG:4230
ED50
Geographic European Datum 1950
EPSG:4258
ETRS89
Geographic European Terrestrial Reference System 1989
EPSG:4267
NAD27
Geographic North American Datum 1927
EPSG:4269
NAD83
Geographic North American Datum 1983
EPSG:4322
WGS72
Geographic World Geodetic System 1972
EPSG:4326
WGS84
Geographic World Geodetic System 1984
EPSG:4936
ETRS89
Geocentric European Terrestrial Reference System 1989
EPSG:4937
ETRS89
Geographic 3D European Terrestrial Reference System 1989
EPSG:4978
WGS84
Geocentric World Geodetic System 1984
EPSG:4979
WGS84
Geographic 3D World Geodetic System 1984
EPSG:4984
WGS72
Geocentric World Geodetic System 1972
EPSG:4985
WGS72
Geographic 3D World Geodetic System 1972
EPSG:5041
WGS84
Projected WGS 84 / UPS North (E,N)
EPSG:5042
WGS84
Projected WGS 84 / UPS South (E,N)
EPSG:322##
WGS72
Projected WGS 72 / UTM zone ##N
EPSG:323##
WGS72
Projected WGS 72 / UTM zone ##S
EPSG:326##
WGS84
Projected WGS 84 / UTM zone ##N
EPSG:327##
WGS84
Projected WGS 84 / UTM zone ##S
EPSG:5714
MEAN_SEA_LEVEL
Vertical Mean Sea Level height
EPSG:5715
DEPTH
Vertical Mean Sea Level depth
OGC:JulianDate
JULIAN
Temporal Julian date (days)
OGC:TruncatedJulianDate
TRUNCATED_JULIAN
Temporal Truncated Julian date (days)
OGC:UnixTime
UNIX
Unix Unix time (seconds)
For codes in above table, the EPSG geodetic database is used when available,
otherwise Apache SIS fallbacks on definitions from public sources with no EPSG metadata except the identifiers.
If the EPSG geodetic dataset has been used, the
authority
title
will be something like
"EPSG geodetic dataset"
, otherwise it will be
"Subset of EPSG"
.
"EPSG:4326"
:
"EPSG::4326"
"urn:ogc:def:crs:EPSG::4326"
"http://www.opengis.net/def/crs/epsg/0/4326"
"http://www.opengis.net/gml/srs/epsg.xml#4326"
"urn:ogc:def:crs,crs:EPSG::4326,crs:EPSG::5714"
"http://www.opengis.net/def/crs-compound?
1=http://www.opengis.net/def/crs/epsg/0/4326&
2=http://www.opengis.net/def/crs/epsg/0/5714"
URNs (but not URLs) can also combine a geodetic datum with an ellipsoidal coordinate system for creating a new geographic CRS , or a base geographic CRS with a conversion and a Cartesian coordinate system for creating a new projected coordinate reference system .
IdentifiedObjects.lookupURN(IdentifiedObject, Citation)
method can be seen
as a converse of this method: from a CRS object, it tries to find a URN that describes it.
More codes may also be supported depending on which extension modules are available.
code
- the authority code.
NoSuchAuthorityCodeException
- if there is no known CRS associated to the given code.
FactoryException
- if the CRS creation failed for another reason.
getAuthorityFactory(String)
GeodeticAuthorityFactory
UNIT[…]
and
ORDER[…]
elements have been omitted.
ProjectedCRS["SIRGAS 2000 / Brazil Mercator",
BaseGeodCRS["SIRGAS 2000",
Datum["Sistema de Referencia Geocentrico para las Americas 2000",
Ellipsoid["GRS 1980", 6378137, 298.257222101]]],
Conversion["Petrobras Mercator",
Method["Mercator (variant B)", Id["EPSG",9805]],
Parameter["Latitude of 1st standard parallel", -2],
Parameter["Longitude of natural origin", -43],
Parameter["False easting", 5000000],
Parameter["False northing", 10000000]],
CS[cartesian,2],
Axis["easting (E)", east],
Axis["northing (N)", north],
LengthUnit["metre", 1],
Id["EPSG",5641]]
If the parsing produced warnings, they will be reported in a logger named
"org.apache.sis.io.wkt"
.
In particular, this method verifies if the description provided by the WKT matches the description provided
by the authority (
"EPSG:5641"
in above example) and reports discrepancies.
Note that this comparison between parsed CRS and authoritative CRS is specific to this convenience method;
other APIs documented in
see also
section do not perform this comparison automatically.
Should the WKT description and the authoritative description be in conflict, the WKT description prevails
as mandated by ISO 19162 standard (see
fromAuthority(…)
if a different behavior is needed).
GeodeticObjectFactory.createFromWKT(String)
using a default factory instance. This is okay for occasional use, but has the following limitations:
WKTFormat
class instead of this method.
text
- coordinate system encoded in Well-Known Text format (version 1 or 2).
FactoryException
- if the given WKT cannot be parsed.
WKTFormat
GeodeticObjectFactory.createFromWKT(String)
Envelopes.fromWKT(CharSequence)
XML
class.
If the unmarshalling produced warnings, they will be reported in a logger named
"org.apache.sis.xml"
.
In particular, this method verifies if the description provided by the XML matches the description provided by
the authority code given in
<gml:identifier>
element, and reports discrepancies.
Note that this comparison between unmarshalled CRS and authoritative CRS is specific to this convenience method;
other APIs documented in
see also
section do not perform this comparison automatically.
Should the XML description and the authoritative description be in conflict, the XML description prevails
(see
fromAuthority(…)
if a different behavior is needed).
xml
- coordinate reference system encoded in XML format.
FactoryException
- if the object creation failed.
GeodeticObjectFactory.createFromXML(String)
XML.unmarshal(String)
PROJCS["WGS 84 / Pseudo-Mercator",
(…base CRS omitted for brevity…)
PROJECTION["Mercator (variant A)"],
—
wrong:
shall be "Popular Visualisation Pseudo Mercator"
(…parameters and axes omitted for brevity…)
AUTHORITY["EPSG", "3857"]]
In such cases, Apache SIS behavior in
fromWKT(String)
,
fromXML(String)
and other methods is
conform to the
ISO 19162 specification
:
"Should any attributes or values given in the cited identifier be in conflict with attributes or values given explicitly in the WKT description, the WKT values shall prevail."In situations where the opposite behavior is desired (i.e. to make the authority identifier prevails), this method can be invoked. This method performs the following actions:
fromWKT(String)
and
fromXML(String)
methods. For avoiding this annoyance,
a
null
value for the
warningFilter
argument means to shut off those redundant loggings.
A non-null
warningFilter
argument is more useful for CRS parsed by methods outside this class,
for example
WKTFormat
or
XML.unmarshal(String)
.
crs
- the CRS to replace by an authoritative CRS, or
null
.
factory
- the factory where to search for authoritative definitions, or
null
for the default.
warningFilter
- whether to log warnings, or
null
for the default behavior (which is to filter out
the warnings that are redundant with warnings emitted by other methods in this class).
crs
argument itself), or
null
if the given CRS was null.
FactoryException
- if an error occurred while querying the authority factory.
null
.
suggestCommonTarget(…)
method can used
for choosing a common CRS which is less likely to fail.
regionOfInterest
- the geographic area for which the coordinate operations will be applied,
or
null
if unknown. Will be intersected with CRS domains of validity.
sourceCRS
- the coordinate reference systems for which a common target CRS is desired.
May contain
null
elements, which are ignored.
null
if this method did not find a common target CRS. The returned CRS may be different than
all given CRS.
CoordinateOperationContext
.
CoordinateOperation
instance, the following methods can be invoked
for checking if the operation suits the caller's needs:
getGeographicBoundingBox(CoordinateOperation)
for checking if the operation is valid in the caller's area of interest.
getLinearAccuracy(CoordinateOperation)
for checking if the operation has sufficient accuracy for caller's purpose.
OperationNotFoundException
.
Note that
CRS.findOperation(
B
,
A
,
aoi
)
is not necessarily
the exact converse of
CRS.findOperation(
A
,
B
,
aoi
)
.
Some deviations may exist for example because of different paths explored in the geodetic database.
For the inverse of an existing
CoordinateOperation
, using
MathTransform.inverse()
is preferable.
sourceCRS
- the CRS of source coordinates.
targetCRS
- the CRS of target coordinates.
areaOfInterest
- the area of interest, or
null
if none.
sourceCRS
to
targetCRS
.
OperationNotFoundException
- if no operation was found between the given pair of CRS.
FactoryException
- if the operation cannot be created for another reason.
Envelopes.findOperation(Envelope, Envelope)
DefaultCoordinateOperationFactory.createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem, CoordinateOperationContext)
sourceCRS
- the CRS of source coordinates.
targetCRS
- the CRS of target coordinates.
areaOfInterest
- the area of interest, or
null
if none.
sourceCRS
to
targetCRS
.
OperationNotFoundException
- if no operation was found between the given pair of CRS.
FactoryException
- if the operation cannot be created for another reason.
DefaultCoordinateOperationFactory.createOperations(CoordinateReferenceSystem, CoordinateReferenceSystem, CoordinateOperationContext)
NaN
if unknown.
This method applies the following heuristics:
AbstractCoordinateOperation
, then delegate to the
operation
getLinearAccuracy()
method.
AbstractCoordinateOperation.getLinearAccuracy()
for more details on the above heuristic rules.
operation
- the coordinate operation for which to get the accuracy estimation, or
null
.
findOperation(CoordinateReferenceSystem, CoordinateReferenceSystem, GeographicBoundingBox)
null
if unknown.
This method explores the
domain of validity
associated with the given operation. If more than one geographic bounding box is found, then this method
computes their
union
.
Fallback:
if the given operation does not declare explicitly a domain of validity, then this
method computes the intersection of the domain of validity declared by source and target CRS. If no CRS
declare a domain of validity, then this method returns
null
.
operation
- the coordinate operation for which to get the domain of validity, or
null
.
null
if unspecified.
findOperation(CoordinateReferenceSystem, CoordinateReferenceSystem, GeographicBoundingBox)
Extents.getGeographicBoundingBox(Extent)
null
if unknown.
This method explores the
domain of
validity
associated with the given CRS. If more than one geographic bounding box is found, then this method
computes their
union
.
together.
crs
- the coordinate reference system for which to get the domain of validity, or
null
.
null
if unspecified.
getDomainOfValidity(CoordinateReferenceSystem)
Extents.getGeographicBoundingBox(Extent)
null
if unknown.
If non-null, then the returned envelope will use the same coordinate reference system than the given CRS
argument.
crs
- the coordinate reference system, or
null
.
null
if none.
getGeographicBoundingBox(CoordinateReferenceSystem)
getVerticalComponent
(crs, true)
.
GeographicCRS
or
ProjectedCRS
or
EngineeringCRS
).
VerticalCRS
or a
ParametricCRS
(but not both).
TemporalCRS
.
components
- the sequence of coordinate reference systems making the compound CRS.
components[0]
if the given array contains only one component.
IllegalArgumentException
- if the given array is empty or if the array contains incompatible components.
FactoryException
- if the geodetic factory failed to create the compound CRS.
DefaultCompoundCRS
GeodeticObjectFactory.createCompoundCRS(Map, CoordinateReferenceSystem...)
Envelopes.compound(Envelope...)
MathTransforms.compound(MathTransform...)
compound(CoordinateReferenceSystem...)
.
This method can also extract the
ellipsoidal height
from a three-dimensional geographic CRS, but this is generally not recommended since ellipsoidal
heights make little sense without their (
latitude
,
longitude
) locations.
crs
- the CRS to reduce the dimensionality, or
null
if none.
dimensions
- the dimensions to retain. The dimensions will be taken in increasing order, ignoring duplicated values.
crs
, which may be
null
.
IllegalArgumentException
- if the given array is empty or if the array contains invalid indices.
FactoryException
- if the geodetic factory failed to create a compound CRS.
getComponentAt(CoordinateReferenceSystem, int, int)
compound(CoordinateReferenceSystem...)
selectDimensions(CoordinateReferenceSystem, int...)
for clarity and consistency with
GridExtent
and
GridGeometry
.
crs
- the CRS to reduce the dimensionality.
dimensions
- the dimensions to retain.
FactoryException
- if the geodetic factory failed to create a compound CRS.
true
if the given CRS is horizontal. The current implementation considers a
CRS as horizontal if it is two-dimensional and comply with one of the following conditions:
GeographicCRS
(or an equivalent
GeodeticCRS
), or
ProjectedCRS
, or
EngineeringCRS
(following
ISO 19162 §16.1
definition of <horizontal crs>).
false
.
crs
- the coordinate reference system, or
null
.
true
if the given CRS is non-null and likely horizontal, or
false
otherwise.
getHorizontalComponent(CoordinateReferenceSystem)
DerivedCRS
instance based on a projected CRS.
Conversely, a future SIS versions may impose more conditions on
EngineeringCRS
.
See
SIS-161
.
null
if there is
none. If the given CRS is already horizontal according
isHorizontalCRS(CoordinateReferenceSystem)
,
then this method returns it as-is. Otherwise if the given CRS is compound, then this method searches for the
first horizontal component in the order of the
single components list
.
In the special case where a three-dimensional geographic or projected CRS is found, this method will create a two-dimensional geographic or projected CRS without the vertical axis.
crs
- the coordinate reference system, or
null
.
null
if none.
GeneralEnvelope.horizontal()
null
if there is none.
If the given CRS is already an instance of
VerticalCRS
, then this method returns it as-is.
Otherwise if the given CRS is compound, then this method searches for the first vertical component
in the order of the
single components list
.
null
when asked for the
VerticalCRS
component of a geographic CRS. This is what
getVerticalComponent(…)
does when the
allowCreateEllipsoidal
argument is
false
.
However, in some exceptional cases, handling ellipsoidal heights like any other kind of heights
may simplify the task. For example, when computing
difference
between heights above the
same datum, the impact of ignoring locations may be smaller (but not necessarily canceled).
Orphan
VerticalCRS
may also be useful for information purpose like labeling a plot axis.
If the caller feels confident that ellipsoidal heights are safe for his task, he can set the
allowCreateEllipsoidal
argument to
true
. In such case, this
getVerticalComponent(…)
method will create a temporary
VerticalCRS
from the first three-dimensional
GeographicCRS
in last resort
, only if it cannot find an existing
VerticalCRS
instance.
Note that this is not a valid CRS according ISO 19111
— use with care.
crs
- the coordinate reference system, or
null
.
allowCreateEllipsoidal
-
true
for allowing the creation of orphan CRS for ellipsoidal heights.
The recommended value is
false
.
null
if none.
compound(CoordinateReferenceSystem...)
null
if there is none.
If the given CRS is already an instance of
TemporalCRS
, then this method returns it as-is.
Otherwise if the given CRS is compound, then this method searches for the first temporal component
in the order of the
single components list
.
crs
- the coordinate reference system, or
null
.
null
if none.
SingleCRS
, returns that instance in a singleton list.
CompoundCRS
, returns a flattened list of its
components
. Some components may themselves be
other
CompoundCRS
instances, in which case those compound CRS are also flattened in their
list of
SingleCRS
components.
ClassCastException
.
Hierarchical structure
CompoundCRS
— (
x
,
y
,
z
,
t
)
├─CompoundCRS
— (
x
,
y
,
z
)
│ ├─ProjectedCRS
— (
x
,
y
)
│ └─VerticalCRS
— (
z
)
└─TemporalCRS
— (
t
)
Flat list
CompoundCRS
— (
x
,
y
,
z
,
t
)
├─ProjectedCRS
— (
x
,
y
)
├─VerticalCRS
— (
z
)
└─TemporalCRS
— (
t
)
This method guaranteed that the returned list is a flat one as shown on the right side.
Note that such flat lists are the only one allowed by ISO/OGC standards for compound CRS.
The hierarchical structure is an Apache SIS flexibility.
crs
- the coordinate reference system, or
null
.
null
.
ClassCastException
- if a CRS is neither a
SingleCRS
or a
CompoundCRS
.
DefaultCompoundCRS.getSingleComponents()
crs
is
null
, then this method returns
null
.
lower
is 0 and
upper
is the number of CRS dimensions,
then this method returns the given CRS unchanged.
CompoundCRS
, then this method
searches for a
component
where:
upper - lower
;
lower
.
null
.
CompoundCRS
or a three-dimensional CRS if the given range spans more than one component.
crs
- the coordinate reference system to decompose, or
null
.
lower
- the first dimension to keep, inclusive.
upper
- the last dimension to keep, exclusive.
null
if the given
crs
was
null
or cannot be decomposed for dimensions in the [
lower
…
upper
] range.
IndexOutOfBoundsException
- if the given index are out of bounds.
selectDimensions(CoordinateReferenceSystem, int[])
GeneralEnvelope.subEnvelope(int, int)
crs
- the coordinate reference system from which to get the prime meridian.
DefaultPrimeMeridian.getGreenwichLongitude(Unit)
forCode(String)
and other SIS methods.
If the given authority is non-null, then this method returns a factory specifically for that authority.
Otherwise, this method returns the
MultiAuthoritiesFactory
instance that manages all other factories.
The
authority
argument can be
"EPSG"
,
"OGC"
or any other authority found
on the classpath. In the
"EPSG"
case, whether the full set of EPSG codes is supported or not
depends on whether a
connection to the database
can be established. If no connection can be established, then this method returns a small embedded
EPSG factory containing at least the CRS defined in the
forCode(String)
method javadoc.
User-defined authorities can be added to the SIS environment by creating a
CRSAuthorityFactory
implementation with a public no-argument constructor, and declaring the fully-qualified name of that class
in a file at the following location:
META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
authority
- the authority of the desired factory (typically
"EPSG"
or
"OGC"
),
or
null
for the
MultiAuthoritiesFactory
instance that manage all factories.
FactoryException
- if no factory can be returned for the given authority.
forCode(String)
MultiAuthoritiesFactory
selectDimensions(CoordinateReferenceSystem, int...)for clarity and consistency withGridExtentandGridGeometry.