Search in sources :

Example 1 with IntArrayScaleGriddedElevationModel

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

Example 2 with IntArrayScaleGriddedElevationModel

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

Example 3 with IntArrayScaleGriddedElevationModel

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;
}
Also used : TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) BoundingBox(com.revolsys.geometry.model.BoundingBox) IntArrayScaleGriddedElevationModel(com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel) Point(com.revolsys.geometry.model.Point)

Example 4 with IntArrayScaleGriddedElevationModel

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;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) IntArrayScaleGriddedElevationModel(com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel) GriddedElevationModel(com.revolsys.elevation.gridded.GriddedElevationModel) IntArrayScaleGriddedElevationModel(com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel)

Example 5 with IntArrayScaleGriddedElevationModel

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

Aggregations

IntArrayScaleGriddedElevationModel (com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel)8 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 IOException (java.io.IOException)3 GriddedElevationModel (com.revolsys.elevation.gridded.GriddedElevationModel)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 Point (com.revolsys.geometry.model.Point)2 ChannelReader (com.revolsys.io.channels.ChannelReader)2 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)2 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)1 IntBuffer (java.nio.IntBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1