Search in sources :

Example 11 with CoordinateSystemAxis

use of org.opengis.referencing.cs.CoordinateSystemAxis in project sis by apache.

the class Normalizer method shiftAxisRange.

/**
 * Returns a coordinate system with the same axes than the given CS, except that the wrapround axes
 * are shifted to a range of positive values. This method can be used in order to shift between the
 * [-180 … +180]° and [0 … 360]° ranges of longitude values.
 *
 * <p>This method shifts the axis {@linkplain CoordinateSystemAxis#getMinimumValue() minimum} and
 * {@linkplain CoordinateSystemAxis#getMaximumValue() maximum} values by a multiple of half the range
 * (typically 180°). This method does not change the meaning of ordinate values. For example a longitude
 * of -60° still locate the same point in the old and the new coordinate system. But the preferred way
 * to locate that point become the 300° value if the longitude range has been shifted to positive values.</p>
 *
 * @return a coordinate system using the given kind of longitude range, or {@code null} if no change is needed.
 */
private static AbstractCS shiftAxisRange(final CoordinateSystem cs) {
    boolean changed = false;
    final CoordinateSystemAxis[] axes = new CoordinateSystemAxis[cs.getDimension()];
    for (int i = 0; i < axes.length; i++) {
        CoordinateSystemAxis axis = cs.getAxis(i);
        final RangeMeaning rangeMeaning = axis.getRangeMeaning();
        if (RangeMeaning.WRAPAROUND.equals(rangeMeaning)) {
            double min = axis.getMinimumValue();
            if (min < 0) {
                double max = axis.getMaximumValue();
                double offset = (max - min) / 2;
                offset *= Math.floor(min / offset + 1E-10);
                min -= offset;
                max -= offset;
                if (min < max) {
                    // Paranoiac check, but also a way to filter NaN values when offset is infinite.
                    final Map<String, Object> properties = new HashMap<>();
                    properties.putAll(IdentifiedObjects.getProperties(axis, EXCLUDES));
                    properties.put(DefaultCoordinateSystemAxis.MINIMUM_VALUE_KEY, min);
                    properties.put(DefaultCoordinateSystemAxis.MAXIMUM_VALUE_KEY, max);
                    properties.put(DefaultCoordinateSystemAxis.RANGE_MEANING_KEY, rangeMeaning);
                    axis = new DefaultCoordinateSystemAxis(properties, axis.getAbbreviation(), axis.getDirection(), axis.getUnit());
                    changed = true;
                }
            }
        }
        axes[i] = axis;
    }
    if (!changed) {
        return null;
    }
    return castOrCopy(cs).createForAxes(IdentifiedObjects.getProperties(cs, EXCLUDES), axes);
}
Also used : RangeMeaning(org.opengis.referencing.cs.RangeMeaning) HashMap(java.util.HashMap) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis)

Example 12 with CoordinateSystemAxis

use of org.opengis.referencing.cs.CoordinateSystemAxis in project sis by apache.

the class StandardDefinitions method createCoordinateSystem.

/**
 * Creates a coordinate system from hard-coded values for the given code.
 * The coordinate system names used by this method contains only the first
 * part of the names declared in the EPSG database.
 *
 * @param  code  the EPSG code.
 * @return the coordinate system for the given code.
 */
@SuppressWarnings("fallthrough")
static CoordinateSystem createCoordinateSystem(final short code) {
    final String name;
    // 0= Cartesian (default), 1= Spherical, 2= Ellipsoidal
    int type = 0;
    // Number of dimension, default to 2.
    int dim = 2;
    // Code of first axis + dim (or code after the last axis).
    short axisCode;
    switch(code) {
        case 6422:
            name = "Ellipsoidal 2D";
            type = 2;
            axisCode = 108;
            break;
        case 6423:
            name = "Ellipsoidal 3D";
            type = 2;
            dim = 3;
            axisCode = 111;
            break;
        case 6404:
            name = "Spherical";
            type = 1;
            dim = 3;
            axisCode = 63;
            break;
        case 6500:
            name = "Earth centred";
            dim = 3;
            axisCode = 118;
            break;
        case 4400:
            name = "Cartesian 2D";
            axisCode = 3;
            break;
        case 1026:
            name = "Cartesian 2D for UPS north";
            axisCode = 1067;
            break;
        case 1027:
            name = "Cartesian 2D for UPS south";
            axisCode = 1059;
            break;
        default:
            throw new AssertionError(code);
    }
    final Map<String, ?> properties = properties(code, name, null, false);
    CoordinateSystemAxis xAxis = null, yAxis = null, zAxis = null;
    switch(dim) {
        default:
            throw new AssertionError(dim);
        case 3:
            zAxis = createAxis(--axisCode);
        case 2:
            yAxis = createAxis(--axisCode);
        case 1:
            xAxis = createAxis(--axisCode);
        case 0:
            break;
    }
    switch(type) {
        default:
            throw new AssertionError(type);
        case 0:
            return (zAxis != null) ? new DefaultCartesianCS(properties, xAxis, yAxis, zAxis) : new DefaultCartesianCS(properties, xAxis, yAxis);
        case 1:
            return new DefaultSphericalCS(properties, xAxis, yAxis, zAxis);
        case 2:
            return (zAxis != null) ? new DefaultEllipsoidalCS(properties, xAxis, yAxis, zAxis) : new DefaultEllipsoidalCS(properties, xAxis, yAxis);
    }
}
Also used : DefaultSphericalCS(org.apache.sis.referencing.cs.DefaultSphericalCS) DefaultCartesianCS(org.apache.sis.referencing.cs.DefaultCartesianCS) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) DefaultCoordinateSystemAxis(org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis) DefaultEllipsoidalCS(org.apache.sis.referencing.cs.DefaultEllipsoidalCS)

