private String getCompatibleAxisName(CoordinateSystemAxis axis, int dimensionIdx) { // try with one of the various ways this can be called String abbreviation = axis.getAbbreviation(); if (AXIS_NAME_VALIDATOR.matcher(abbreviation).matches()) { return abbreviation; } String name = axis.getName().getCode(); if (AXIS_NAME_VALIDATOR.matcher(name).matches()) { return name; } for (GenericName gn : axis.getAlias()) { String alias = gn.tip().toString(); if (AXIS_NAME_VALIDATOR.matcher(alias).matches()) { return alias; } } // one last try if (CRS.equalsIgnoreMetadata(DefaultCoordinateSystemAxis.LONGITUDE, axis)) { return "Longitude"; } else if (CRS.equalsIgnoreMetadata(DefaultCoordinateSystemAxis.LATITUDE, axis)) { return "Latitude"; } else if (CRS.equalsIgnoreMetadata(DefaultCoordinateSystemAxis.ALTITUDE, axis)) { return "Altitude"; } // ok, give up, let's use a name return "DIM_" + (dimensionIdx + 1); }
/** * 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(); }
/** Tests the (latitude, longitude) axis order for EPSG:4326. */ public void testCorrectAxisOrder() throws NoSuchAuthorityCodeException, FactoryException { final CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); CoordinateSystemAxis axis0 = cs.getAxis(0); assertEquals("Lat", axis0.getAbbreviation()); CoordinateSystemAxis axis1 = cs.getAxis(1); assertEquals("Long", axis1.getAbbreviation()); }
/** Tests the (longitude, latitude) axis order for EPSG:4326. */ public void testForcedAxisOrder() throws NoSuchAuthorityCodeException, FactoryException { final CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); CoordinateSystemAxis axis0 = cs.getAxis(0); assertEquals("Long", axis0.getAbbreviation()); CoordinateSystemAxis axis1 = cs.getAxis(1); assertEquals("Lat", axis1.getAbbreviation()); final CoordinateReferenceSystem standard = CRS.decode("EPSG:4326"); assertFalse( "Should not be (long,lat) axis order.", CRS.equalsIgnoreMetadata(crs, standard)); final CoordinateReferenceSystem def; try { assertNull( Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE)); def = CRS.decode("EPSG:4326"); } finally { assertEquals( Boolean.TRUE, Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER)); } assertEquals("Expected (long,lat) axis order.", crs, def); assertSame("Should be back to (lat,long) axis order.", standard, CRS.decode("EPSG:4326")); }
axis = csFactory.createCoordinateSystemAxis( properties, axis.getAbbreviation(), newDirection, newUnits); axis = (CoordinateSystemAxis) pool.unique(axis);
private String getAxisLabel(CoordinateSystemAxis axis) { // some default axis have weird abbreviations (greek letters), handle them separately String label = axis.getAbbreviation(); if (label.equals(DefaultCoordinateSystemAxis.LONGITUDE.getAbbreviation())) { return "Long"; } else if (label.equals(DefaultCoordinateSystemAxis.LATITUDE.getAbbreviation())) { return "Lat"; } else { return label; } }
/** * Returns a new axis with the same properties than the given axis except the identifiers which are omitted, * and the minimum and maximum values which are set to the given values. */ private static CoordinateSystemAxis forRange(final CoordinateSystemAxis axis, final double min, final double max) { final Map<String,Object> properties = new HashMap<>(8); 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, axis.getRangeMeaning()); return new DefaultCoordinateSystemAxis(properties, axis.getAbbreviation(), axis.getDirection(), axis.getUnit()); }
/** * Compares the abbreviations of coordinate system axes against the expected values. * The comparison is case-sensitive, e.g. <var>h</var> (ellipsoidal height) is not the same than * <var>H</var> (gravity-related height). * * <p>The GeoAPI conformance tests invoke this method only for abbreviations that should not need transliteration. * For example the GeoAPI tests do not invoke this method for geodetic latitude and longitude axes, because some * implementations may keep the Greek letters φ and λ as specified in ISO 19111 while other implementations may * transliterate those Greek letters to the <var>P</var> and <var>L</var> Latin letters.</p> * * @param cs the coordinate system to verify. * @param abbreviations the expected abbreviations. Null elements are considered unrestricted. */ private static void verifyAxisAbbreviations(final CoordinateSystem cs, final String... abbreviations) { final int dimension = Math.min(abbreviations.length, cs.getDimension()); for (int i=0; i<dimension; i++) { final String expected = abbreviations[i]; if (expected != null) { assertEquals("CoordinateSystemAxis.getAbbreviation()", expected, cs.getAxis(i).getAbbreviation()); } } }
/** * Returns a new axis with the same properties than current axis except for the units. * * @param newUnit The unit for the new axis. * @return An axis using the specified unit. * @throws IncommensurableException If the specified unit is incompatible with the expected one. */ static CoordinateSystemAxis usingUnit(final CoordinateSystemAxis a, final Unit<?> newUnit) throws IncommensurableException { final Unit<?> unit = a.getUnit(); if (unit.equals(newUnit)) { return a; } final UnitConverter converter = unit.getConverterToAny(newUnit); final Map<String,Object> properties = new HashMap<>(PredefinedCS.getProperties(a, null)); properties.put(DefaultCoordinateSystemAxis.MINIMUM_VALUE_KEY, converter.convert(a.getMinimumValue())); properties.put(DefaultCoordinateSystemAxis.MAXIMUM_VALUE_KEY, converter.convert(a.getMaximumValue())); properties.put(DefaultCoordinateSystemAxis.RANGE_MEANING_KEY, a.getRangeMeaning()); // TODO: should be provided by getProperties return new DefaultCoordinateSystemAxis(properties, a.getAbbreviation(), a.getDirection(), newUnit); } }
/** * Creates a new coordinate system axis with the same values than the specified one. * This copy constructor provides a way to convert an arbitrary implementation into a SIS one * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API. * * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p> * * @param axis the coordinate system axis to copy. * * @see #castOrCopy(CoordinateSystemAxis) */ protected DefaultCoordinateSystemAxis(final CoordinateSystemAxis axis) { super(axis); abbreviation = axis.getAbbreviation(); direction = axis.getDirection(); unit = axis.getUnit(); minimumValue = axis.getMinimumValue(); maximumValue = axis.getMaximumValue(); rangeMeaning = axis.getRangeMeaning(); }
/** * Creates a new coordinate system axis with the same values than the specified one. * This copy constructor provides a way to convert an arbitrary implementation into a SIS one * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API. * * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p> * * @param axis the coordinate system axis to copy. * * @see #castOrCopy(CoordinateSystemAxis) */ protected DefaultCoordinateSystemAxis(final CoordinateSystemAxis axis) { super(axis); abbreviation = axis.getAbbreviation(); direction = axis.getDirection(); unit = axis.getUnit(); minimumValue = axis.getMinimumValue(); maximumValue = axis.getMaximumValue(); rangeMeaning = axis.getRangeMeaning(); }
/** * Creates an axis identical to the given one with an EPSG code added. * This is a helper method for {@link #testIdentifierRemoval()}. */ private static CoordinateSystemAxis addIdentifier(final CoordinateSystemAxis axis, final short epsg) { final Map<String,Object> properties = new HashMap<>(8); properties.putAll(IdentifiedObjects.getProperties(axis)); properties.put(DefaultCoordinateSystemAxis.IDENTIFIERS_KEY, new ImmutableIdentifier(null, "EPSG", String.valueOf(epsg))); properties.put(DefaultCoordinateSystemAxis.MINIMUM_VALUE_KEY, axis.getMinimumValue()); properties.put(DefaultCoordinateSystemAxis.MAXIMUM_VALUE_KEY, axis.getMaximumValue()); properties.put(DefaultCoordinateSystemAxis.RANGE_MEANING_KEY, axis.getRangeMeaning()); return new DefaultCoordinateSystemAxis(properties, axis.getAbbreviation(), axis.getDirection(), axis.getUnit()); }
/** * Validates the given axis. * * @param object the object to validate, or {@code null}. */ public void validate(final CoordinateSystemAxis object) { if (object == null) { return; } validateIdentifiedObject(object); mandatory("CoordinateSystemAxis: abbreviation is mandatory.", object.getAbbreviation()); mandatory("CoordinateSystemAxis: unit is mandatory.", object.getUnit()); assertValidRange("CoordinateSystemAxis: expected maximum >= minimum.", object.getMinimumValue(), object.getMaximumValue()); }
/** * Verifies that the abbreviations used in {@link HardCodedAxes} constants are consistent with the abbreviations * suggested by {@link AxisDirections#suggestAbbreviation(String, AxisDirection, Unit)}. Note that a failure in * this verification does not necessarily means that {@code suggestAbbreviation(…)} has a bug. It could also be * the hard-coded constant which need a revision, or we may decide that the different abbreviations are intended * and should not be compared. * * @throws IllegalAccessException should never happen since we inspect only for public fields. * * @since 0.6 */ @Test public void verifyAbbreviationConsistency() throws IllegalAccessException { for (final Field field : HardCodedAxes.class.getFields()) { if (CoordinateSystemAxis.class.isAssignableFrom(field.getType())) { final CoordinateSystemAxis axis = (CoordinateSystemAxis) field.get(null); assertEquals(field.getName(), axis.getAbbreviation(), AxisDirections.suggestAbbreviation( axis.getName().getCode(), axis.getDirection(), axis.getUnit())); } } }
/** * Tests the (latitude, longitude) axis order for EPSG:4326. * * @throws FactoryException Should not happen. */ @Test public void testCorrectAxisOrder() throws FactoryException { final CoordinateReferenceSystem crs = CommonCRS.WGS84.geographic(); assertEquals("EPSG:4326", IdentifiedObjects.getIdentifierOrName(crs)); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); CoordinateSystemAxis axis0 = cs.getAxis(0); assertEquals("Lat", axis0.getAbbreviation()); CoordinateSystemAxis axis1 = cs.getAxis(1); assertEquals("Long", axis1.getAbbreviation()); }
/** * Tests a spherical CRS conforms to EPSG:8.9:6404 definition. * Expected axes are: * * <ol> * <li>Spherical latitude (Ω)</li> * <li>Spherical longitude (θ)</li> * <li>Geocentric radius (R)</li> * </ol> */ @Test public void testGeodetic() { final DefaultSphericalCS cs = HardCodedCS.SPHERICAL; assertEquals("EPSG abbreviation for geocentric radius should be lower-case", "r", cs.getAxis(2).getAbbreviation()); final DefaultSphericalCS normalized = cs.forConvention(AxesConvention.DISPLAY_ORIENTED); assertNotSame("Should create a new CoordinateSystem.", cs, normalized); assertAxisDirectionsEqual("Normalized", normalized, AxisDirection.EAST, AxisDirection.NORTH, AxisDirection.UP); assertEquals(new DefaultSphericalCS( Collections.singletonMap(AbstractCS.NAME_KEY, "Spherical CS: East (°), North (°), Up (m)."), HardCodedAxes.SPHERICAL_LONGITUDE, HardCodedAxes.SPHERICAL_LATITUDE, HardCodedAxes.GEOCENTRIC_RADIUS), normalized); }
/** * Tests a spherical CRS conforms to the example given in ISO 19162. * Expected axes are: * * <ol> * <li>Distance (r)</li> * <li>Longitude</li> * <li>Elevation</li> * </ol> * * This order is not exactly the usual engineering axis order. * But this is the order expected by the {@code SphericalToCartesian} transform. */ @Test public void testEngineering() { final DefaultSphericalCS cs = HardCodedCS.SPHERICAL_ENGINEERING; assertEquals("Abbreviation for distance should be lower-case", "r", cs.getAxis(0).getAbbreviation()); final DefaultSphericalCS normalized = cs.forConvention(AxesConvention.NORMALIZED); assertNotSame("Should create a new CoordinateSystem.", cs, normalized); assertAxisDirectionsEqual("Normalized", normalized, AxisDirections.COUNTER_CLOCKWISE, AxisDirection.UP, AxisDirections.AWAY_FROM); } }
/** * Tests the (longitude, latitude) axis order for EPSG:4326. * * @throws FactoryException Should not happen. */ @Test public void testForcedAxisOrder() throws FactoryException { final CoordinateReferenceSystem crs = AbstractCRS.castOrCopy(CommonCRS.WGS84.geographic()).forConvention(AxesConvention.RIGHT_HANDED); assertEquals("EPSG:4326", IdentifiedObjects.getIdentifierOrName(crs)); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); CoordinateSystemAxis axis0 = cs.getAxis(0); assertEquals("Long", axis0.getAbbreviation()); CoordinateSystemAxis axis1 = cs.getAxis(1); assertEquals("Lat", axis1.getAbbreviation()); assertNotDeepEquals(crs, CommonCRS.WGS84.geographic()); // Should not be (lon,lat) axis order. }
/** * Compares only the properties which are known to be defined in {@link StandardDefinitions}. */ private static void compare(final CoordinateSystemAxis expected, final CoordinateSystemAxis actual) { assertEquals("name", expected.getName().getCode(), actual.getName().getCode()); assertEquals("abbreviation", expected.getAbbreviation(), actual.getAbbreviation()); assertEquals("unit", expected.getUnit(), actual.getUnit()); assertEquals("direction", expected.getDirection(), actual.getDirection()); assertEquals("minimumValue", expected.getMinimumValue(), actual.getMinimumValue(), STRICT); assertEquals("maximumValue", expected.getMaximumValue(), actual.getMaximumValue(), STRICT); assertEquals("rangeMeaning", expected.getRangeMeaning(), actual.getRangeMeaning()); }
/** * Compares the given coordinate system axis against the expected values. * * @param name the expected axis name code. * @param abbreviation the expected axis abbreviation. * @param direction the expected axis direction. * @param minimumValue the expected axis minimal value. * @param maximumValue the expected axis maximal value. * @param unit the expected axis unit of measurement. * @param rangeMeaning the expected axis range meaning. * @param axis the axis to verify. */ public static void assertAxisEquals(final String name, final String abbreviation, final AxisDirection direction, final double minimumValue, final double maximumValue, final Unit<?> unit, final RangeMeaning rangeMeaning, final CoordinateSystemAxis axis) { assertEquals("name", name, axis.getName().getCode()); assertEquals("abbreviation", abbreviation, axis.getAbbreviation()); assertEquals("direction", direction, axis.getDirection()); assertEquals("minimumValue", minimumValue, axis.getMinimumValue(), TestCase.STRICT); assertEquals("maximumValue", maximumValue, axis.getMaximumValue(), TestCase.STRICT); assertEquals("unit", unit, axis.getUnit()); assertEquals("rangeMeaning", rangeMeaning, axis.getRangeMeaning()); }