use of org.apache.sis.internal.metadata.EllipsoidalHeightCombiner in project sis by apache.
the class GeodeticObjectParser method parseCompoundCRS.
/**
* Parses a {@code "CompoundCRS"} element. The syntax is given by
* <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#110">WKT 2 specification ยง16</a>.
*
* The legacy WKT 1 specification was:
*
* {@preformat wkt
* COMPD_CS["<name>", <head cs>, <tail cs> {,<authority>}]
* }
*
* In the particular case where there is a geographic CRS and an ellipsoidal height,
* this method rather build a three-dimensional geographic CRS.
*
* @param mode {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
* @param parent the parent element.
* @return the {@code "CompoundCRS"} element as a {@link CompoundCRS} object.
* @throws ParseException if the {@code "CompoundCRS"} element can not be parsed.
*/
private CoordinateReferenceSystem parseCompoundCRS(final int mode, final Element parent) throws ParseException {
final Element element = parent.pullElement(mode, WKTKeywords.CompoundCRS, WKTKeywords.Compd_CS);
if (element == null) {
return null;
}
final String name = element.pullString("name");
CoordinateReferenceSystem crs;
final List<CoordinateReferenceSystem> components = new ArrayList<>(4);
while ((crs = parseCoordinateReferenceSystem(element, components.size() < 2)) != null) {
components.add(crs);
}
try {
return new EllipsoidalHeightCombiner(crsFactory, csFactory, opFactory).createCompoundCRS(parseMetadataAndClose(element, name, null), components.toArray(new CoordinateReferenceSystem[components.size()]));
} catch (FactoryException exception) {
throw element.parseFailed(exception);
}
}
use of org.apache.sis.internal.metadata.EllipsoidalHeightCombiner in project sis by apache.
the class CRS method compound.
/**
* Creates a compound coordinate reference system from an ordered list of CRS components.
* A CRS is inferred from the given components and the domain of validity is set to the
* {@linkplain org.apache.sis.metadata.iso.extent.DefaultExtent#intersect intersection}
* of the domain of validity of all components.
*
* <div class="section">Ellipsoidal height</div>
* If a two-dimensional geographic or projected CRS if followed or preceded by a vertical CRS with ellipsoidal
* {@linkplain org.apache.sis.referencing.datum.DefaultVerticalDatum#getVerticalDatumType() datum type}, then
* this method combines them in a single three-dimensional geographic or projected CRS. Note that standalone
* ellipsoidal heights are not allowed according ISO 19111. But if such situation is nevertheless found, then
* the action described here fixes the issue. This is the reverse of <code>{@linkplain #getVerticalComponent
* getVerticalComponent}(crs, true)</code>.
*
* <div class="section">Components order</div>
* Apache SIS is permissive on the order of components that can be used in a compound CRS.
* However for better inter-operability, users are encouraged to follow the order mandated by ISO 19162:
*
* <ol>
* <li>A mandatory horizontal CRS (only one of two-dimensional {@code GeographicCRS} or {@code ProjectedCRS} or {@code EngineeringCRS}).</li>
* <li>Optionally followed by a {@code VerticalCRS} or a {@code ParametricCRS} (but not both).</li>
* <li>Optionally followed by a {@code TemporalCRS}.</li>
* </ol>
*
* @param components the sequence of coordinate reference systems making the compound CRS.
* @return the compound CRS, or {@code components[0]} if the given array contains only one component.
* @throws IllegalArgumentException if the given array is empty or if the array contains incompatible components.
* @throws FactoryException if the geodetic factory failed to create the compound CRS.
*
* @since 0.8
*
* @see GeodeticObjectFactory#createCompoundCRS(Map, CoordinateReferenceSystem...)
*/
public static CoordinateReferenceSystem compound(final CoordinateReferenceSystem... components) throws FactoryException {
ArgumentChecks.ensureNonNull("components", components);
switch(components.length) {
case 0:
{
throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1, "components"));
}
case 1:
{
final CoordinateReferenceSystem crs = components[0];
if (crs != null)
return crs;
break;
}
}
final Map<String, ?> properties = EllipsoidalHeightCombiner.properties(components);
return new EllipsoidalHeightCombiner() {
@Override
public void initialize(final int factoryTypes) {
if ((factoryTypes & CRS) != 0)
crsFactory = DefaultFactories.forBuildin(CRSFactory.class);
if ((factoryTypes & CS) != 0)
csFactory = DefaultFactories.forBuildin(CSFactory.class);
if ((factoryTypes & OPERATION) != 0)
opFactory = DefaultFactories.forBuildin(CoordinateOperationFactory.class);
}
}.createCompoundCRS(properties, components);
}
Aggregations