Example 13 with CoordinateSystemAxis

use of org.opengis.referencing.cs.CoordinateSystemAxis in project sis by apache.

the class CoordinateSystems method getAxisDirections.

/**
 * Returns the axis directions for the specified coordinate system.
 * This method guarantees that the returned array is non-null and does not contain any null direction.
 *
 * @param  cs  the coordinate system.
 * @return the axis directions for the specified coordinate system.
 * @throws NullArgumentException if {@code cs} is null, or one of its axes is null,
 *         or a value returned by {@link CoordinateSystemAxis#getDirection()} is null.
 *
 * @since 0.8
 */
public static AxisDirection[] getAxisDirections(final CoordinateSystem cs) {
    ensureNonNull("cs", cs);
    final AxisDirection[] directions = new AxisDirection[cs.getDimension()];
    for (int i = 0; i < directions.length; i++) {
        final CoordinateSystemAxis axis = cs.getAxis(i);
        ensureNonNullElement("cs", i, cs);
        ensureNonNullElement("cs[#].direction", i, directions[i] = axis.getDirection());
    }
    return directions;
}
Also used : AxisDirection(org.opengis.referencing.cs.AxisDirection) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis)

Example 14 with CoordinateSystemAxis

use of org.opengis.referencing.cs.CoordinateSystemAxis in project sis by apache.

the class DefaultCompoundCS method getAxes.

/**
 * Returns all axes in the given sequence of components.
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
private static CoordinateSystemAxis[] getAxes(final CoordinateSystem[] components) {
    int count = 0;
    for (int i = 0; i < components.length; i++) {
        count += components[i].getDimension();
    }
    final CoordinateSystemAxis[] axis = new CoordinateSystemAxis[count];
    count = 0;
    for (final CoordinateSystem c : components) {
        final int dim = c.getDimension();
        for (int j = 0; j < dim; j++) {
            axis[count++] = c.getAxis(j);
        }
    }
    assert count == axis.length;
    return axis;
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis)

Example 15 with CoordinateSystemAxis

use of org.opengis.referencing.cs.CoordinateSystemAxis in project sis by apache.

the class AbstractEnvelope method getSpan.

/**
 * Returns the envelope span along the specified dimension, in terms of the given units.
 * The default implementation invokes {@link #getSpan(int)} and converts the result.
 *
 * @param  dimension  the dimension to query.
 * @param  unit  the unit for the return value.
 * @return the span in terms of the given unit.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws IncommensurableException if the length can't be converted to the specified units.
 */
public double getSpan(final int dimension, final Unit<?> unit) throws IndexOutOfBoundsException, IncommensurableException {
    double value = getSpan(dimension);
    final CoordinateSystemAxis axis = getAxis(getCoordinateReferenceSystem(), dimension);
    if (axis != null) {
        final Unit<?> source = axis.getUnit();
        if (source != null) {
            value = source.getConverterToAny(unit).convert(value);
        }
    }
    return value;
}
Also used : CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis)

Aggregations

CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)50 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)15 Test (org.junit.Test)14 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)9 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)5 Unit (javax.measure.Unit)4 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)4 AxisDirection (org.opengis.referencing.cs.AxisDirection)4 FactoryException (org.opengis.util.FactoryException)4 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 VerticalCS (org.opengis.referencing.cs.VerticalCS)3 InternationalString (org.opengis.util.InternationalString)3 DefaultVerticalCRS (org.apache.sis.referencing.crs.DefaultVerticalCRS)2 DefaultCoordinateSystemAxis (org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis)2 DefaultVerticalCS (org.apache.sis.referencing.cs.DefaultVerticalCS)2 AbstractCoordinateOperation (org.apache.sis.referencing.operation.AbstractCoordinateOperation)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Identifier (org.opengis.metadata.Identifier)2 VerticalExtent (org.opengis.metadata.extent.VerticalExtent)2 GeodeticCRS (org.opengis.referencing.crs.GeodeticCRS)2