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);
}
}
}
}
}
}
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);
}
}
}
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;
}
}
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;
}
}
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);
}
}
Aggregations