use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelReader method close.
@Override
public void close() {
super.close();
final ChannelReader reader = this.reader;
this.reader = null;
if (reader != null) {
reader.close();
}
this.resource = null;
}
use of com.revolsys.io.channels.ChannelReader 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.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class ScaledIntegerTriangulatedIrregularNetworkReader method forEachTriangle.
public void forEachTriangle(final TriangleConsumer action) {
open();
final GeometryFactory geometryFactory = this.geometryFactory;
final ChannelReader in = this.in;
try {
boolean hasMore = true;
while (hasMore) {
int triangleVertexCount = 0;
try {
final double x1 = geometryFactory.toDoubleX(in.getInt());
final double y1 = geometryFactory.toDoubleY(in.getInt());
final double z1 = geometryFactory.toDoubleZ(in.getInt());
final double x2 = geometryFactory.toDoubleX(in.getInt());
final double y2 = geometryFactory.toDoubleY(in.getInt());
final double z2 = geometryFactory.toDoubleZ(in.getInt());
final double x3 = geometryFactory.toDoubleX(in.getInt());
final double y3 = geometryFactory.toDoubleY(in.getInt());
final double z3 = geometryFactory.toDoubleZ(in.getInt());
action.accept(x1, y1, z1, x2, y2, z2, x3, y3, z3);
triangleVertexCount = 9;
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class) && triangleVertexCount == 0) {
hasMore = false;
} else {
throw e;
}
}
}
} finally {
close();
}
}
use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class AbstractScaledIntegerPointCloudGeometryReader method closeDo.
@Override
protected void closeDo() {
super.closeDo();
final ChannelReader reader = this.reader;
this.reader = null;
if (reader != null) {
reader.close();
}
}
use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class AbstractScaledIntegerPointCloudGeometryReader method getNext.
@SuppressWarnings("unchecked")
@Override
protected G getNext() {
final ChannelReader reader = this.reader;
if (reader == null) {
throw new NoSuchElementException();
} else {
try {
final int xInt = reader.getInt();
final int yInt = reader.getInt();
final int zInt = reader.getInt();
final double x = this.geometryFactory.toDoubleX(xInt);
final double y = this.geometryFactory.toDoubleY(yInt);
final double z = this.geometryFactory.toDoubleZ(zInt);
return (G) this.geometryFactory.point(x, y, z);
} catch (final WrappedException e) {
if (e.getCause() instanceof EOFException) {
throw new NoSuchElementException();
} else {
throw e;
}
}
}
}
Aggregations