use of javax.measure.quantity.Angle in project sis by apache.
the class FranceGeocentricInterpolation method createMathTransform.
/**
* Creates a transform from the specified group of parameter values.
* This method creates the transform from <em>target</em> to <em>source</em>
* (which is the direction that use the interpolation grid directly without iteration),
* then inverts the transform.
*
* @param factory the factory to use if this constructor needs to create other math transforms.
* @param values the group of parameter values.
* @return the created math transform.
* @throws ParameterNotFoundException if a required parameter was not found.
* @throws FactoryException if an error occurred while loading the grid.
*/
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values) throws ParameterNotFoundException, FactoryException {
boolean withHeights = false;
final Parameters pg = Parameters.castOrWrap(values);
final Integer dim = pg.getValue(Molodensky.DIMENSION);
if (dim != null)
switch(dim) {
case 2:
break;
case 3:
withHeights = true;
break;
default:
throw new InvalidParameterValueException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "dim", dim), "dim", dim);
}
final Path file = pg.getMandatoryValue(FILE);
final DatumShiftGridFile<Angle, Length> grid = getOrLoad(file, isRecognized(file) ? new double[] { TX, TY, TZ } : null, PRECISION);
MathTransform tr = createGeodeticTransformation(factory, createEllipsoid(pg, Molodensky.TGT_SEMI_MAJOR, Molodensky.TGT_SEMI_MINOR, // GRS 1980 ellipsoid
CommonCRS.ETRS89.ellipsoid()), createEllipsoid(pg, Molodensky.SRC_SEMI_MAJOR, Molodensky.SRC_SEMI_MINOR, // Clarke 1880 (IGN) ellipsoid
null), withHeights, grid);
try {
tr = tr.inverse();
} catch (NoninvertibleTransformException e) {
// Should never happen.
throw new FactoryException(e);
}
return tr;
}
use of javax.measure.quantity.Angle in project sis by apache.
the class FranceGeocentricInterpolation method getOrLoad.
/**
* Returns the grid of the given name. This method returns the cached instance if it still exists,
* or load the grid otherwise.
*
* @param file name of the datum shift grid file to load.
* @param averages an "average" value for the offset in each dimension, or {@code null} if unknown.
* @param scale the factor by which to multiply each compressed value before to add to the average value.
*/
@SuppressWarnings("null")
static DatumShiftGridFile<Angle, Length> getOrLoad(final Path file, final double[] averages, final double scale) throws FactoryException {
final Path resolved = DataDirectory.DATUM_CHANGES.resolve(file).toAbsolutePath();
DatumShiftGridFile<?, ?> grid = DatumShiftGridFile.CACHE.peek(resolved);
if (grid == null) {
final Cache.Handler<DatumShiftGridFile<?, ?>> handler = DatumShiftGridFile.CACHE.lock(resolved);
try {
grid = handler.peek();
if (grid == null) {
try (BufferedReader in = Files.newBufferedReader(resolved)) {
DatumShiftGridLoader.log(FranceGeocentricInterpolation.class, file);
final DatumShiftGridFile.Float<Angle, Length> g = load(in, file);
grid = DatumShiftGridCompressed.compress(g, averages, scale);
} catch (IOException | NoninvertibleTransformException | RuntimeException e) {
// NumberFormatException, ArithmeticException, NoSuchElementException, possibly other.
throw DatumShiftGridLoader.canNotLoad(HEADER, file, e);
}
grid = grid.useSharedData();
}
} finally {
handler.putAndUnlock(grid);
}
}
return grid.castTo(Angle.class, Length.class);
}
use of javax.measure.quantity.Angle in project com.revolsys.open by revolsys.
the class GeographicCoordinateSystem method getCoordinatesOperation.
@Override
public CoordinatesOperation getCoordinatesOperation(final CoordinateSystem coordinateSystem) {
if (coordinateSystem == null || this == coordinateSystem) {
return null;
} else if (coordinateSystem instanceof GeographicCoordinateSystem) {
final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) coordinateSystem;
final Unit<Angle> angularUnit1 = getUnit();
// TODO GeodeticDatum shift
final Unit<Angle> angularUnit2 = geographicCoordinateSystem.getUnit();
if (!angularUnit1.equals(angularUnit2)) {
return new UnitConverstionOperation(angularUnit1, angularUnit2, 2);
} else {
return null;
}
} else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
final List<CoordinatesOperation> operations = new ArrayList<>();
final Unit<Angle> angularUnit1 = getUnit();
if (!angularUnit1.equals(NonSI.DEGREE_ANGLE)) {
CoordinatesOperation converstionOperation;
if (angularUnit1.equals(Units.RADIAN)) {
converstionOperation = RadiansToDegreesOperation.INSTANCE;
} else {
converstionOperation = new UnitConverstionOperation(angularUnit1, NonSI.DEGREE_ANGLE, 2);
}
operations.add(converstionOperation);
}
// TODO geodeticDatum shift
final CoordinatesOperation projectOperation = projectedCoordinateSystem.getProjectCoordinatesOperation();
if (projectOperation != null) {
operations.add(projectOperation);
}
final Unit<Length> linearUnit2 = projectedCoordinateSystem.getLengthUnit();
if (!linearUnit2.equals(Units.METRE)) {
operations.add(new UnitConverstionOperation(Units.METRE, linearUnit2));
}
switch(operations.size()) {
case 0:
return null;
case 1:
return operations.get(0);
default:
return new ChainedCoordinatesOperation(operations);
}
} else {
return null;
}
}
use of javax.measure.quantity.Angle in project uom-se by unitsofmeasurement.
the class PiMultiplierConverterTest method testAngleConverterOpposite.
@Test
public void testAngleConverterOpposite() {
Quantity<Angle> sut = Quantities.getQuantity(BigDecimal.ONE, Units.RADIAN).to(Units.DEGREE_ANGLE);
assertNotNull(sut);
assertEquals(Units.DEGREE_ANGLE, sut.getUnit());
assertEquals(new BigDecimal("57.29577951308232087679815481410517"), sut.getValue());
}
use of javax.measure.quantity.Angle in project uom-se by unitsofmeasurement.
the class PiMultiplierConverterTest method testAngleConverter.
@Test
public void testAngleConverter() {
Quantity<Angle> sut = Quantities.getQuantity(BigDecimal.ONE, Units.DEGREE_ANGLE).to(Units.RADIAN);
assertNotNull(sut);
assertEquals(Units.RADIAN, sut.getUnit());
assertEquals(new BigDecimal("0.01745329251994329576923690768488613"), sut.getValue());
}
Aggregations