Search in sources :

Example 1 with ChannelReader

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;
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader)

Example 2 with ChannelReader

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;
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ChannelReader(com.revolsys.io.channels.ChannelReader) IntArrayScaleGriddedElevationModel(com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel)

Example 3 with ChannelReader

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();
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ChannelReader(com.revolsys.io.channels.ChannelReader)

Example 4 with ChannelReader

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();
    }
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader)

Example 5 with ChannelReader

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;
            }
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ChannelReader (com.revolsys.io.channels.ChannelReader)34 WrappedException (com.revolsys.util.WrappedException)20 EOFException (java.io.EOFException)19 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)14 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)12 ParameterName (com.revolsys.geometry.cs.ParameterName)7 Area (com.revolsys.geometry.cs.Area)4 Authority (com.revolsys.geometry.cs.Authority)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 LasPoint (com.revolsys.elevation.cloud.las.pointformat.LasPoint)3 LasPointFormat (com.revolsys.elevation.cloud.las.pointformat.LasPointFormat)3 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)3 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)3 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)3 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)3 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)3