use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class IntArrayScaleTriangulatedIrregularNetwork method getTriangleSpatialIndex.
public QuadTree<Triangle> getTriangleSpatialIndex() {
if (this.triangleSpatialIndex == null) {
final QuadTree<Triangle> index = new QuadTree<>(this.geometryFactory);
forEachTriangle((x1, y1, z1, x2, y2, z2, x3, y3, z3) -> {
final Triangle triangle = new TriangleDoubleXYZ(x1, y1, z1, x2, y2, z2, x3, y3, z3);
final BoundingBox boundingBox = triangle.getBoundingBox();
index.insertItem(boundingBox, triangle);
});
this.triangleSpatialIndex = index;
}
return this.triangleSpatialIndex;
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class TriangulatedIrregularNetwork method getTriangles.
default List<Triangle> getTriangles(final LineSegment segment) {
final BoundingBox boundingBox = segment.getBoundingBox();
final List<Triangle> triangles = new ArrayList<>();
forEachTriangle(boundingBox, triangles::add);
return triangles;
}
use of com.revolsys.geometry.model.BoundingBox 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.model.BoundingBox in project com.revolsys.open by revolsys.
the class IntArrayScaleGriddedElevationModel method resample.
@Override
public GriddedElevationModel resample(final int newGridCellSize) {
final double gridCellSize = getGridCellSize();
final double cellRatio = gridCellSize / newGridCellSize;
final int step = (int) Math.round(1 / cellRatio);
final int gridWidth = getGridWidth();
final int gridHeight = getGridHeight();
final int newGridWidth = (int) Math.round(gridWidth * cellRatio);
final int newGridHeight = (int) Math.round(gridHeight * cellRatio);
final GeometryFactory geometryFactory = getGeometryFactory();
final int[] oldElevations = this.elevations;
final int[] newElevations = new int[newGridWidth * newGridHeight];
int newIndex = 0;
for (int gridYMin = 0; gridYMin < gridHeight; gridYMin += step) {
final int gridYMax = gridYMin + step;
for (int gridXMin = 0; gridXMin < gridWidth; gridXMin += step) {
final int gridXMax = gridXMin + step;
int count = 0;
long sum = 0;
for (int gridY = gridYMin; gridY < gridYMax; gridY++) {
for (int gridX = gridXMin; gridX < gridXMax; gridX++) {
final int elevation = oldElevations[gridY * gridWidth + gridX];
if (elevation != NULL_VALUE) {
count++;
sum += elevation;
}
}
}
if (count > 0) {
newElevations[newIndex] = (int) (sum / count);
} else {
newElevations[newIndex] = NULL_VALUE;
}
newIndex++;
}
}
final BoundingBox boundingBox = getBoundingBox();
final GriddedElevationModel newDem = new IntArrayScaleGriddedElevationModel(geometryFactory, boundingBox, newGridWidth, newGridHeight, newGridCellSize, newElevations);
return newDem;
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class EsriAsciiGriddedElevationModelWriter method write.
@Override
public void write(final GriddedElevationModel model) {
final String nodataValue = DataTypes.toString(model.getProperty("nodataValue", "-9999"));
if (this.resource == null) {
throw new IllegalStateException("Writer is closed");
} else {
open(model);
try {
final BoundingBox boundingBox = model.getBoundingBox();
final int width = model.getGridWidth();
final int height = model.getGridHeight();
final double cellSize = model.getGridCellSize();
this.writer.write("NCOLS ");
this.writer.write(Integers.toString(width));
this.writer.write('\n');
this.writer.write("NROWS ");
this.writer.write(Integers.toString(height));
this.writer.write('\n');
this.writer.write("XLLCORNER ");
this.writer.write(Doubles.toString(boundingBox.getMinX()));
this.writer.write('\n');
this.writer.write("YLLCORNER ");
this.writer.write(Doubles.toString(boundingBox.getMinY()));
this.writer.write('\n');
this.writer.write("CELLSIZE ");
this.writer.write(Doubles.toString(cellSize));
this.writer.write('\n');
this.writer.write("NODATA_VALUE ");
this.writer.write(nodataValue);
this.writer.write('\n');
for (int gridY = height - 1; gridY >= 0; gridY--) {
for (int gridX = 0; gridX < width; gridX++) {
final double elevation = model.getElevation(gridX, gridY);
if (Double.isFinite(elevation)) {
final String elevationString = Doubles.toString(elevation);
this.writer.write(elevationString);
} else {
this.writer.write(nodataValue);
}
this.writer.write(' ');
}
this.writer.write('\n');
}
this.writer.write('\n');
} catch (final Throwable e) {
throw Exceptions.wrap("Unable to write to: " + this.resource, e);
} finally {
close();
}
}
}
Aggregations