Search in sources :

Example 6 with ProjectedCRS

use of org.opengis.referencing.crs.ProjectedCRS in project sis by apache.

the class DefaultCompoundCRS method verify.

/**
 * Verifies that the given array does not contain duplicated horizontal or vertical components.
 * Verifies also that if there is an horizontal component, then there is no ellipsoidal height
 * defined separately.
 *
 * @param  properties  the user-specified properties, for determining the locale of error messages.
 * @param  components  the components to verify.
 */
private static void verify(final Map<String, ?> properties, final CoordinateReferenceSystem[] components) {
    int allTypes = 0;
    // 0 for false, 1 for true.
    int isProjected = 0;
    boolean isEllipsoidalHeight = false;
    for (final CoordinateReferenceSystem component : components) {
        final int type;
        if (component instanceof GeodeticCRS) {
            // Must match the number used in Resources.Keys.DuplicatedSpatialComponents_1.
            type = 1;
        } else if (component instanceof ProjectedCRS) {
            isProjected = 1;
            // Intentionally same number than for GeographicCRS case.
            type = 1;
        } else if (component instanceof VerticalCRS) {
            isEllipsoidalHeight = ReferencingUtilities.isEllipsoidalHeight(((VerticalCRS) component).getDatum());
            // Must match the number used in Resources.Keys.DuplicatedSpatialComponents_1.
            type = 2;
        } else {
            // Skip other types. In particular, we allow 2 temporal CRS (used in meteorology).
            continue;
        }
        if (allTypes == (allTypes |= type)) {
            throw new IllegalArgumentException(Resources.forProperties(properties).getString(Resources.Keys.DuplicatedSpatialComponents_1, type));
        }
    }
    if (isEllipsoidalHeight && ((allTypes & 1) != 0)) {
        throw new IllegalArgumentException(Resources.forProperties(properties).getString(Resources.Keys.EllipsoidalHeightNotAllowed_1, isProjected));
    }
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeodeticCRS(org.opengis.referencing.crs.GeodeticCRS)

Example 7 with ProjectedCRS

use of org.opengis.referencing.crs.ProjectedCRS in project sis by apache.

the class EPSGInstallerTest method createAndTest.

/**
 * Requests the "WGS84" and the "WGS72 / UTM zone 15N" coordinate reference systems from the EPSG database
 * at the given {@code DataSource}. Those requests should trig the creation of the EPSG database.
 */
private void createAndTest(final DataSource ds, final InstallationScriptProvider scriptProvider) throws SQLException, FactoryException {
    final Map<String, Object> properties = new HashMap<>();
    assertNull(properties.put("dataSource", ds));
    assertNull(properties.put("scriptProvider", scriptProvider));
    assertEquals("Should not contain EPSG tables before we created them.", 0, countCRSTables(ds));
    // Should not yet have logged anything at this point.
    loggings.assertNoUnexpectedLog();
    try (EPSGFactory factory = new EPSGFactory(properties)) {
        /*
             * Fetch the "WGS 84" coordinate reference system.
             */
        final GeographicCRS crs = factory.createGeographicCRS("4326");
        assertTrue(Utilities.deepEquals(CommonCRS.WGS84.geographic(), crs, ComparisonMode.DEBUG));
        /*
             * Fetch the "WGS 72 / UTM zone 15" coordinate system.
             * This implies the creation of a coordinate operation.
             */
        final ProjectedCRS p = factory.createProjectedCRS("EPSG:32215");
        assertTrue(Utilities.deepEquals(CommonCRS.WGS72.universal(1, -93), p, ComparisonMode.DEBUG));
        /*
             * Get the authority codes. We choose a type that implies an SQL statement
             * with both "DEPRECATED" and "SHOW_CRS" conditions in their "WHERE" clause.
             */
        Set<String> codes = factory.getAuthorityCodes(GeographicCRS.class);
        // A non-deprecated code.
        assertTrue("4979", codes.contains("4979"));
        // A deprecated code.
        assertTrue("4329", codes.contains("4329"));
        /*
             * Following forces the authority factory to iterate over all codes.
             * Since the iterator returns only non-deprecated codes, EPSG:4329
             * should not be included. The intent is to verify that the fields
             * of type BOOLEAN have been properly handled.
             */
        codes = new HashSet<>(codes);
        assertTrue("4979", codes.contains("4979"));
        assertFalse("4329", codes.contains("4329"));
    }
    assertEquals("Should contain EPSG tables after we created them.", 1, countCRSTables(ds));
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) HashMap(java.util.HashMap) GeographicCRS(org.opengis.referencing.crs.GeographicCRS)

Example 8 with ProjectedCRS

use of org.opengis.referencing.crs.ProjectedCRS in project sis by apache.

the class CommonAuthorityFactoryTest method testAuto42001.

/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42001"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
public void testAuto42001() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42001,-123,0");
    assertSame("With other coord.", crs, factory.createProjectedCRS("AUTO : 42001, -122, 10 "));
    assertSame("Omitting namespace.", crs, factory.createProjectedCRS(" 42001, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO2 :  42001, 1, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO1 :  42001, 9001, -122 , 10 "));
    assertSame("Legacy namespace.", crs, factory.createProjectedCRS("AUTO:42001,9001,-122,10"));
    assertSame("When the given parameters match exactly the UTM central meridian and latitude of origin," + " the CRS created by AUTO:42002 should be the same than the CRS created by AUTO:42001.", crs, factory.createProjectedCRS("AUTO2:42002,1,-123,0"));
    assertEpsgNameAndIdentifierEqual("WGS 84 / UTM zone 10N", 32610, crs);
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertEquals(TransverseMercator.NAME, crs.getConversionFromBase().getMethod().getName().getCode());
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, -123, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 0, p.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
    assertEquals(Constants.FALSE_NORTHING, 0, p.parameter(Constants.FALSE_NORTHING).doubleValue(), STRICT);
    assertEquals("axis[0].unit", Units.METRE, crs.getCoordinateSystem().getAxis(0).getUnit());
    try {
        factory.createObject("AUTO:42001");
        fail("Should not have accepted incomplete code.");
    } catch (NoSuchAuthorityCodeException e) {
        assertEquals("42001", e.getAuthorityCode());
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Example 9 with ProjectedCRS

use of org.opengis.referencing.crs.ProjectedCRS in project sis by apache.

the class CommonAuthorityFactoryTest method testAuto42004.

/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42004"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
public void testAuto42004() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO2:42004,1,10,45");
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, 10, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 45, p.parameter(Constants.STANDARD_PARALLEL_1).doubleValue(), STRICT);
    assertInstanceOf("Opportunistic check: in the special case of Equirectangular projection, " + "SIS should have optimized the MathTransform as an affine transform.", LinearTransform.class, crs.getConversionFromBase().getMathTransform());
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 10 with ProjectedCRS

use of org.opengis.referencing.crs.ProjectedCRS in project sis by apache.

the class MilitaryGridReferenceSystemTest method testDecodeLimitCases.

/**
 * Tests decoding of values that are close to a change of zones.
 * Values tested in this methods were used to cause a {@link ReferenceVerifyException}
 * before we debugged the verification algorithm in the {@code decode(…)} method.
 *
 * @throws TransformException if an error occurred while computing the coordinate.
 */
@Test
@DependsOnMethod("testDecodeUTM")
public void testDecodeLimitCases() throws TransformException {
    final MilitaryGridReferenceSystem.Coder coder = coder();
    DirectPosition position;
    ProjectedCRS crs;
    /*
         * Cell on the West border of a UTM zone in the South hemisphere.
         * Easting value before clipping: 250000
         * Easting value after  clipping: 251256
         */
    coder.setClipToValidArea(false);
    // South hemisphere
    position = decode(coder, "19JBK");
    crs = CommonCRS.WGS84.universal(-10, -69);
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 250000, position.getOrdinate(0), 1);
    assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
    coder.setClipToValidArea(true);
    position = decode(coder, "19JBK");
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 251256, position.getOrdinate(0), 1);
    assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
    /*
         * Easting range before clipping is [300000 … 400000] metres.
         * The east bound become 343828 metres after clipping.
         * Easting value before clipping: 350000
         * Easting value after  clipping: 371914
         */
    coder.setClipToValidArea(false);
    // North of Norway latitude band
    position = decode(coder, "1VCK");
    crs = CommonCRS.WGS84.universal(62, -180);
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 350000, position.getOrdinate(0), 1);
    assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
    coder.setClipToValidArea(true);
    position = decode(coder, "1VCK");
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 371914, position.getOrdinate(0), 1);
    assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
    /*
         * Northing value before clipping: 7350000
         * Northing value after  clipping: 7371306
         */
    coder.setClipToValidArea(false);
    position = decode(coder, "57KTP");
    crs = CommonCRS.WGS84.universal(-24, 156);
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 250000, position.getOrdinate(0), STRICT);
    assertEquals("Northing", 7350000, position.getOrdinate(1), 1);
    coder.setClipToValidArea(true);
    position = decode(coder, "57KTP");
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 250000, position.getOrdinate(0), STRICT);
    assertEquals("Northing", 7371306, position.getOrdinate(1), 1);
    /*
         * Easting and northing values before clipping:  650000   6250000
         * Easting and northing values after  clipping:  643536   6253618
         */
    coder.setClipToValidArea(false);
    position = decode(coder, "56VPH");
    crs = CommonCRS.WGS84.universal(55, 154);
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 650000, position.getOrdinate(0), 1);
    assertEquals("Northing", 6250000, position.getOrdinate(1), 1);
    coder.setClipToValidArea(true);
    position = decode(coder, "56VPH");
    assertSame("crs", crs, position.getCoordinateReferenceSystem());
    assertEquals("Easting", 643536, position.getOrdinate(0), 1);
    assertEquals("Northing", 6253618, position.getOrdinate(1), 1);
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)40 Test (org.junit.Test)31 DependsOnMethod (org.apache.sis.test.DependsOnMethod)23 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)10 GeodeticCRS (org.opengis.referencing.crs.GeodeticCRS)5 CartesianCS (org.opengis.referencing.cs.CartesianCS)5 Conversion (org.opengis.referencing.operation.Conversion)5 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)4 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)4 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)4 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)4 GeodeticObjectBuilder (org.apache.sis.internal.referencing.GeodeticObjectBuilder)3 DefaultProjectedCRS (org.apache.sis.referencing.crs.DefaultProjectedCRS)3 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 DirectPosition (org.opengis.geometry.DirectPosition)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 EngineeringCRS (org.opengis.referencing.crs.EngineeringCRS)2 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)2