Search in sources :

Example 6 with Angle

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;
}
Also used : Path(java.nio.file.Path) NoninvertibleTransformException(org.opengis.referencing.operation.NoninvertibleTransformException) Parameters(org.apache.sis.parameter.Parameters) Angle(javax.measure.quantity.Angle) MathTransform(org.opengis.referencing.operation.MathTransform) InvalidParameterValueException(org.opengis.parameter.InvalidParameterValueException) Length(javax.measure.quantity.Length) FactoryException(org.opengis.util.FactoryException)

Example 7 with Angle

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);
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) NoninvertibleTransformException(org.opengis.referencing.operation.NoninvertibleTransformException) Angle(javax.measure.quantity.Angle) Length(javax.measure.quantity.Length) BufferedReader(java.io.BufferedReader) Cache(org.apache.sis.util.collection.Cache)

Example 8 with Angle

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;
    }
}
Also used : Angle(javax.measure.quantity.Angle) Length(javax.measure.quantity.Length) ArrayList(java.util.ArrayList) ChainedCoordinatesOperation(com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation) Unit(javax.measure.Unit) AngularUnit(com.revolsys.geometry.cs.unit.AngularUnit) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ChainedCoordinatesOperation(com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation) UnitConverstionOperation(com.revolsys.geometry.cs.projection.UnitConverstionOperation)

Example 9 with Angle

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());
}
Also used : Angle(javax.measure.quantity.Angle) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 10 with Angle

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());
}
Also used : Angle(javax.measure.quantity.Angle) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Angle (javax.measure.quantity.Angle)19 Length (javax.measure.quantity.Length)7 Path (java.nio.file.Path)3 Unit (javax.measure.Unit)3 Convention (org.apache.sis.io.wkt.Convention)3 CartesianCS (org.opengis.referencing.cs.CartesianCS)3 GeodeticDatum (org.opengis.referencing.datum.GeodeticDatum)3 FactoryException (org.opengis.util.FactoryException)3 BufferedReader (java.io.BufferedReader)2 BigDecimal (java.math.BigDecimal)2 Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)2 Test (org.junit.Test)2 Envelope (org.opengis.geometry.Envelope)2 Identifier (org.opengis.metadata.Identifier)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)2 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)2 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)1