Search in sources :

Example 1 with UnformattableObjectException

use of org.apache.sis.io.wkt.UnformattableObjectException in project sis by apache.

the class ConsistencyTest method testCoordinateReferenceSystems.

/**
 * Verifies the WKT consistency of all CRS instances.
 *
 * @throws FactoryException if an error other than "unsupported operation method" occurred.
 */
@Test
public void testCoordinateReferenceSystems() throws FactoryException {
    assumeTrue(RUN_EXTENSIVE_TESTS);
    final WKTFormat v1 = new WKTFormat(null, null);
    final WKTFormat v1c = new WKTFormat(null, null);
    final WKTFormat v2 = new WKTFormat(null, null);
    final WKTFormat v2s = new WKTFormat(null, null);
    v1.setConvention(Convention.WKT1);
    v1c.setConvention(Convention.WKT1_COMMON_UNITS);
    v2.setConvention(Convention.WKT2);
    v2s.setConvention(Convention.WKT2_SIMPLIFIED);
    for (final String code : CRS.getAuthorityFactory(null).getAuthorityCodes(CoordinateReferenceSystem.class)) {
        if (!EXCLUDES.contains(code)) {
            final CoordinateReferenceSystem crs;
            try {
                crs = CRS.forCode(code);
            } catch (UnavailableFactoryException | NoSuchIdentifierException | FactoryDataException e) {
                print(code, "WARNING", e.getLocalizedMessage());
                continue;
            }
            lookup(parseAndFormat(v2, code, crs), crs);
            lookup(parseAndFormat(v2s, code, crs), crs);
            /*
                 * There is more information lost in WKT 1 than in WKT 2, so we can not test everything.
                 * For example we can not format fully three-dimensional geographic CRS because the unit
                 * is not the same for all axes. We can not format neither some axis directions.
                 */
            try {
                parseAndFormat(v1, code, crs);
            } catch (UnformattableObjectException e) {
                print(code, "WARNING", e.getLocalizedMessage());
                continue;
            }
            parseAndFormat(v1c, code, crs);
        }
    }
}
Also used : UnformattableObjectException(org.apache.sis.io.wkt.UnformattableObjectException) FactoryDataException(org.apache.sis.referencing.factory.FactoryDataException) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) UnavailableFactoryException(org.apache.sis.referencing.factory.UnavailableFactoryException) WKTFormat(org.apache.sis.io.wkt.WKTFormat) Test(org.junit.Test)

Aggregations

UnformattableObjectException (org.apache.sis.io.wkt.UnformattableObjectException)1 WKTFormat (org.apache.sis.io.wkt.WKTFormat)1 FactoryDataException (org.apache.sis.referencing.factory.FactoryDataException)1 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)1 Test (org.junit.Test)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)1