Search in sources :

Example 1 with DefaultGeographicCRS

use of org.apache.sis.referencing.crs.DefaultGeographicCRS in project sis by apache.

the class EPSGFactoryTest method testFindGeographic.

/**
 * Tests {@link EPSGFactory#newIdentifiedObjectFinder()} method with a geographic CRS.
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
@DependsOnMethod("testWGS84")
public void testFindGeographic() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    final IdentifiedObjectFinder finder = factory.newIdentifiedObjectFinder();
    final DefaultGeographicCRS crs = (DefaultGeographicCRS) CRS.fromWKT("GEOGCS[“WGS 84”,\n" + // Use the alias instead than primary name for forcing a deeper search.
    "  DATUM[“WGS 84”,\n" + // Different name for forcing a deeper search.
    "    SPHEROID[“WGS 1984”, 6378137.0, 298.257223563]],\n" + "  PRIMEM[“Greenwich”, 0.0],\n" + "  UNIT[“degree”, 0.017453292519943295],\n" + "  AXIS[“Geodetic latitude”, NORTH],\n" + "  AXIS[“Geodetic longitude”, EAST]]");
    /*
         * First, search for a CRS with axis order that does not match the ones in the EPSG database.
         * IdentifiedObjectFinder should not accept EPSG:4326 as a match for the given CRS.
         */
    assertEquals("Full scan should be enabled by default.", IdentifiedObjectFinder.Domain.VALID_DATASET, finder.getSearchDomain());
    assertTrue("Should not find WGS84 because the axis order is not the same.", finder.find(crs.forConvention(AxesConvention.NORMALIZED)).isEmpty());
    /*
         * Ensure that the cache is empty.
         */
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.DECLARATION);
    assertTrue("Should not find without a full scan, because the WKT contains no identifier " + "and the CRS name is ambiguous (more than one EPSG object have this name).", finder.find(crs).isEmpty());
    /*
         * Scan the database for searching the CRS.
         */
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.ALL_DATASET);
    final IdentifiedObject found = finder.findSingleton(crs);
    assertNotNull("With full scan allowed, the CRS should be found.", found);
    assertEpsgNameAndIdentifierEqual("WGS 84", 4326, found);
    /*
         * Should find the CRS without the need of a full scan, because of the cache.
         */
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.DECLARATION);
    assertSame("The CRS should still in the cache.", found, finder.findSingleton(crs));
}
Also used : IdentifiedObjectFinder(org.apache.sis.referencing.factory.IdentifiedObjectFinder) IdentifiedObject(org.opengis.referencing.IdentifiedObject) DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with DefaultGeographicCRS

use of org.apache.sis.referencing.crs.DefaultGeographicCRS in project sis by apache.

the class DefinitionVerifierTest method testDifferentAxisOrder.

/**
 * Tests with a CRS having wrong axis order.
 *
 * @throws FactoryException if an error occurred while querying the authority factory.
 */
@Test
@DependsOnMethod("testNormalizedCRS")
public void testDifferentAxisOrder() throws FactoryException {
    final Map<String, Object> properties = new HashMap<>(4);
    properties.put(DefaultGeographicCRS.NAME_KEY, "WGS 84");
    properties.put(DefaultGeographicCRS.IDENTIFIERS_KEY, new NamedIdentifier(HardCodedCitations.EPSG, "4326"));
    DefaultGeographicCRS crs = HardCodedCRS.WGS84;
    crs = new DefaultGeographicCRS(properties, crs.getDatum(), crs.getCoordinateSystem());
    final DefinitionVerifier ver = DefinitionVerifier.withAuthority(crs, null, false);
    assertNotNull("Should replace by normalized CRS", ver);
    assertNotSame("Should replace by normalized CRS", crs, ver.authoritative);
    assertSame("Should replace by normalized CRS", CommonCRS.WGS84.normalizedGeographic(), ver.authoritative);
    final LogRecord warning = ver.warning(true);
    assertNotNull("Should emit a warning.", warning);
    final String message = new SimpleFormatter().formatMessage(warning);
    assertTrue(message, message.contains("WGS 84"));
    assertTrue(message, message.contains("EPSG:4326"));
}
Also used : HashMap(java.util.HashMap) LogRecord(java.util.logging.LogRecord) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with DefaultGeographicCRS

use of org.apache.sis.referencing.crs.DefaultGeographicCRS in project sis by apache.

