Search in sources :

Example 36 with CoordinateSystem

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

the class DefaultEngineeringCRSTest method testSphericalXML.

/**
 * Tests XML (un)marshalling of an engineering CRS using a Spherical CS.
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 */
@Test
public void testSphericalXML() throws JAXBException {
    final String xml = marshal(createSpherical());
    assertXmlEquals("<gml:EngineeringCRS xmlns:gml=\"" + Namespaces.GML + "\">\n" + "  <gml:name>A spherical CRS</gml:name>\n" + "  <gml:sphericalCS gml:id=\"Spherical\">\n" + "    <gml:name>Spherical</gml:name>\n" + "    <gml:axis>\n" + "      <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9122\" gml:id=\"SphericalLatitude\">\n" + "        <gml:name>Spherical latitude</gml:name>\n" + "        <gml:axisAbbrev>φ′</gml:axisAbbrev>\n" + "        <gml:axisDirection codeSpace=\"EPSG\">north</gml:axisDirection>\n" + "        <gml:minimumValue>-90.0</gml:minimumValue>\n" + "        <gml:maximumValue>90.0</gml:maximumValue>\n" + "        <gml:rangeMeaning codeSpace=\"EPSG\">exact</gml:rangeMeaning>\n" + "      </gml:CoordinateSystemAxis>\n" + "    </gml:axis>\n" + "    <gml:axis>\n" + "      <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9122\" gml:id=\"SphericalLongitude\">\n" + "        <gml:name>Spherical longitude</gml:name>\n" + "        <gml:axisAbbrev>θ</gml:axisAbbrev>\n" + "        <gml:axisDirection codeSpace=\"EPSG\">east</gml:axisDirection>\n" + "        <gml:minimumValue>-180.0</gml:minimumValue>\n" + "        <gml:maximumValue>180.0</gml:maximumValue>\n" + "        <gml:rangeMeaning codeSpace=\"EPSG\">wraparound</gml:rangeMeaning>\n" + "      </gml:CoordinateSystemAxis>\n" + "    </gml:axis>\n" + "    <gml:axis>\n" + "      <gml:CoordinateSystemAxis uom=\"urn:ogc:def:uom:EPSG::9001\" gml:id=\"GeocentricRadius\">\n" + "        <gml:name>Geocentric radius</gml:name>\n" + "        <gml:axisAbbrev>R</gml:axisAbbrev>\n" + "        <gml:axisDirection codeSpace=\"EPSG\">up</gml:axisDirection>\n" + "        <gml:minimumValue>0.0</gml:minimumValue>\n" + "        <gml:rangeMeaning codeSpace=\"EPSG\">exact</gml:rangeMeaning>\n" + "      </gml:CoordinateSystemAxis>\n" + "    </gml:axis>\n" + "  </gml:sphericalCS>\n" + "  <gml:engineeringDatum>\n" + "    <gml:EngineeringDatum gml:id=\"Centre\">\n" + "      <gml:name>Centre</gml:name>\n" + "    </gml:EngineeringDatum>\n" + "  </gml:engineeringDatum>\n" + "</gml:EngineeringCRS>", xml, "xmlns:*");
    final DefaultEngineeringCRS crs = unmarshal(DefaultEngineeringCRS.class, xml);
    assertEquals("name", "A spherical CRS", crs.getName().getCode());
    assertEquals("datum.name", "Centre", crs.getDatum().getName().getCode());
    final CoordinateSystem cs = crs.getCoordinateSystem();
    assertInstanceOf("coordinateSystem", SphericalCS.class, cs);
    assertEquals("cs.name", "Spherical", cs.getName().getCode());
    assertEquals("cs.dimension", 3, cs.getDimension());
    assertAxisDirectionsEqual("cartesianCS", cs, AxisDirection.NORTH, AxisDirection.EAST, AxisDirection.UP);
    assertEquals("cs.axis[0].name", "Spherical latitude", cs.getAxis(0).getName().getCode());
    assertEquals("cs.axis[1].name", "Spherical longitude", cs.getAxis(1).getName().getCode());
    assertEquals("cs.axis[2].name", "Geocentric radius", cs.getAxis(2).getName().getCode());
    assertEquals("cs.axis[0].abbreviation", "φ′", cs.getAxis(0).getAbbreviation());
    assertEquals("cs.axis[1].abbreviation", "θ", cs.getAxis(1).getAbbreviation());
    assertEquals("cs.axis[2].abbreviation", "R", cs.getAxis(2).getAbbreviation());
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test)

Example 37 with CoordinateSystem

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

the class DefaultGeocentricCRSTest method testRightHanded.

/**
 * Tests the {@link DefaultGeocentricCRS#forConvention(AxesConvention)} method
 * for {@link AxesConvention#RIGHT_HANDED}.
 *
 * @since 0.7
 */
@Test
public void testRightHanded() {
    final DefaultGeocentricCRS crs = DefaultGeocentricCRS.castOrCopy(HardCodedCRS.SPHERICAL);
    final DefaultGeocentricCRS normalized = crs.forConvention(AxesConvention.RIGHT_HANDED);
    assertNotSame(crs, normalized);
    final CoordinateSystem cs = normalized.getCoordinateSystem();
    final CoordinateSystem ref = crs.getCoordinateSystem();
    assertSame("longitude", ref.getAxis(1), cs.getAxis(0));
    assertSame("latitude", ref.getAxis(0), cs.getAxis(1));
    assertSame("height", ref.getAxis(2), cs.getAxis(2));
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test)

