Search in sources :

Example 1 with ChainedCoordinatesOperation

use of com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation in project com.revolsys.open by revolsys.

the class ProjectedCoordinateSystem method getCoordinatesOperation.

@Override
public CoordinatesOperation getCoordinatesOperation(final CoordinateSystem coordinateSystem) {
    if (coordinateSystem == null || this == coordinateSystem) {
        return null;
    } else {
        final List<CoordinatesOperation> operations = new ArrayList<>();
        final CoordinatesOperation inverseOperation = this.getInverseCoordinatesOperation();
        if (inverseOperation == null) {
            return null;
        }
        final Unit<Length> linearUnit1 = this.getLengthUnit();
        if (!linearUnit1.equals(Units.METRE)) {
            operations.add(new UnitConverstionOperation(linearUnit1, Units.METRE));
        }
        operations.add(inverseOperation);
        if (coordinateSystem instanceof ProjectedCoordinateSystem) {
            final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
            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));
            }
        } else if (coordinateSystem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) coordinateSystem;
            final Unit<Angle> angularUnit2 = geographicCoordinateSystem.getUnit();
            if (!angularUnit2.equals(NonSI.DEGREE_ANGLE)) {
                operations.add(new UnitConverstionOperation(NonSI.DEGREE_ANGLE, angularUnit2, 2));
            }
        } else {
            return null;
        }
        switch(operations.size()) {
            case 0:
                return null;
            case 1:
                return operations.get(0);
            default:
                return new ChainedCoordinatesOperation(operations);
        }
    }
}
Also used : Length(javax.measure.quantity.Length) ArrayList(java.util.ArrayList) ChainedCoordinatesOperation(com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation) ChainedCoordinatesOperation(com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation) Unit(javax.measure.Unit) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) UnitConverstionOperation(com.revolsys.geometry.cs.projection.UnitConverstionOperation)

Example 2 with ChainedCoordinatesOperation

use of com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation 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)

Aggregations

ChainedCoordinatesOperation (com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation)2 CoordinatesOperation (com.revolsys.geometry.cs.projection.CoordinatesOperation)2 UnitConverstionOperation (com.revolsys.geometry.cs.projection.UnitConverstionOperation)2 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)2 ArrayList (java.util.ArrayList)2 Unit (javax.measure.Unit)2 Length (javax.measure.quantity.Length)2 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)1 Angle (javax.measure.quantity.Angle)1