Search in sources :

Example 1 with CSFactory

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;
}
Also used : CartesianCS(org.opengis.referencing.cs.CartesianCS) DatumFactory(org.opengis.referencing.datum.DatumFactory) CSFactory(org.opengis.referencing.cs.CSFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentifiedObject(org.opengis.referencing.IdentifiedObject) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 2 with CSFactory

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);
}
Also used : CSFactory(org.opengis.referencing.cs.CSFactory) EllipsoidalHeightCombiner(org.apache.sis.internal.metadata.EllipsoidalHeightCombiner) DefaultCoordinateOperationFactory(org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory) CoordinateOperationFactory(org.opengis.referencing.operation.CoordinateOperationFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CRSFactory(org.opengis.referencing.crs.CRSFactory)

Example 3 with CSFactory

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);
    }
}
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

CSFactory (org.opengis.referencing.cs.CSFactory)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 EllipsoidalHeightCombiner (org.apache.sis.internal.metadata.EllipsoidalHeightCombiner)1 CommonCRS (org.apache.sis.referencing.CommonCRS)1 DefaultCoordinateOperationFactory (org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 CRSFactory (org.opengis.referencing.crs.CRSFactory)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 TemporalCRS (org.opengis.referencing.crs.TemporalCRS)1 CartesianCS (org.opengis.referencing.cs.CartesianCS)1 TimeCS (org.opengis.referencing.cs.TimeCS)1 DatumFactory (org.opengis.referencing.datum.DatumFactory)1 TemporalDatum (org.opengis.referencing.datum.TemporalDatum)1 CoordinateOperationFactory (org.opengis.referencing.operation.CoordinateOperationFactory)1 InternationalString (org.opengis.util.InternationalString)1