Example 38 with CoordinateSystem

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

the class CoordinateOperationsTest method testWrapAroundChanges.

/**
 * Tests {@link CoordinateOperations#wrapAroundChanges(CoordinateReferenceSystem, CoordinateSystem)}.
 */
@Test
@DependsOnMethod("testIsWrapAround")
public void testWrapAroundChanges() {
    CoordinateReferenceSystem sourceCRS = HardCodedCRS.WGS84_3D;
    CoordinateSystem targetCS = HardCodedCS.GEODETIC_2D;
    assertTrue("(λ,φ,h) → (λ,φ)", CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).isEmpty());
    sourceCRS = HardCodedCRS.WGS84_3D.forConvention(AxesConvention.POSITIVE_RANGE);
    assertArrayEquals("(λ′,φ,h) → (λ,φ)", new Integer[] { 0 }, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());
    targetCS = HardCodedCS.GEODETIC_φλ;
    assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] { 1 }, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());
    sourceCRS = HardCodedConversions.mercator((GeographicCRS) sourceCRS);
    assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] { 1 }, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 39 with CoordinateSystem

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

the class EPSGFactoryTest method testDeprecatedCoordinateSystems.

/**
 * Tests creation of deprecated coordinate systems.
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
public void testDeprecatedCoordinateSystems() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    for (final Map.Entry<Integer, Integer> entry : EPSGDataAccess.deprecatedCS().entrySet()) {
        final CoordinateSystem expected = factory.createEllipsoidalCS(entry.getValue().toString());
        loggings.assertNoUnexpectedLog();
        final String code = entry.getKey().toString();
        final CoordinateSystem deprecated;
        try {
            deprecated = factory.createEllipsoidalCS(code);
        } catch (FactoryException e) {
            final String m = e.getMessage();
            if (m.contains("9115") || m.contains("9116") || m.contains("9117") || m.contains("9118") || m.contains("9119") || m.contains("9120")) {
                // Unit "9116" to "9120" are known to be unsupported.
                continue;
            }
            throw e;
        }
        loggings.assertNextLogContains(code);
        final int dimension = expected.getDimension();
        assertEquals("dimension", dimension, deprecated.getDimension());
        for (int i = 0; i < dimension; i++) {
            final CoordinateSystemAxis ref = expected.getAxis(i);
            final CoordinateSystemAxis axis = deprecated.getAxis(i);
            assertEquals("name", ref.getName(), axis.getName());
            assertEquals("alias", ref.getAlias(), axis.getAlias());
            assertEquals("direction", ref.getDirection(), axis.getDirection());
            assertEquals("rangeMeaning", ref.getRangeMeaning(), axis.getRangeMeaning());
            assertEquals("unit", ref.getUnit().getSystemUnit(), axis.getUnit().getSystemUnit());
        }
    }
}
Also used : FactoryException(org.opengis.util.FactoryException) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) Map(java.util.Map) Test(org.junit.Test)

Example 40 with CoordinateSystem

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

the class CoordinateSystemsTest method testReplaceAxes.

/**
 * Tests {@link CoordinateSystems#replaceAxes(CoordinateSystem, AxisFilter)}
 * without change of coordinate system type.
 */
@Test
public void testReplaceAxes() {
    final EllipsoidalCS sourceCS = HardCodedCS.GEODETIC_3D;
    // What we want to get.
    final EllipsoidalCS targetCS = HardCodedCS.ELLIPSOIDAL_gon;
    final CoordinateSystem actualCS = CoordinateSystems.replaceAxes(sourceCS, new AxisFilter() {

        @Override
        public boolean accept(final CoordinateSystemAxis axis) {
            return Units.isAngular(axis.getUnit());
        }

        @Override
        public Unit<?> getUnitReplacement(CoordinateSystemAxis axis, Unit<?> unit) {
            if (Units.isAngular(unit)) {
                unit = Units.GRAD;
            }
            return unit;
        }
    });
    assertEqualsIgnoreMetadata(targetCS, actualCS);
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) EllipsoidalCS(org.opengis.referencing.cs.EllipsoidalCS) Unit(javax.measure.Unit) Test(org.junit.Test)

Aggregations

CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)43 Test (org.junit.Test)16 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)15 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)13 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)9 DependsOnMethod (org.apache.sis.test.DependsOnMethod)7 FactoryException (org.opengis.util.FactoryException)7 AxisDirection (org.opengis.referencing.cs.AxisDirection)6 CartesianCS (org.opengis.referencing.cs.CartesianCS)6 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)5 Convention (org.apache.sis.io.wkt.Convention)4 GeodeticCRS (org.opengis.referencing.crs.GeodeticCRS)4 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)4 TransformException (org.opengis.referencing.operation.TransformException)4 Unit (javax.measure.Unit)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)3 GeodeticDatum (org.opengis.referencing.datum.GeodeticDatum)3 MathTransform (org.opengis.referencing.operation.MathTransform)3 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)3