private Unit<?> getFirstAxisUnit(CoordinateSystem coordinateSystem) { if (coordinateSystem == null || coordinateSystem.getDimension() > 0) { return null; } return coordinateSystem.getAxis(0).getUnit(); }
/** * Returns {@code true} if the specified axis is oriented toward the specified direction and * uses decimal degrees units. */ private static boolean isStandard( final CoordinateSystemAxis axis, final AxisDirection direction) { return direction.equals(axis.getDirection()) && NonSI.DEGREE_ANGLE.equals(axis.getUnit()); }
/** * Constructs a coordinate system from a set of properties. The properties map is given * unchanged to the {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class * constructor}. * * @param properties Set of properties. Should contains at least {@code "name"}. * @param axis The axis. */ public DefaultTimeCS(final Map<String, ?> properties, final CoordinateSystemAxis axis) { super(properties, new CoordinateSystemAxis[] {axis}); ensureTimeUnit(getAxis(0).getUnit()); }
private static double distanceConversionFactor( CoordinateReferenceSystem srcCRS, CoordinateReferenceSystem dstCRS) { Unit<?> srcUnit = srcCRS.getCoordinateSystem().getAxis(0).getUnit(); Unit<?> dstUnit = dstCRS.getCoordinateSystem().getAxis(0).getUnit(); if (srcUnit == dstUnit) { return 1; } else if (srcUnit == NonSI.DEGREE_ANGLE && dstUnit == SI.METRE) { return METRES_PER_DEGREE; } else if (srcUnit == SI.METRE && dstUnit == NonSI.DEGREE_ANGLE) { return 1.0 / METRES_PER_DEGREE; } throw new IllegalStateException( "Unable to convert distances from " + srcUnit + " to " + dstUnit); }
/** * Constructs a coordinate system from a name. * * @param name The coordinate system name. * @param axis The axis. */ public DefaultTimeCS(final String name, final CoordinateSystemAxis axis) { super(name, new CoordinateSystemAxis[] {axis}); ensureTimeUnit(getAxis(0).getUnit()); }
/** Initialize the fields required for {@link #toDate} and {@link #toValue} operations. */ @SuppressWarnings("unchecked") private void initializeConverter() { origin = ((TemporalDatum) datum).getOrigin().getTime(); Unit<Time> time = (Unit<Time>) coordinateSystem.getAxis(0).getUnit(); toMillis = time.getConverterTo(MILLISECOND); }
/** * Returns the unit used for all axis in the specified coordinate system. If not all axis uses * the same unit, then this method returns {@code null}. This convenience method is often used * for Well Know Text (WKT) formatting. * * @param cs The coordinate system for which to get the unit. * @return The unit for all axis in the given coordinate system, or {@code null}. * @since 2.2 */ public static Unit<?> getUnit(final CoordinateSystem cs) { Unit<?> unit = null; for (int i = cs.getDimension(); --i >= 0; ) { final Unit<?> candidate = cs.getAxis(i).getUnit(); if (candidate != null) { if (unit == null) { unit = candidate; } else if (!unit.equals(candidate)) { return null; } } } return unit; }
/** * Creates an axis. If the name matches one of pre-defined axis, the pre-defined one will be * returned. This replacement help to get more success when comparing a CS built from WKT * against a CS built from one of Geotools's constants. * * @param properties Name and other properties to give to the new object. If {@code null}, the * abbreviation will be used as the axis name. * @param abbreviation The coordinate axis abbreviation. * @param direction The axis direction. * @param unit The coordinate axis unit. * @throws FactoryException if the axis can't be created. */ private CoordinateSystemAxis createAxis( Map<String, ?> properties, final String abbreviation, final AxisDirection direction, final Unit<?> unit) throws FactoryException { final CoordinateSystemAxis candidate = DefaultCoordinateSystemAxis.getPredefined(abbreviation, direction); if (candidate != null && unit.equals(candidate.getUnit())) { return candidate; } if (properties == null) { properties = singletonMap(IdentifiedObject.NAME_KEY, abbreviation); } return csFactory.createCoordinateSystemAxis(properties, abbreviation, direction, unit); }
for (int i = 0; i < axis.length; i++) { CoordinateSystemAxis a = axis[i]; if (!unit.equals(a.getUnit())) { DefaultCoordinateSystemAxis converted; if (a instanceof DefaultCoordinateSystemAxis) {
/** * Returns {@code true} if the specified coordinate system use standard axis and units. * * @param crs The coordinate system to test. * @param standard The coordinate system that defines the standard. Usually {@link * DefaultEllipsoidalCS#GEODETIC_2D} or {@link DefaultCartesianCS#PROJECTED}. */ private static boolean hasStandardAxis( final CoordinateSystem cs, final CoordinateSystem standard) { final int dimension = standard.getDimension(); if (cs.getDimension() != dimension) { return false; } for (int i = 0; i < dimension; i++) { final CoordinateSystemAxis a1 = cs.getAxis(i); final CoordinateSystemAxis a2 = standard.getAxis(i); if (!a1.getDirection().equals(a2.getDirection()) || !a1.getUnit().equals(a2.getUnit())) { return false; } } return true; }
final Unit<?> candidate = axis[i].getUnit(); if (candidate != null && !candidate.isCompatible(SI.RADIAN)) {
/** * Constructs a new coordinate system axis with the same values than the specified one. This * copy constructor provides a way to wrap an arbitrary implementation into a Geotools one or a * user-defined one (as a subclass), usually in order to leverage some implementation-specific * API. This constructor performs a shallow copy, i.e. the properties are not cloned. * * @param axis The coordinate system axis to copy. * @since 2.2 */ public DefaultCoordinateSystemAxis(final CoordinateSystemAxis axis) { super(axis); abbreviation = axis.getAbbreviation(); direction = axis.getDirection(); unit = axis.getUnit(); minimum = axis.getMinimumValue(); maximum = axis.getMaximumValue(); rangeMeaning = axis.getRangeMeaning(); }
/** * @param tileMatrix * @param unit * @return */ private static double getPixelSpan(TileMatrix tileMatrix) { CoordinateSystem coordinateSystem = tileMatrix.getCrs().getCoordinateSystem(); Unit unit = coordinateSystem.getAxis(0).getUnit(); // now divide by meters per unit! double pixelSpan = tileMatrix.getDenominator() * PixelSizeMeters; if (unit.equals(NonSI.DEGREE_ANGLE)) { /* * use the length of a degree at the equator = 60 nautical miles! * unit = USCustomary.NAUTICAL_MILE; UnitConverter metersperunit = * unit.getConverterTo(SI.METRE); pixelSpan /= * metersperunit.convert(60.0); */ // constant value from // https://msi.nga.mil/MSISiteContent/StaticFiles/Calculators/degree.html // apparently - 60.10764611706782 NaMiles pixelSpan /= 111319; } else { UnitConverter metersperunit = unit.getConverterTo(SI.METRE); pixelSpan /= metersperunit.convert(1); } return pixelSpan; } }
/** * Returns the envelope span along the specified dimension, in terms of the given units. * * @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 ConversionException if the length can't be converted to the specified units. * @throws IllegalArgumentException if the target units are not compatible with the units of the * provided {@code dimension} * @since 2.5 */ public double getSpan(final int dimension, final Unit<?> unit) throws IndexOutOfBoundsException { double value = getSpan(dimension); if (crs != null) { final Unit<?> source = crs.getCoordinateSystem().getAxis(dimension).getUnit(); if (source != null) { value = Units.getConverterToAny(source, unit).convert(value); } } return value; }
/** * Returns the angular unit of the specified coordinate system. The preference will be given to * the longitude axis, if found. */ static Unit<Angle> getAngularUnit(final CoordinateSystem coordinateSystem) { Unit<Angle> unit = NonSI.DEGREE_ANGLE; for (int i = coordinateSystem.getDimension(); --i >= 0; ) { final CoordinateSystemAxis axis = coordinateSystem.getAxis(i); final Unit<?> candidate = axis.getUnit(); if (NonSI.DEGREE_ANGLE.isCompatible(candidate)) { unit = candidate.asType(Angle.class); if (AxisDirection.EAST.equals(axis.getDirection().absolute())) { break; // Found the longitude axis. } } } return unit; }
for (int i = 0; i < converters.length; i++) { try { converters[i] = getAxis(i).getUnit().getConverterToAny(unit); } catch (UnconvertibleException | IndexOutOfBoundsException
final CoordinateSystemAxis axis = getAxis(i); final AxisDirection direction = axis.getDirection().absolute(); final Unit<?> unit = axis.getUnit(); try { if (AxisDirection.EAST.equals(direction)) {
final Unit targetUnit = targetCS.getAxis(0).getUnit(); double epochShift = sourceDatum.getOrigin().getTime() - targetDatum.getOrigin().getTime(); epochShift = MILLISECOND.getConverterTo(targetUnit).convert(epochShift);
AffineTransform af = (AffineTransform) g2w; CoordinateReferenceSystem crs = source.getCoordinateReferenceSystem(); Unit<?> unit = crs.getCoordinateSystem().getAxis(0).getUnit(); boolean isMeter = unit.isCompatible(SI.METRE); double resX = af.getScaleX();
/** Tests {@link AbstractCS#axisUsingUnit}. */ @Test public void testAxisUsingUnit() { assertNull( "Should detect that no axis change is needed", DefaultCartesianCS.PROJECTED.axisUsingUnit(SI.METRE)); final Unit<Length> KILOMETER = MetricPrefix.KILO(SI.METRE); final CoordinateSystemAxis[] axis = DefaultCartesianCS.PROJECTED.axisUsingUnit(KILOMETER); assertNotNull(axis); assertEquals("Expected two-dimensional", 2, axis.length); assertEquals(KILOMETER, axis[0].getUnit()); assertEquals(KILOMETER, axis[1].getUnit()); assertEquals(AxisDirection.EAST, axis[0].getDirection()); assertEquals(AxisDirection.NORTH, axis[1].getDirection()); assertEquals("Easting", axis[0].getName().getCode()); assertEquals("Northing", axis[1].getName().getCode()); }