use of com.revolsys.geometry.cs.projection.CoordinatesOperation in project com.revolsys.open by revolsys.
the class BoundingBox method convert.
default BoundingBox convert(final GeometryFactory geometryFactory) {
final GeometryFactory factory = getGeometryFactory();
if (isEmpty()) {
return geometryFactory.newBoundingBoxEmpty();
} else if (geometryFactory == null) {
return this;
} else if (factory == geometryFactory) {
return this;
} else {
if (factory == null || factory.getCoordinateSystem() == null) {
final int axisCount = Math.min(geometryFactory.getAxisCount(), getAxisCount());
final double[] minMaxValues = getMinMaxValues(axisCount);
return geometryFactory.newBoundingBox(axisCount, minMaxValues);
} else if (isEmpty()) {
return newBoundingBoxEmpty();
} else {
final CoordinatesOperation operation = factory.getCoordinatesOperation(geometryFactory);
if (operation != null) {
double xStep = getWidth() / 10;
double yStep = getHeight() / 10;
final double scaleXY = geometryFactory.getScaleXY();
if (scaleXY > 0) {
if (xStep < 1 / scaleXY) {
xStep = 1 / scaleXY;
}
if (yStep < 1 / scaleXY) {
yStep = 1 / scaleXY;
}
}
final double minX = getMinX();
final double maxX = getMaxX();
final double minY = getMinY();
final double maxY = getMaxY();
final double[] bounds = getMinMaxValues(2);
bounds[0] = Double.NaN;
bounds[1] = Double.NaN;
bounds[2] = Double.NaN;
bounds[3] = Double.NaN;
final double[] to = new double[2];
expand(geometryFactory, bounds, operation, to, minX, minY);
expand(geometryFactory, bounds, operation, to, minX, maxY);
expand(geometryFactory, bounds, operation, to, minX, minY);
expand(geometryFactory, bounds, operation, to, maxX, minY);
if (xStep != 0) {
for (double x = minX + xStep; x < maxX; x += xStep) {
expand(geometryFactory, bounds, operation, to, x, minY);
expand(geometryFactory, bounds, operation, to, x, maxY);
}
}
if (yStep != 0) {
for (double y = minY + yStep; y < maxY; y += yStep) {
expand(geometryFactory, bounds, operation, to, minX, y);
expand(geometryFactory, bounds, operation, to, maxX, y);
}
}
return geometryFactory.newBoundingBox(2, bounds);
} else {
return this;
}
}
}
}
use of com.revolsys.geometry.cs.projection.CoordinatesOperation in project com.revolsys.open by revolsys.
the class Geometry method forEachVertex.
default void forEachVertex(final GeometryFactory geometryFactory, final Consumer<double[]> action) {
if (!isEmpty()) {
int axisCount = getAxisCount();
final int axisCount2 = geometryFactory.getAxisCount();
if (axisCount2 < axisCount) {
axisCount = axisCount2;
}
final double[] coordinates = new double[axisCount];
if (isProjectionRequired(geometryFactory)) {
final CoordinatesOperation coordinatesOperation = getCoordinatesOperation(geometryFactory);
forEachVertex(coordinatesOperation, coordinates, action);
} else {
forEachVertex(coordinates, action);
}
}
}
use of com.revolsys.geometry.cs.projection.CoordinatesOperation in project com.revolsys.open by revolsys.
the class LineStringDouble method convertCoordinates.
@Override
public double[] convertCoordinates(GeometryFactory geometryFactory, final int axisCount) {
final GeometryFactory sourceGeometryFactory = getGeometryFactory();
final double[] sourceCoordinates = this.coordinates;
if (isEmpty()) {
return sourceCoordinates;
} else {
final int sourceAxisCount = this.axisCount;
final int vertexCount = this.vertexCount;
geometryFactory = getNonZeroGeometryFactory(geometryFactory);
final int targetAxisCount = axisCount;
double[] targetCoordinates;
final CoordinatesOperation coordinatesOperation = sourceGeometryFactory.getCoordinatesOperation(geometryFactory);
if (coordinatesOperation == null) {
if (sourceAxisCount == geometryFactory.getAxisCount()) {
return sourceCoordinates;
} else {
final double[] coordinates = new double[targetAxisCount * vertexCount];
int i = 0;
for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
for (int axisIndex = 0; axisIndex < targetAxisCount; axisIndex++) {
final double coordinate;
if (axisIndex < sourceAxisCount) {
coordinate = sourceCoordinates[vertexIndex * sourceAxisCount + axisIndex];
} else {
coordinate = Double.NaN;
}
coordinates[i++] = coordinate;
}
}
return coordinates;
}
} else {
targetCoordinates = new double[targetAxisCount * vertexCount];
coordinatesOperation.perform(sourceAxisCount, sourceCoordinates, targetAxisCount, targetCoordinates);
return targetCoordinates;
}
}
}
Aggregations