use of com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelWriter method write.
@Override
public void write(final GriddedElevationModel elevationModel) {
open();
try {
writeHeader(elevationModel);
if (elevationModel instanceof IntArrayScaleGriddedElevationModel) {
final IntArrayScaleGriddedElevationModel scaleModel = (IntArrayScaleGriddedElevationModel) elevationModel;
scaleModel.writeIntArray(this, this.writer);
} else {
writeGrid(elevationModel);
}
} catch (final IOException e) {
Exceptions.throwUncheckedException(e);
}
}
use of com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel in project com.revolsys.open by revolsys.
the class BynReader method read.
@Override
public GriddedElevationModel read() {
init();
if (this.exists) {
try {
final ChannelReader reader = this.reader;
final int gridWidth = this.gridWidth;
final int gridHeight = this.gridHeight;
final int cellCount = gridWidth * gridHeight;
final int[] elevations = new int[cellCount];
for (int gridY = gridHeight - 1; gridY >= 0; gridY--) {
int index = gridY * gridWidth;
for (int gridX = 0; gridX < gridWidth; gridX++) {
final int elevation = reader.getInt();
elevations[index++] = elevation;
}
}
final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(this.geometryFactory, this.boundingBox, gridWidth, gridHeight, this.gridCellSize, elevations);
elevationModel.setResource(this.resource);
return elevationModel;
} catch (final RuntimeException e) {
if (Exceptions.isException(e, ClosedByInterruptException.class)) {
return null;
} else {
throw Exceptions.wrap("Unable to read DEM: " + this.resource, e);
}
}
} else {
return null;
}
}
use of com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel in project com.revolsys.open by revolsys.
the class PointCloud method newGriddedElevationModel.
default GriddedElevationModel newGriddedElevationModel(final Map<String, ? extends Object> properties) {
final TriangulatedIrregularNetwork tin = newTriangulatedIrregularNetwork();
final BoundingBox boundingBox = getBoundingBox();
final int minX = (int) Math.floor(boundingBox.getMinX());
final int minY = (int) Math.floor(boundingBox.getMinY());
final int maxX = (int) Math.ceil(boundingBox.getMaxX());
final int maxY = (int) Math.ceil(boundingBox.getMaxY());
final int width = maxX - minX;
final int height = maxY - minY;
final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(getGeometryFactory().convertAxisCountAndScales(3, 1000.0, 1000.0, 1000.0), minX, minY, width, height, 1);
tin.forEachTriangle(elevationModel::setElevationsForTriangle);
return null;
}
use of com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel in project com.revolsys.open by revolsys.
the class GriddedElevationModelTest method newIntArrayModelNaNOnDiagonal.
/**
* Create a new {@link IntArrayScaleGriddedElevationModel}.
* The elevation for each cell is set to gridX.gridY (e.g. 10.34).
* Except where gridX == gridY where NaN is used.
*
* @param coordinateSystemId The coordinate system id.
* @return The model
*/
protected static GriddedElevationModel newIntArrayModelNaNOnDiagonal(final int coordinateSystemId) {
final GeometryFactory geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, 1000.0, 1000.0, 1000.0);
final GriddedElevationModel model = new IntArrayScaleGriddedElevationModel(geometryFactory, 0, 0, 255, 255, 1);
for (int gridY = 0; gridY < model.getGridHeight() - 1; gridY++) {
for (int gridX = 0; gridX < model.getGridWidth() - 1; gridX++) {
double elevation;
if (gridX == gridY) {
elevation = Double.NaN;
} else {
elevation = gridX + gridY / 1000.0;
}
model.setElevation(gridX, gridY, elevation);
}
}
return model;
}
use of com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelReader method read.
@Override
public GriddedElevationModel read() {
init();
if (this.exists) {
try {
final ChannelReader in = this.reader;
final int cellCount = this.gridWidth * this.gridHeight;
final int[] elevations = new int[cellCount];
final ReadableByteChannel channel = in.getChannel();
if (isMemoryMapped() && channel instanceof FileChannel) {
final FileChannel fileChannel = (FileChannel) channel;
final MappedByteBuffer mappedBytes = fileChannel.map(MapMode.READ_ONLY, ScaledIntegerGriddedDigitalElevation.HEADER_SIZE, cellCount * ScaledIntegerGriddedDigitalElevation.RECORD_SIZE);
final IntBuffer intBuffer = mappedBytes.asIntBuffer();
for (int index = 0; index < cellCount; index++) {
elevations[index] = intBuffer.get();
}
} else {
for (int index = 0; index < cellCount; index++) {
final int elevation = in.getInt();
elevations[index] = elevation;
}
}
final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(this.geometryFactory, this.boundingBox, this.gridWidth, this.gridHeight, this.gridCellSize, elevations);
elevationModel.setResource(this.resource);
return elevationModel;
} catch (final ClosedByInterruptException e) {
return null;
} catch (final IOException | RuntimeException e) {
if (Exceptions.isException(e, ClosedByInterruptException.class)) {
return null;
} else {
throw Exceptions.wrap("Unable to read DEM: " + this.resource, e);
}
}
} else {
return null;
}
}
Aggregations