use of org.opengis.referencing.cs.CSFactory in project sis by apache.
the class CommonAuthorityFactory method displayCRS.
/**
* Returns the "Computer display" reference system (CRS:1). This is rarely used.
*/
private synchronized CoordinateReferenceSystem displayCRS() throws FactoryException {
if (displayCRS == null) {
final CSFactory csFactory = DefaultFactories.forBuildin(CSFactory.class);
final CartesianCS cs = csFactory.createCartesianCS(Collections.singletonMap(CartesianCS.NAME_KEY, "Computer display"), csFactory.createCoordinateSystemAxis(Collections.singletonMap(CartesianCS.NAME_KEY, "i"), "i", AxisDirection.EAST, Units.PIXEL), csFactory.createCoordinateSystemAxis(Collections.singletonMap(CartesianCS.NAME_KEY, "j"), "j", AxisDirection.SOUTH, Units.PIXEL));
final Map<String, Object> properties = new HashMap<>(4);
properties.put(EngineeringDatum.NAME_KEY, cs.getName());
properties.put(EngineeringDatum.ANCHOR_POINT_KEY, "Origin is in upper left.");
displayCRS = DefaultFactories.forBuildin(CRSFactory.class).createEngineeringCRS(properties, DefaultFactories.forBuildin(DatumFactory.class).createEngineeringDatum(properties), cs);
}
return displayCRS;
}
use of org.opengis.referencing.cs.CSFactory 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);
}
use of org.opengis.referencing.cs.CSFactory in project sis by apache.
the class GeodeticObjectBuilder method createTemporalCRS.
/**
* Creates a temporal CRS from the given origin and temporal unit. For this method, the CRS name is optional:
* if no {@code addName(…)} method has been invoked, then a default name will be used.
*
* @param origin the epoch in milliseconds since January 1st, 1970 at midnight UTC.
* @param unit the unit of measurement.
* @return a temporal CRS using the given origin and units.
* @throws FactoryException if an error occurred while building the temporal CRS.
*/
public TemporalCRS createTemporalCRS(final Date origin, final Unit<Time> unit) throws FactoryException {
/*
* Try to use one of the pre-defined datum and coordinate system if possible.
* This not only saves a little bit of memory, but also provides better names.
*/
TimeCS cs = null;
TemporalDatum datum = null;
for (final CommonCRS.Temporal c : CommonCRS.Temporal.values()) {
if (datum == null) {
final TemporalDatum candidate = c.datum();
if (origin.equals(candidate.getOrigin())) {
datum = candidate;
}
}
if (cs == null) {
final TemporalCRS crs = c.crs();
final TimeCS candidate = crs.getCoordinateSystem();
if (unit.equals(candidate.getAxis(0).getUnit())) {
if (datum == candidate && properties.isEmpty()) {
return crs;
}
cs = candidate;
}
}
}
/*
* Create the datum and coordinate system before the CRS if we were not able to use a pre-defined object.
* In the datum case, we will use the same metadata than the CRS (domain of validity, scope, etc.) except
* the identifier and the remark.
*/
onCreate(false);
try {
if (cs == null) {
final CSFactory csFactory = getCSFactory();
// To be used as a template, except for units.
cs = CommonCRS.Temporal.JAVA.crs().getCoordinateSystem();
cs = csFactory.createTimeCS(name(cs), csFactory.createCoordinateSystemAxis(name(cs.getAxis(0)), "t", AxisDirection.FUTURE, unit));
}
if (properties.get(TemporalCRS.NAME_KEY) == null) {
properties.putAll(name(cs));
}
if (datum == null) {
final Object remarks = properties.remove(TemporalCRS.REMARKS_KEY);
final Object identifier = properties.remove(TemporalCRS.IDENTIFIERS_KEY);
datum = getDatumFactory().createTemporalDatum(properties, origin);
properties.put(TemporalCRS.IDENTIFIERS_KEY, identifier);
properties.put(TemporalCRS.REMARKS_KEY, remarks);
// Share the Identifier instance.
properties.put(TemporalCRS.NAME_KEY, datum.getName());
}
return getCRSFactory().createTemporalCRS(properties, datum, cs);
} finally {
onCreate(true);
}
}
Aggregations