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));
}
}
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));
}
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());
}
}
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());
}
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);
}
Aggregations