Search in sources :

Example 1 with TimeCS

use of org.opengis.referencing.cs.TimeCS 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);
    }
}
Also used : TemporalDatum(org.opengis.referencing.datum.TemporalDatum) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) CSFactory(org.opengis.referencing.cs.CSFactory) IdentifiedObject(org.opengis.referencing.IdentifiedObject) CommonCRS(org.apache.sis.referencing.CommonCRS) TimeCS(org.opengis.referencing.cs.TimeCS)

Aggregations

CommonCRS (org.apache.sis.referencing.CommonCRS)1 IdentifiedObject (org.opengis.referencing.IdentifiedObject)1 TemporalCRS (org.opengis.referencing.crs.TemporalCRS)1 CSFactory (org.opengis.referencing.cs.CSFactory)1 TimeCS (org.opengis.referencing.cs.TimeCS)1 TemporalDatum (org.opengis.referencing.datum.TemporalDatum)1