use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CoordinateOperationFinderTest method testGeocentricTranslationInGeographic3D.
/**
* Tests a transformation with a three-dimensional geographic source CRS.
* This method verifies with both a three-dimensional and a two-dimensional target CRS.
*
* @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
@DependsOnMethod("testGeocentricTranslationInGeographic2D")
public void testGeocentricTranslationInGeographic3D() throws ParseException, FactoryException, TransformException {
final GeographicCRS sourceCRS = (GeographicCRS) parse("GeodeticCRS[“NAD27”,\n" + " Datum[“North American Datum 1927”,\n" + " Ellipsoid[“Clarke 1866”, 6378206.4, 294.9786982138982],\n" + // See comment in above test.
" ToWGS84[-8, 160, 176]]," + " CS[ellipsoidal, 3],\n" + " Axis[“Latitude (φ)”, NORTH, Unit[“degree”, 0.017453292519943295]],\n" + " Axis[“Longitude (λ)”, EAST, Unit[“degree”, 0.017453292519943295]],\n" + " Axis[“Height (h)”, UP, Unit[“m”, 1]]]");
testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)", sourceCRS, CommonCRS.WGS84.geographic3D());
// Because lost of height values changes (φ,λ) results.
isInverseTransformSupported = false;
testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)", sourceCRS, CommonCRS.WGS84.geographic());
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CommonAuthorityFactoryTest method testWKT.
/**
* Tests the WKT formatting. The main purpose of this test is to ensure that
* the authority name is "CRS" and not "Web Map Service CRS".
*
* @throws FactoryException if an error occurred while creating the CRS.
*/
@Test
@DependsOnMethod("testCRS84")
public void testWKT() throws FactoryException {
GeographicCRS crs = factory.createGeographicCRS("CRS:84");
assertWktEquals(Convention.WKT1, "GEOGCS[“WGS 84”,\n" + " DATUM[“World Geodetic System 1984”,\n" + " SPHEROID[“WGS 84”, 6378137.0, 298.257223563]],\n" + " PRIMEM[“Greenwich”, 0.0],\n" + " UNIT[“degree”, 0.017453292519943295],\n" + " AXIS[“Longitude”, EAST],\n" + " AXIS[“Latitude”, NORTH],\n" + " AUTHORITY[“CRS”, “84”]]", crs);
assertWktEqualsRegex(Convention.WKT2, "(?m)\\Q" + "GEODCRS[“WGS 84”,\n" + " DATUM[“World Geodetic System 1984”,\n" + " ELLIPSOID[“WGS 84”, 6378137.0, 298.257223563, LENGTHUNIT[“metre”, 1]]],\n" + " PRIMEM[“Greenwich”, 0.0, ANGLEUNIT[“degree”, 0.017453292519943295]],\n" + " CS[ellipsoidal, 2],\n" + " AXIS[“Longitude (L)”, east, ORDER[1]],\n" + " AXIS[“Latitude (B)”, north, ORDER[2]],\n" + " ANGLEUNIT[“degree”, 0.017453292519943295],\n" + " SCOPE[“Horizontal component of 3D system.\\E.*\\Q”],\n" + " AREA[“World\\E.*\\Q”],\n" + " BBOX[-90.00, -180.00, 90.00, 180.00],\n" + " ID[“CRS”, 84, CITATION[“OGC:WMS”], URI[“urn:ogc:def:crs:OGC:1.3:CRS84”]]]\\E", crs);
/*
* Note: the WKT specification defines the ID element as:
*
* ID[authority, code, (version), (authority citation), (URI)]
*
* where everything after the code is optional. The difference between "authority" and "authority citation"
* is unclear. The only example found in OGC 12-063r5 uses CITATION[…] as the source of an EPSG definition
* (so we could almost said "the authority of the authority").
*/
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class ServicesForMetadata method setBounds.
/**
* Sets a geographic bounding box from the specified envelope.
* If the envelope contains a CRS which is not geographic, then the bounding box will be transformed
* to a geographic CRS (without datum shift if possible). Otherwise, the envelope is assumed already
* in a geographic CRS using (<var>longitude</var>, <var>latitude</var>) axis order.
*
* @param envelope the source envelope.
* @param target the target bounding box where to store envelope information.
* @throws TransformException if the given envelope can not be transformed.
*/
@Override
public void setBounds(Envelope envelope, final DefaultGeographicBoundingBox target) throws TransformException {
final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
GeographicCRS normalizedCRS = ReferencingUtilities.toNormalizedGeographicCRS(crs);
if (normalizedCRS == null) {
if (crs != null) {
normalizedCRS = CommonCRS.defaultGeographic();
} else if (envelope.getDimension() != 2) {
throw new TransformException(dimensionNotFound(Resources.Keys.MissingHorizontalDimension_1, crs));
}
}
setGeographicExtent(envelope, target, crs, normalizedCRS);
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class ServicesForMetadata method setBounds.
/**
* Sets the geographic, vertical and temporal extents with the values inferred from the given envelope.
* If the given {@code target} has more geographic or vertical extents than needed (0 or 1), then the
* extraneous extents are removed.
*
* @param envelope the source envelope.
* @param target the target spatiotemporal extent where to store envelope information.
* @throws TransformException if no temporal component can be extracted from the given envelope.
*/
@Override
public void setBounds(final Envelope envelope, final DefaultSpatialTemporalExtent target) throws TransformException {
final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
final SingleCRS horizontalCRS = CRS.getHorizontalComponent(crs);
final VerticalCRS verticalCRS = CRS.getVerticalComponent(crs, true);
final TemporalCRS temporalCRS = CRS.getTemporalComponent(crs);
if (horizontalCRS == null && verticalCRS == null && temporalCRS == null) {
throw new TransformException(dimensionNotFound(Resources.Keys.MissingSpatioTemporalDimension_1, crs));
}
/*
* Try to set the geographic bounding box first, because this operation may fail with a
* TransformException while the other operations (vertical and temporal) should not fail.
* So doing the geographic part first help us to get a "all or nothing" behavior.
*/
DefaultGeographicBoundingBox box = null;
boolean useExistingBox = (horizontalCRS != null);
final Collection<GeographicExtent> spatialExtents = target.getSpatialExtent();
final Iterator<GeographicExtent> it = spatialExtents.iterator();
while (it.hasNext()) {
final GeographicExtent extent = it.next();
if (extent instanceof GeographicBoundingBox) {
if (useExistingBox && (extent instanceof DefaultGeographicBoundingBox)) {
box = (DefaultGeographicBoundingBox) extent;
useExistingBox = false;
} else {
it.remove();
}
}
}
if (horizontalCRS != null) {
if (box == null) {
box = new DefaultGeographicBoundingBox();
spatialExtents.add(box);
}
GeographicCRS normalizedCRS = ReferencingUtilities.toNormalizedGeographicCRS(crs);
if (normalizedCRS == null) {
normalizedCRS = CommonCRS.defaultGeographic();
}
setGeographicExtent(envelope, box, crs, normalizedCRS);
}
/*
* Other dimensions (vertical and temporal).
*/
if (verticalCRS != null) {
VerticalExtent e = target.getVerticalExtent();
if (!(e instanceof DefaultVerticalExtent)) {
e = new DefaultVerticalExtent();
target.setVerticalExtent(e);
}
setVerticalExtent(envelope, (DefaultVerticalExtent) e, crs, verticalCRS);
} else {
target.setVerticalExtent(null);
}
if (temporalCRS != null) {
setTemporalExtent(envelope, target, crs, temporalCRS);
} else {
target.setExtent(null);
}
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class TransformTestCase method testTransformOverPole.
/**
* Tests conversions of an envelope or rectangle over a pole using a coordinate operation.
*
* @throws FactoryException if an error occurred while creating the operation.
* @throws TransformException if an error occurred while transforming the envelope.
*/
@Test
@DependsOnMethod("testTransform")
public final void testTransformOverPole() throws FactoryException, TransformException {
final ProjectedCRS sourceCRS = (ProjectedCRS) CRS.fromWKT("PROJCS[“WGS 84 / Antarctic Polar Stereographic”,\n" + " GEOGCS[“WGS 84”,\n" + " DATUM[“World Geodetic System 1984”,\n" + " SPHEROID[“WGS 84”, 6378137.0, 298.257223563]],\n" + " PRIMEM[“Greenwich”, 0.0],\n" + " UNIT[“degree”, 0.017453292519943295]],\n" + " PROJECTION[“Polar Stereographic (variant B)”],\n" + " PARAMETER[“standard_parallel_1”, -71.0],\n" + " UNIT[“m”, 1.0]]");
final GeographicCRS targetCRS = sourceCRS.getBaseCRS();
final Conversion conversion = inverse(sourceCRS.getConversionFromBase());
final MathTransform2D transform = (MathTransform2D) conversion.getMathTransform();
/*
* The rectangle to test, which contains the South pole.
*/
G rectangle = createFromExtremums(sourceCRS, -3943612.4042124213, -4078471.954436003, 3729092.5890516187, 4033483.085688618);
/*
* This is what we get without special handling of singularity point.
* Note that is does not include the South pole as we would expect.
* The commented out values are what we get by projecting an arbitrary
* larger amount of points.
*/
G expected = createFromExtremums(targetCRS, // anti-regression values
-179.8650137390031, // anti-regression values
-88.99136583196396, // 178.8122742080059 -40.90577500420587] // empirical values
137.9769431693009, // anti-regression values
-40.90577500420587);
/*
* Tests what we actually get. First, test using the method working on MathTransform.
* Next, test again the same transform, but using the API on Envelope objects.
*/
G actual = transform(targetCRS, transform, rectangle);
assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
/*
* Using the transform(CoordinateOperation, …) method,
* the singularity at South pole is taken in account.
*/
expected = createFromExtremums(targetCRS, -180, -90, 180, -40.905775004205864);
actual = transform(conversion, rectangle);
assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
/*
* Another rectangle containing the South pole, but this time the south
* pole is almost in a corner of the rectangle
*/
rectangle = createFromExtremums(sourceCRS, -4000000, -4000000, 300000, 30000);
expected = createFromExtremums(targetCRS, -180, -90, 180, -41.03163170198091);
actual = transform(conversion, rectangle);
assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
/*
* Another rectangle with the South pole close to the border.
* This test should execute the step #3 in the transform method code.
*/
rectangle = createFromExtremums(sourceCRS, -2000000, -1000000, 200000, 2000000);
expected = createFromExtremums(targetCRS, -180, -90, 180, -64.3861643256928);
actual = transform(conversion, rectangle);
assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
}
Aggregations