Author: desruisseaux Date: Fri Feb 17 13:21:18 2017 New Revision: 1783399 URL: http://svn.apache.org/viewvc?rev=1783399&view=rev Log: Add tests.
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -95,8 +95,8 @@ final class EPSGFactoryFallback extends } /** - * Returns the EPSG authority with only a modification in the title of emphasing that this is a subset - * of EPSG dataset. + * Returns the EPSG authority with only a modification in the title + * for emphasing that this is a subset of EPSG dataset. */ @Override public synchronized Citation getAuthority() { Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -74,6 +74,7 @@ import static org.apache.sis.internal.me /** * Definitions of referencing objects identified by the {@link CommonCRS} enumeration values. * This class is used only as a fallback if the objects can not be fetched from the EPSG database. + * This class should not be loaded when a connection to an EPSG geodetic dataset is available. * * @author Martin Desruisseaux (Geomatys) * @since 0.4 @@ -109,7 +110,7 @@ final class StandardDefinitions { map.put(IDENTIFIERS_KEY, new NamedIdentifier(Citations.EPSG, String.valueOf(code))); } map.put(NAME_KEY, new NamedIdentifier(Citations.EPSG, name)); - map.put(ALIAS_KEY, alias); // May be null, which is okay. + map.put(ALIAS_KEY, alias); // May be null, which is okay. if (world) { map.put(DOMAIN_OF_VALIDITY_KEY, Extents.WORLD); } @@ -146,7 +147,7 @@ final class StandardDefinitions { final OperationMethod method; try { method = DefaultFactories.forBuildin(MathTransformFactory.class, DefaultMathTransformFactory.class) - .getOperationMethod(isUTM ? TransverseMercator.NAME : PolarStereographicA.NAME); + .getOperationMethod(isUTM ? TransverseMercator.NAME : PolarStereographicA.NAME); } catch (NoSuchIdentifierException e) { throw new IllegalStateException(e); // Should not happen with SIS implementation. } @@ -169,17 +170,17 @@ final class StandardDefinitions { */ static GeographicCRS createGeographicCRS(final short code, final GeodeticDatum datum, final EllipsoidalCS cs) { final String name; - String alias = null; - String scope = null; + String alias = null; + String scope = null; boolean world = false; switch (code) { - case 4326: name = "WGS 84"; world = true; scope = "Horizontal component of 3D system."; break; - case 4322: name = "WGS 72"; world = true; break; - case 4258: name = "ETRS89"; alias = "ETRS89-GRS80"; break; - case 4269: name = "NAD83"; break; - case 4267: name = "NAD27"; break; - case 4230: name = "ED50"; break; - case 4047: name = "Unspecified datum based upon the GRS 1980 Authalic Sphere"; world = true; break; + case 4326: name = "WGS 84"; world = true; scope = "Horizontal component of 3D system."; break; + case 4322: name = "WGS 72"; world = true; scope = "Horizontal component of 3D system."; break; + case 4258: name = "ETRS89"; alias = "ETRS89-GRS80"; scope = "Horizontal component of 3D system."; break; + case 4269: name = "NAD83"; scope = "Geodetic survey."; break; + case 4267: name = "NAD27"; scope = "Geodetic survey."; break; + case 4230: name = "ED50"; scope = "Geodetic survey."; break; + case 4047: name = "Unspecified datum based upon the GRS 1980 Authalic Sphere"; world = true; break; default: throw new AssertionError(code); } final Map<String, Object> properties = properties(code, name, alias, world); Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -602,7 +602,7 @@ public class CommonAuthorityFactory exte CartesianCS cs; // Coordinate system with (E,N) axes in metres. try { if (isUTM != null && isUTM) { - crs = datum.UTM(latitude, longitude); + crs = datum.universal(forceUTM(latitude), longitude); if (factor == (isLegacy ? Constants.EPSG_METRE : 1)) { return crs; } @@ -611,7 +611,7 @@ public class CommonAuthorityFactory exte } else { cs = projectedCS; if (cs == null) { - crs = datum.UTM(latitude, longitude); + crs = datum.universal(forceUTM(latitude), longitude); projectedCS = cs = crs.getCoordinateSystem(); baseCRS = crs.getBaseCRS(); } else { @@ -683,6 +683,17 @@ public class CommonAuthorityFactory exte } /** + * Forces the given latitude in the range of UTM projections, including Norway and Svalbard special cases. + * This method is used for preventing {@code "AUTO:42001"} to switch on the Universal Polar Stereographic + * projection for high latitudes, because the WMS specification does not said that we should. However we + * could remove this method if we consider allowing that as an Apache SIS extension. + */ + private static double forceUTM(final double latitude) { + return Math.max(Zoner.SOUTH_BOUNDS + 0.5, + Math.min(Zoner.NORTH_BOUNDS - 0.5, latitude)); + } + + /** * Returns the "Computer display" reference system (CRS:1). This is rarely used. */ private synchronized CoordinateReferenceSystem displayCRS() throws FactoryException { Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -75,28 +75,30 @@ public final strictfp class CRSTest exte * * @throws FactoryException if a CRS can not be constructed. * - * @see CommonCRSTest#testForCode() + * @see EPSGFactoryFallbackTest#testCreateCRS() */ @Test public void testForEpsgCode() throws FactoryException { - verifyForCode(CommonCRS.WGS84 .geographic(), "EPSG:4326"); - verifyForCode(CommonCRS.WGS84 .geographic(), "urn:ogc:def:crs:EPSG::4326"); - verifyForCode(CommonCRS.WGS84 .geographic(), "urn:x-ogc:def:crs:EPSG::4326"); - verifyForCode(CommonCRS.WGS84 .geographic(), "http://www.opengis.net/gml/srs/epsg.xml#4326"); - verifyForCode(CommonCRS.WGS72 .geographic(), "EPSG:4322"); - verifyForCode(CommonCRS.SPHERE.geographic(), "EPSG:4047"); - verifyForCode(CommonCRS.NAD83 .geographic(), "EPSG:4269"); - verifyForCode(CommonCRS.NAD27 .geographic(), "EPSG:4267"); - verifyForCode(CommonCRS.ETRS89.geographic(), "EPSG:4258"); - verifyForCode(CommonCRS.ED50 .geographic(), "EPSG:4230"); - verifyForCode(CommonCRS.WGS84 .geocentric(), "EPSG:4978"); - verifyForCode(CommonCRS.WGS72 .geocentric(), "EPSG:4984"); - verifyForCode(CommonCRS.ETRS89.geocentric(), "EPSG:4936"); - verifyForCode(CommonCRS.WGS84 .geographic3D(), "EPSG:4979"); - verifyForCode(CommonCRS.WGS72 .geographic3D(), "EPSG:4985"); - verifyForCode(CommonCRS.ETRS89.geographic3D(), "EPSG:4937"); + verifyForCode(CommonCRS.WGS84 .geographic(), "EPSG:4326"); + verifyForCode(CommonCRS.WGS84 .geographic(), "urn:ogc:def:crs:EPSG::4326"); + verifyForCode(CommonCRS.WGS84 .geographic(), "urn:x-ogc:def:crs:EPSG::4326"); + verifyForCode(CommonCRS.WGS84 .geographic(), "http://www.opengis.net/gml/srs/epsg.xml#4326"); + verifyForCode(CommonCRS.WGS72 .geographic(), "EPSG:4322"); + verifyForCode(CommonCRS.SPHERE.geographic(), "EPSG:4047"); + verifyForCode(CommonCRS.NAD83 .geographic(), "EPSG:4269"); + verifyForCode(CommonCRS.NAD27 .geographic(), "EPSG:4267"); + verifyForCode(CommonCRS.ETRS89.geographic(), "EPSG:4258"); + verifyForCode(CommonCRS.ED50 .geographic(), "EPSG:4230"); + verifyForCode(CommonCRS.WGS84 .geocentric(), "EPSG:4978"); + verifyForCode(CommonCRS.WGS72 .geocentric(), "EPSG:4984"); + verifyForCode(CommonCRS.ETRS89.geocentric(), "EPSG:4936"); + verifyForCode(CommonCRS.WGS84 .geographic3D(), "EPSG:4979"); + verifyForCode(CommonCRS.WGS72 .geographic3D(), "EPSG:4985"); + verifyForCode(CommonCRS.ETRS89.geographic3D(), "EPSG:4937"); + verifyForCode(CommonCRS.WGS84 .universal(88, 120), "EPSG:5041"); + verifyForCode(CommonCRS.WGS84 .universal(-40, 2), "EPSG:32731"); verifyForCode(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(), "EPSG:5714"); - verifyForCode(CommonCRS.Vertical.DEPTH.crs(), "EPSG:5715"); + verifyForCode(CommonCRS.Vertical.DEPTH.crs(), "EPSG:5715"); } /** @@ -104,7 +106,7 @@ public final strictfp class CRSTest exte * * @throws FactoryException if a CRS can not be constructed. * - * @see CommonCRSTest#testForCode() + * @see EPSGFactoryFallbackTest#testCreateCRS() */ @Test @DependsOnMethod("testForEpsgCode") Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -290,6 +290,7 @@ public final strictfp class CommonCRSTes final ParameterValueGroup pg = crs.getConversionFromBase().getParameterValues(); assertEquals(Constants.LATITUDE_OF_ORIGIN, 0, pg.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT); assertEquals(Constants.CENTRAL_MERIDIAN, -123, pg.parameter(Constants.CENTRAL_MERIDIAN) .doubleValue(), STRICT); + assertEquals(Constants.SCALE_FACTOR, 0.9996, pg.parameter(Constants.SCALE_FACTOR) .doubleValue(), STRICT); assertEquals(Constants.FALSE_EASTING, 500000, pg.parameter(Constants.FALSE_EASTING) .doubleValue(), STRICT); assertEquals(Constants.FALSE_NORTHING, 10000000, pg.parameter(Constants.FALSE_NORTHING) .doubleValue(), STRICT); assertSame("Expected a cached instance.", crs, CommonCRS.WGS72.universal(-45, -122)); @@ -309,6 +310,7 @@ public final strictfp class CommonCRSTes final ParameterValueGroup pg = crs.getConversionFromBase().getParameterValues(); assertEquals(Constants.LATITUDE_OF_ORIGIN, -90, pg.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT); assertEquals(Constants.CENTRAL_MERIDIAN, 0, pg.parameter(Constants.CENTRAL_MERIDIAN) .doubleValue(), STRICT); + assertEquals(Constants.SCALE_FACTOR, 0.994, pg.parameter(Constants.SCALE_FACTOR) .doubleValue(), STRICT); assertEquals(Constants.FALSE_EASTING, 2000000, pg.parameter(Constants.FALSE_EASTING) .doubleValue(), STRICT); assertEquals(Constants.FALSE_NORTHING, 2000000, pg.parameter(Constants.FALSE_NORTHING) .doubleValue(), STRICT); assertSame("Expected a cached instance.", crs, CommonCRS.WGS72.universal(-85, -122)); Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -19,11 +19,13 @@ package org.apache.sis.referencing; import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; +import java.util.Set; import org.opengis.util.FactoryException; import org.opengis.referencing.crs.SingleCRS; import org.opengis.referencing.crs.VerticalCRS; import org.opengis.referencing.crs.GeographicCRS; import org.opengis.referencing.crs.GeocentricCRS; +import org.opengis.referencing.crs.ProjectedCRS; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.datum.Datum; import org.opengis.referencing.datum.Ellipsoid; @@ -74,6 +76,12 @@ public final strictfp class EPSGFactoryF EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeographicCRS.class)); assertSetEquals(Arrays.asList("5714", "5715", "5703"), EPSGFactoryFallback.INSTANCE.getAuthorityCodes(VerticalCRS.class)); + /* + * There is two many ProjectedCRS codes for enumerating all of them, so test only a sampling. + */ + final Set<String> codes = EPSGFactoryFallback.INSTANCE.getAuthorityCodes(ProjectedCRS.class); + assertTrue(codes.containsAll(Arrays.asList("5041", "5042", "32601", "32660", "32701", "32760"))); + assertTrue(Collections.disjoint(codes, Arrays.asList("7030", "6326", "4326", "4978", "32600", "32700", "5714"))); } /** @@ -141,6 +149,8 @@ public final strictfp class EPSGFactoryF verifyCreateCRS(CommonCRS.WGS84 .geographic3D(), "4979"); verifyCreateCRS(CommonCRS.WGS72 .geographic3D(), "4985"); verifyCreateCRS(CommonCRS.ETRS89.geographic3D(), "4937"); + verifyCreateCRS(CommonCRS.WGS84 .universal(-88, 120), "5042"); + verifyCreateCRS(CommonCRS.WGS84 .universal( 40, 14), "32633"); verifyCreateCRS(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(), "5714"); verifyCreateCRS(CommonCRS.Vertical.DEPTH.crs(), "5715"); } Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java?rev=1783399&r1=1783398&r2=1783399&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java [UTF-8] Fri Feb 17 13:21:18 2017 @@ -82,8 +82,31 @@ public final strictfp class StandardDefi final ProjectedCRS crs = StandardDefinitions.createUniversal(32610, HardCodedCRS.WGS84, true, 15, -122, HardCodedCS.PROJECTED); assertEquals("name", "WGS 84 / UTM zone 10N", crs.getName().getCode()); final ParameterValueGroup pg = crs.getConversionFromBase().getParameterValues(); - assertEquals(Constants.LATITUDE_OF_ORIGIN, -123, pg.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(), STRICT); - assertEquals(Constants.FALSE_NORTHING, 0, pg.parameter(Constants.FALSE_NORTHING).doubleValue(), STRICT); + assertEquals(Constants.LATITUDE_OF_ORIGIN, 0, pg.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT); + assertEquals(Constants.CENTRAL_MERIDIAN, -123, pg.parameter(Constants.CENTRAL_MERIDIAN) .doubleValue(), STRICT); + assertEquals(Constants.SCALE_FACTOR, 0.9996, pg.parameter(Constants.SCALE_FACTOR) .doubleValue(), STRICT); + assertEquals(Constants.FALSE_EASTING, 500000, pg.parameter(Constants.FALSE_EASTING) .doubleValue(), STRICT); + assertEquals(Constants.FALSE_NORTHING, 0, pg.parameter(Constants.FALSE_NORTHING) .doubleValue(), STRICT); + } + + /** + * Tests {@link StandardDefinitions#createUniversal(int, GeographicCRS, boolean, double, double, CartesianCS)} + * for a Universal Polar Stereographic (UPS) projection. This test cheats a little bit on the coordinate system + * by laziness; we are more interested in the projection parameters. + * + * @since 0.8 + */ + @Test + @DependsOnMethod("testCreateGeographicCRS") + public void testCreateUPS() { + final ProjectedCRS crs = StandardDefinitions.createUniversal(5041, HardCodedCRS.WGS84, false, 90, -122, HardCodedCS.PROJECTED); + assertEquals("name", "WGS 84 / Universal Polar Stereographic North", crs.getName().getCode()); + final ParameterValueGroup pg = crs.getConversionFromBase().getParameterValues(); + assertEquals(Constants.LATITUDE_OF_ORIGIN, 90, pg.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT); + assertEquals(Constants.CENTRAL_MERIDIAN, 0, pg.parameter(Constants.CENTRAL_MERIDIAN) .doubleValue(), STRICT); + assertEquals(Constants.SCALE_FACTOR, 0.994, pg.parameter(Constants.SCALE_FACTOR) .doubleValue(), STRICT); + assertEquals(Constants.FALSE_EASTING, 2000000, pg.parameter(Constants.FALSE_EASTING) .doubleValue(), STRICT); + assertEquals(Constants.FALSE_NORTHING, 2000000, pg.parameter(Constants.FALSE_NORTHING) .doubleValue(), STRICT); } /**