use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sis by apache.
the class DefaultCoordinateOperationFactoryTest method testProjectionAndLongitudeRotation.
/**
* Tests a transformation between 2D projected CRS which implies a change of prime meridian.
*
* @throws ParseException if a CRS used in this test can not be parsed.
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
public void testProjectionAndLongitudeRotation() throws ParseException, FactoryException, TransformException {
final CoordinateReferenceSystem sourceCRS = parse("$NTF");
final CoordinateReferenceSystem targetCRS = parse("$Mercator");
final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertInstanceOf("operation", ConcatenatedOperation.class, operation);
/*
* The accuracy of the coordinate operation depends on whether a path has been found with the help
* of the EPSG database (in which case the reported accuracy is 2 metres) or if we had to find an
* operation by ourselves (in which case we conservatively report an accuracy of 3000 metres, but
* in practice observe an error between 80 and 515 metres for this test depending on the operation
* method used). By comparison, the translation declared in EPSG database is about 370 metres in
* geocentric coordinates.
*/
final boolean isUsingEpsgFactory = verifyParametersNTF(((ConcatenatedOperation) operation).getOperations(), 1);
assertEquals("linearAccuracy", isUsingEpsgFactory ? 2 : PositionalAccuracyConstant.UNKNOWN_ACCURACY, CRS.getLinearAccuracy(operation), STRICT);
tolerance = isUsingEpsgFactory ? Formulas.LINEAR_TOLERANCE : 600;
transform = operation.getMathTransform();
/*
* Test using the location of Paris (48.856578°N, 2.351828°E) first,
* then using a coordinate different than the prime meridian.
*/
verifyTransform(new double[] { 601124.99, 2428693.45, 600000.00, 2420000.00 }, new double[] { 261804.30, 6218365.73, 260098.74, 6205194.95 });
validate();
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sis by apache.
the class DefaultCoordinateOperationFactoryTest method testMercatorToGoogle.
/**
* Tests the conversion from Mercator projection to the Google projection. The referencing module
* should detects that the conversion is something more complex that an identity transform.
*
* @throws ParseException if a CRS used in this test can not be parsed.
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
public void testMercatorToGoogle() throws ParseException, FactoryException, TransformException {
final CoordinateReferenceSystem sourceCRS = parse("$Mercator");
final CoordinateReferenceSystem targetCRS = parse("ProjectedCRS[“WGS 84 / Pseudo-Mercator”,\n" + " BaseGeodCRS[“WGS 84”,\n" + " Datum[“World Geodetic System 1984”,\n" + " Ellipsoid[“WGS 84”, 6378137.0, 298.257223563]],\n" + " Unit[“degree”, 0.017453292519943295]],\n" + " Conversion[“Popular Visualisation Pseudo-Mercator”,\n" + " Method[“Popular Visualisation Pseudo Mercator”]],\n" + " CS[Cartesian, 2],\n" + " Axis[“Easting (X)”, east],\n" + " Axis[“Northing (Y)”, north],\n" + " Unit[“metre”, 1],\n" + " Id[“EPSG”, 3857]]");
final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertInstanceOf("operation", ConcatenatedOperation.class, operation);
transform = operation.getMathTransform();
tolerance = 1;
assertFalse("Mercator to Google should not be an identity transform.", transform.isIdentity());
// Approximatively 40°N 3°W
final DirectPosition2D sourcePt = new DirectPosition2D(334000, 4840000);
final DirectPosition2D targetPt = new DirectPosition2D();
assertSame(targetPt, transform.transform(sourcePt, targetPt));
assertEquals("Easting should be unchanged", sourcePt.getX(), targetPt.getX(), STRICT);
assertEquals("Expected 27 km shift", 27476, targetPt.getY() - sourcePt.getY(), tolerance);
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem 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");
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sis by apache.
the class SingleOperationMarshallingTest method testTransformationUnmarshalling.
/**
* Tests unmarshalling of a transformation.
*
* @throws JAXBException if an error occurred during marshalling or unmarshalling.
*/
@Test
@DependsOnMethod("testConversionUnmarshalling")
public void testTransformationUnmarshalling() throws JAXBException {
final DefaultTransformation c = unmarshalFile(DefaultTransformation.class, "Transformation.xml");
assertEquals("name", "NTF (Paris) to NTF (1)", c.getName().getCode());
assertEquals("identifier", "1763", getSingleton(c.getIdentifiers()).getCode());
assertEquals("scope", "Change of prime meridian.", String.valueOf(c.getScope()));
assertEquals("operationVersion", "IGN-Fra", c.getOperationVersion());
final OperationMethod method = c.getMethod();
assertNotNull("method", method);
assertEquals("method.name", "Longitude rotation", method.getName().getCode());
assertEquals("method.identifier", "9601", getSingleton(method.getIdentifiers()).getCode());
assertEquals("method.formula", "Target_longitude = Source_longitude + longitude_offset.", method.getFormula().getFormula().toString());
final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) getSingleton(method.getParameters().descriptors());
assertEquals("descriptor.name", "Longitude offset", descriptor.getName().getCode());
assertEquals("descriptor.identifier", "8602", getSingleton(descriptor.getIdentifiers()).getCode());
assertEquals("descriptor.valueClass", Double.class, descriptor.getValueClass());
final ParameterValueGroup parameters = c.getParameterValues();
assertNotNull("parameters", parameters);
assertSame("parameters.descriptors", method.getParameters(), parameters.getDescriptor());
final ParameterValue<?> parameter = (ParameterValue<?>) getSingleton(parameters.values());
assertSame("parameters.descriptor", descriptor, parameter.getDescriptor());
assertEquals("parameters.unit", Units.GRAD, parameter.getUnit());
assertEquals("parameters.value", 2.5969213, parameter.getValue());
final CoordinateReferenceSystem sourceCRS = c.getSourceCRS();
assertInstanceOf("sourceCRS", GeodeticCRS.class, sourceCRS);
assertEquals("sourceCRS.name", "NTF (Paris)", sourceCRS.getName().getCode());
assertEquals("sourceCRS.scope", "Geodetic survey.", sourceCRS.getScope().toString());
assertEquals("sourceCRS.identifier", "4807", getSingleton(sourceCRS.getIdentifiers()).getCode());
final CoordinateReferenceSystem targetCRS = c.getTargetCRS();
assertInstanceOf("targetCRS", GeodeticCRS.class, targetCRS);
assertEquals("targetCRS.name", "NTF", targetCRS.getName().getCode());
assertEquals("targetCRS.scope", "Geodetic survey.", targetCRS.getScope().toString());
assertEquals("targetCRS.identifier", "4275", getSingleton(targetCRS.getIdentifiers()).getCode());
final MathTransform tr = c.getMathTransform();
assertInstanceOf("mathTransform", LinearTransform.class, tr);
assertMatrixEquals("mathTransform.matrix", new Matrix3(1, 0, 0, 0, 1, 2.33722917, 0, 0, 1), ((LinearTransform) tr).getMatrix(), STRICT);
Validators.validate(c);
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sis by apache.
the class AbstractEnvelope method getCommonCRS.
/**
* Returns the common CRS of specified points.
*
* @param lowerCorner the first position.
* @param upperCorner the second position.
* @return their common CRS, or {@code null} if none.
* @throws MismatchedReferenceSystemException if the two positions don't use equal CRS.
*/
static CoordinateReferenceSystem getCommonCRS(final DirectPosition lowerCorner, final DirectPosition upperCorner) throws MismatchedReferenceSystemException {
ensureNonNull("lowerCorner", lowerCorner);
ensureNonNull("upperCorner", upperCorner);
final CoordinateReferenceSystem crs1 = lowerCorner.getCoordinateReferenceSystem();
final CoordinateReferenceSystem crs2 = upperCorner.getCoordinateReferenceSystem();
if (crs1 == null) {
return crs2;
} else {
if (crs2 != null && !crs1.equals(crs2)) {
throw new MismatchedReferenceSystemException(Errors.format(Errors.Keys.MismatchedCRS));
}
return crs1;
}
}
Aggregations