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