Search in sources :

Example 1 with CoordinatesOperation

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

the class GriddedElevationModel method forEachPointFinite.

default void forEachPointFinite(final BoundingBox boundingBox, final Consumer<Point> action) {
    final GeometryFactory targetGeometryFactory = boundingBox.getGeometryFactory();
    final GeometryFactory geometryFactory = getGeometryFactory();
    final CoordinatesOperation projection = geometryFactory.getCoordinatesOperation(targetGeometryFactory);
    final BoundingBox convertexBoundingBox = boundingBox.convert(geometryFactory);
    final double gridCellSize = getGridCellSize();
    final double minY = getGridMinY();
    final double minX = getGridMinX();
    final int gridWidth = getGridWidth();
    final int gridHeight = getGridHeight();
    int startGridX = (int) Math.floor((convertexBoundingBox.getMinX() - minX) / gridCellSize);
    if (startGridX < 0) {
        startGridX = 0;
    }
    int endGridX = (int) Math.ceil((convertexBoundingBox.getMaxX() - minX) / gridCellSize);
    if (endGridX > gridWidth) {
        endGridX = gridWidth;
    }
    int startGridY = (int) Math.floor((convertexBoundingBox.getMinY() - minY) / gridCellSize);
    if (startGridY < 0) {
        startGridY = 0;
    }
    int endGridY = (int) Math.ceil((convertexBoundingBox.getMaxY() - minY) / gridCellSize);
    if (endGridY > gridHeight) {
        endGridY = gridHeight;
    }
    if (projection == null) {
        for (int gridY = startGridY; gridY < endGridY; gridY++) {
            final double y = minY + gridY * gridCellSize;
            for (int gridX = startGridX; gridX < endGridX; gridX++) {
                final double x = minX + gridX * gridCellSize;
                final double z = getElevationFast(gridX, gridY);
                if (Double.isFinite(z)) {
                    if (boundingBox.covers(x, y)) {
                        final Point point = targetGeometryFactory.point(x, y, z);
                        action.accept(point);
                    }
                }
            }
        }
    } else {
        final double[] coordinates = new double[2];
        for (int gridY = startGridY; gridY < endGridY; gridY++) {
            final double y = minY + gridY * gridCellSize;
            for (int gridX = startGridX; gridX < endGridX; gridX++) {
                final double x = minX + gridX * gridCellSize;
                final double z = getElevationFast(gridX, gridY);
                if (Double.isFinite(z)) {
                    coordinates[0] = x;
                    coordinates[1] = y;
                    projection.perform(2, coordinates, 2, coordinates);
                    final double targetX = coordinates[0];
                    final double targetY = coordinates[1];
                    if (boundingBox.covers(targetX, targetY)) {
                        final Point point = targetGeometryFactory.point(targetX, targetY, z);
                        action.accept(point);
                    }
                }
            }
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation) Point(com.revolsys.geometry.model.Point)

Example 2 with CoordinatesOperation

use of com.revolsys.geometry.cs.projection.CoordinatesOperation 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 3 with CoordinatesOperation

use of com.revolsys.geometry.cs.projection.CoordinatesOperation 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 4 with CoordinatesOperation

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

the class LineString method intersects.

@Override
default boolean intersects(final BoundingBox boundingBox) {
    if (isEmpty() || boundingBox.isEmpty()) {
        return false;
    } else {
        final double minX = boundingBox.getMinX();
        final double maxX = boundingBox.getMaxX();
        final double minY = boundingBox.getMinY();
        final double maxY = boundingBox.getMaxY();
        final int vertexCount = getVertexCount();
        final GeometryFactory geometryFactory = boundingBox.getGeometryFactory();
        final CoordinatesOperation coordinatesOperation = getCoordinatesOperation(geometryFactory);
        if (coordinatesOperation == null) {
            double previousX = getX(0);
            double previousY = getY(0);
            for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
                final double x = getX(vertexIndex);
                final double y = getY(vertexIndex);
                if (// 
                RectangleUtil.intersectsLine(// 
                minX, // 
                minY, // 
                maxX, // 
                maxY, previousX, previousY, x, y)) {
                    return true;
                }
                previousX = x;
                previousY = y;
            }
        } else {
            final double[] coordinates = new double[] { getX(0), getY(0) };
            coordinatesOperation.perform(2, coordinates, 2, coordinates);
            double previousX = coordinates[X];
            double previousY = coordinates[Y];
            for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
                coordinates[X] = getX(vertexIndex);
                coordinates[Y] = getY(vertexIndex);
                coordinatesOperation.perform(2, coordinates, 2, coordinates);
                final double x = coordinates[X];
                final double y = coordinates[Y];
                if (// 
                RectangleUtil.intersectsLine(// 
                minX, // 
                minY, // 
                maxX, // 
                maxY, previousX, previousY, x, y)) {
                    return true;
                }
                previousX = x;
                previousY = y;
            }
        }
        return false;
    }
}
Also used : CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Example 5 with CoordinatesOperation

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

the class LineString method convertVertexCoordinates2d.

default void convertVertexCoordinates2d(final int vertexIndex, final GeometryFactory geometryFactory, final double[] targetCoordinates) {
    final double x = getX(vertexIndex);
    final double y = getY(vertexIndex);
    targetCoordinates[X] = x;
    targetCoordinates[Y] = y;
    final CoordinatesOperation coordinatesOperation = getGeometryFactory().getCoordinatesOperation(geometryFactory);
    if (coordinatesOperation != null) {
        coordinatesOperation.perform(2, targetCoordinates, 2, targetCoordinates);
    }
}
Also used : CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Aggregations

CoordinatesOperation (com.revolsys.geometry.cs.projection.CoordinatesOperation)13 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 ChainedCoordinatesOperation (com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation)2 UnitConverstionOperation (com.revolsys.geometry.cs.projection.UnitConverstionOperation)2 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)2 Point (com.revolsys.geometry.model.Point)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 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 BoundingBoxDoubleXYGeometryFactory (com.revolsys.geometry.model.impl.BoundingBoxDoubleXYGeometryFactory)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 Angle (javax.measure.quantity.Angle)1