the class DefinitionVerifierTest method testConformCRS.

/**
 * Tests with a CRS which is conform to the authoritative definition.
 *
 * @throws FactoryException if an error occurred while querying the authority factory.
 */
@Test
public void testConformCRS() throws FactoryException {
    final DefaultGeographicCRS crs = HardCodedCRS.WGS84_φλ;
    final DefinitionVerifier ver = DefinitionVerifier.withAuthority(crs, null, false);
    assertNotNull("Should replace by EPSG:4326", ver);
    assertNotSame("Should replace by EPSG:4326", crs, ver.authoritative);
    assertSame("Should replace by EPSG:4326", CommonCRS.WGS84.geographic(), ver.authoritative);
    assertNull("Should be silent.", ver.warning(true));
}
Also used : DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Test(org.junit.Test)

Example 4 with DefaultGeographicCRS

use of org.apache.sis.referencing.crs.DefaultGeographicCRS in project sis by apache.

the class DefinitionVerifierTest method testNormalizedCRS.

/**
 * Tests with a CRS which is conform to the authoritative definition.
 *
 * @throws FactoryException if an error occurred while querying the authority factory.
 */
@Test
@DependsOnMethod("testConformCRS")
public void testNormalizedCRS() throws FactoryException {
    final DefaultGeographicCRS crs = HardCodedCRS.WGS84;
    assertNull("No replacement without EPSG code.", DefinitionVerifier.withAuthority(crs, null, false));
    final DefinitionVerifier ver = DefinitionVerifier.withAuthority(crs, null, true);
    assertNotNull("Should replace by normalized CRS", ver);
    assertNotSame("Should replace by normalized CRS", crs, ver.authoritative);
    assertSame("Should replace by normalized CRS", CommonCRS.WGS84.normalizedGeographic(), ver.authoritative);
    assertNull("Should be silent.", ver.warning(true));
}
Also used : DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with DefaultGeographicCRS

use of org.apache.sis.referencing.crs.DefaultGeographicCRS in project sis by apache.

the class IdentifiedObjectFinderTest method testFindSingleton.

/**
 * Tests the {@link IdentifiedObjectFinder#findSingleton(IdentifiedObject)} method.
 *
 * @throws FactoryException if the creation of a CRS failed.
 */
@Test
public void testFindSingleton() throws FactoryException {
    final GeographicCRS CRS84 = factory.createGeographicCRS("CRS:84");
    final IdentifiedObjectFinder finder = factory.newIdentifiedObjectFinder();
    assertEquals("Newly created finder should default to full scan.", IdentifiedObjectFinder.Domain.VALID_DATASET, finder.getSearchDomain());
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.DECLARATION);
    assertSame("Should find without the need for scan, since we can use the CRS:84 identifier.", CRS84, finder.findSingleton(CRS84));
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.VALID_DATASET);
    assertSame("Allowing scanning should not make any difference for this CRS84 instance.", CRS84, finder.findSingleton(CRS84));
    /*
         * Same test than above, using a CRS without identifier.
         * The intent is to force a full scan.
         */
    final CoordinateReferenceSystem search = new DefaultGeographicCRS(Collections.singletonMap(DefaultGeographicCRS.NAME_KEY, CRS84.getName()), CRS84.getDatum(), CRS84.getCoordinateSystem());
    // Required condition for next test.
    assertEqualsIgnoreMetadata(CRS84, search);
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.DECLARATION);
    assertNull("Should not find WGS84 without a full scan, since it does not contains the CRS:84 identifier.", finder.findSingleton(search));
    finder.setSearchDomain(IdentifiedObjectFinder.Domain.VALID_DATASET);
    assertSame("A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.", CRS84, finder.findSingleton(search));
}
Also used : GeographicCRS(org.opengis.referencing.crs.GeographicCRS) DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Test(org.junit.Test)

Aggregations

DefaultGeographicCRS (org.apache.sis.referencing.crs.DefaultGeographicCRS)5 Test (org.junit.Test)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 HashMap (java.util.HashMap)1 LogRecord (java.util.logging.LogRecord)1 SimpleFormatter (java.util.logging.SimpleFormatter)1 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)1 IdentifiedObjectFinder (org.apache.sis.referencing.factory.IdentifiedObjectFinder)1 IdentifiedObject (org.opengis.referencing.IdentifiedObject)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)1