use of org.opengis.referencing.crs.CompoundCRS in project sis by apache.
the class IdentifiedObjects method lookupURN.
/**
* Looks up a URN, such as {@code "urn:ogc:def:crs:EPSG:9.1:4326"}, of the specified object.
* This method searches in all {@linkplain org.apache.sis.referencing.factory.GeodeticAuthorityFactory geodetic
* authority factories} known to SIS for an object {@linkplain org.apache.sis.util.ComparisonMode#APPROXIMATIVE
* approximatively equals} to the specified object. Then there is a choice:
*
* <ul>
* <li>If a single matching object is found in the specified authority factory, then its URN is returned.</li>
* <li>Otherwise if the given object is a {@link CompoundCRS} or {@link ConcatenatedOperation}
* and all components have an URN, then this method returns a combined URN.</li>
* <li>Otherwise this method returns {@code null}.</li>
* </ul>
*
* <p><strong>Note that this method checks the identifier validity.</strong>
* If the given object declares explicitly an identifier, then this method will instantiate an object from the
* authority factory using that identifier and compare it with the given object. If the comparison fails, then
* this method returns {@code null}. Consequently this method may return {@code null} even if the given object
* declares explicitly its identifier. If the declared identifier is wanted unconditionally,
* one can use the following pattern instead:
*
* {@preformat java
* String urn = toURN(object.getClass(), getIdentifier(object, authority));
* }
*
* This method can be seen as a converse of {@link CRS#forCode(String)}.
*
* @param object the object (usually a {@linkplain org.apache.sis.referencing.crs.AbstractCRS
* coordinate reference system}) whose identifier is to be found, or {@code null}.
* @param authority the authority for the identifier to return, or {@code null} for
* the first identifier regardless its authority.
* @return the identifier, or {@code null} if none was found without ambiguity or if the given object was null.
* @throws FactoryException if an error occurred during the search.
*
* @see #newFinder(String)
* @see #toURN(Class, Identifier)
*
* @since 0.7
*/
public static String lookupURN(final IdentifiedObject object, final Citation authority) throws FactoryException {
if (object == null) {
return null;
}
IdentifiedObjectFinder finder;
try {
finder = newFinder(Citations.getCodeSpace(authority));
} catch (NoSuchAuthorityFactoryException e) {
warning("lookupURN", e);
finder = newFinder(null);
}
String urn = lookupURN(object, authority, finder);
if (urn != null) {
return urn;
}
/*
* If we didn't found a URN but the given object is made of smaller components, build a combined URN.
* Example: "urn:ogc:def:crs, crs:EPSG::27700, crs:EPSG::5701" (without spaces actually).
*/
final List<? extends IdentifiedObject> components;
if (object instanceof CompoundCRS) {
components = CRS.getSingleComponents((CompoundCRS) object);
} else if (object instanceof ConcatenatedOperation) {
components = ((ConcatenatedOperation) object).getOperations();
} else {
return null;
}
StringBuilder buffer = null;
for (final IdentifiedObject component : components) {
urn = lookupURN(component, authority, finder);
if (urn == null) {
return null;
}
assert urn.startsWith(DefinitionURI.PREFIX) : urn;
if (buffer == null) {
buffer = new StringBuilder(40).append(DefinitionURI.PREFIX).append(DefinitionURI.SEPARATOR).append(NameMeaning.toObjectType(object.getClass()));
}
buffer.append(DefinitionURI.COMPONENT_SEPARATOR).append(urn, DefinitionURI.PREFIX.length() + 1, urn.length());
}
return (buffer != null) ? buffer.toString() : null;
}
use of org.opengis.referencing.crs.CompoundCRS in project sis by apache.
the class CoordinateOperationFinderTest method testSpatioTemporalToDerived.
/**
* Tests conversion from spatio-temporal CRS to a derived CRS.
*
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testProjected4D_to_2D")
public void testSpatioTemporalToDerived() throws FactoryException, TransformException {
final Map<String, Object> properties = new HashMap<>();
properties.put(DerivedCRS.NAME_KEY, "Display");
properties.put("conversion.name", "Display to WGS84");
final GeographicCRS WGS84 = CommonCRS.WGS84.normalizedGeographic();
final CompoundCRS sourceCRS = compound("Test3D", WGS84, CommonCRS.Temporal.UNIX.crs());
final DerivedCRS targetCRS = DefaultDerivedCRS.create(properties, WGS84, null, factory.getOperationMethod("Affine"), MathTransforms.linear(Matrices.create(3, 3, new double[] { 12, 0, 480, 0, -12, 790, 0, 0, 1 })), HardCodedCS.DISPLAY);
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
transform = operation.getMathTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
assertEquals("targetDimensions", 2, transform.getTargetDimensions());
Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] { 12, 0, 0, 480, 0, -12, 0, 790, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
validate();
}
use of org.opengis.referencing.crs.CompoundCRS in project sis by apache.
the class CoordinateOperationFinderTest method testGeographic4D_to_EllipsoidalHeight.
/**
* Tests extracting the vertical part of a spatio-temporal CRS.
*
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testGeographic3D_to_EllipsoidalHeight")
public void testGeographic4D_to_EllipsoidalHeight() throws FactoryException, TransformException {
// NOTE: make sure that the 'sourceCRS' below is not equal to any other 'sourceCRS' created in this class.
final CompoundCRS sourceCRS = compound("Test4D", CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.JULIAN.crs());
final VerticalCRS targetCRS = CommonCRS.Vertical.ELLIPSOIDAL.crs();
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertEquals("name", "Axis changes", operation.getName().getCode());
assertInstanceOf("operation", Conversion.class, operation);
transform = operation.getMathTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertEquals("sourceDimensions", 4, transform.getSourceDimensions());
assertEquals("targetDimensions", 1, transform.getTargetDimensions());
Assert.assertMatrixEquals("transform.matrix", Matrices.create(2, 5, new double[] { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
isInverseTransformSupported = false;
verifyTransform(new double[] { 0, 0, 0, 0, 5, 8, 20, 10, -5, -8, 24, 30 }, new double[] { 0, 20, 24 });
validate();
}
use of org.opengis.referencing.crs.CompoundCRS in project sis by apache.
the class CoordinateOperationFinderTest method testGeographic3D_to_4D.
/**
* Tests conversion from three-dimensional geographic CRS to four-dimensional compound CRS
* where the last dimension is time.
*
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testTemporalConversion")
public void testGeographic3D_to_4D() throws FactoryException, TransformException {
// NOTE: make sure that the 'sourceCRS' below is not equal to any other 'sourceCRS' created in this class.
final CompoundCRS sourceCRS = compound("Test3D", CommonCRS.WGS84.geographic(), CommonCRS.Temporal.UNIX.crs());
final CompoundCRS targetCRS = compound("Test4D", CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.MODIFIED_JULIAN.crs());
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertInstanceOf("operation", ConcatenatedOperation.class, operation);
assertEquals("name", "CompoundCRS[“Test3D”] ⟶ CompoundCRS[“Test4D”]", operation.getName().getCode());
transform = operation.getMathTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
assertEquals("targetDimensions", 4, transform.getTargetDimensions());
Assert.assertMatrixEquals("transform.matrix", Matrices.create(5, 4, new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1. / (24 * 60 * 60), 40587, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), 1E-12);
tolerance = 1E-12;
verifyTransform(new double[] { -5, -8, CommonCRS.Temporal.DUBLIN_JULIAN.datum().getOrigin().getTime() / 1000 }, new double[] { // Same value than in testTemporalConversion().
-5, // Same value than in testTemporalConversion().
-8, // Same value than in testTemporalConversion().
0, // Same value than in testTemporalConversion().
15019.5 });
validate();
}
use of org.opengis.referencing.crs.CompoundCRS in project sis by apache.
the class DefaultPassThroughOperationTest method testXML.
/**
* Tests (un)marshalling of a concatenated operation.
*
* @throws JAXBException if an error occurred during (un)marshalling.
*/
@Test
public void testXML() throws JAXBException {
final DefaultPassThroughOperation toTest = unmarshalFile(DefaultPassThroughOperation.class, XML_FILE);
Validators.validate(toTest);
final CoordinateReferenceSystem sourceCRS = toTest.getSourceCRS();
final CoordinateReferenceSystem targetCRS = toTest.getTargetCRS();
final CoordinateOperation operation = toTest.getOperation();
assertIdentifierEquals("identifier", "test", "test", null, "passthrough", getSingleton(toTest.getIdentifiers()));
assertIdentifierEquals("sourceCRS.identifier", "test", "test", null, "source", getSingleton(sourceCRS.getIdentifiers()));
assertIdentifierEquals("targetCRS.identifier", "test", "test", null, "target", getSingleton(targetCRS.getIdentifiers()));
assertIdentifierEquals("operation.identifier", "test", "test", null, "rotation", getSingleton(operation.getIdentifiers()));
assertInstanceOf("sourceCRS", CompoundCRS.class, sourceCRS);
assertInstanceOf("targetCRS", CompoundCRS.class, targetCRS);
assertInstanceOf("operation", Transformation.class, operation);
final List<CoordinateReferenceSystem> srcComponents = ((CompoundCRS) sourceCRS).getComponents();
final List<CoordinateReferenceSystem> tgtComponents = ((CompoundCRS) targetCRS).getComponents();
assertEquals("sourceCRS.components.size", 2, srcComponents.size());
assertEquals("targetCRS.components.size", 2, tgtComponents.size());
assertSame("sourceCRS.components[0]", operation.getSourceCRS(), srcComponents.get(0));
assertSame("targetCRS.components[0]", operation.getTargetCRS(), tgtComponents.get(0));
assertSame("targetCRS.components[1]", srcComponents.get(1), tgtComponents.get(1));
/*
* Test marshalling and compare with the original file.
*/
assertMarshalEqualsFile(XML_FILE, toTest, "xmlns:*", "xsi:schemaLocation");
}
Aggregations