Search in sources :

Example 1 with LasPointFormat

use of com.revolsys.elevation.cloud.las.pointformat.LasPointFormat in project com.revolsys.open by revolsys.

the class LasPointCloud method forEachPointLazChunked.

private void forEachPointLazChunked(final ArithmeticDecoder decoder, final LazDecompress[] pointDecompressors, final Consumer<? super LasPoint> action) {
    final ChannelReader reader = this.reader;
    final long chunkTableOffset = reader.getLong();
    final long chunkSize = getLasZipHeader().getChunkSize();
    long chunkReadCount = chunkSize;
    final long pointCount = getPointCount();
    for (int i = 0; i < pointCount; i++) {
        final LasPoint point;
        final LasPointFormat pointFormat = getPointFormat();
        if (chunkSize == chunkReadCount) {
            point = pointFormat.readLasPoint(this, reader);
            for (final LazDecompress pointDecompressor : pointDecompressors) {
                pointDecompressor.init(point);
            }
            decoder.reset();
            chunkReadCount = 0;
        } else {
            point = pointFormat.newLasPoint(this);
            for (final LazDecompress pointDecompressor : pointDecompressors) {
                pointDecompressor.read(point);
            }
        }
        action.accept(point);
        chunkReadCount++;
    }
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader) LazDecompress(com.revolsys.elevation.cloud.las.zip.LazDecompress) LasPoint(com.revolsys.elevation.cloud.las.pointformat.LasPoint) LasPointFormat(com.revolsys.elevation.cloud.las.pointformat.LasPointFormat) LasPoint(com.revolsys.elevation.cloud.las.pointformat.LasPoint) Point(com.revolsys.geometry.model.Point)

Example 2 with LasPointFormat

use of com.revolsys.elevation.cloud.las.pointformat.LasPointFormat in project com.revolsys.open by revolsys.

the class LasPointCloud method forEachPointLazPointwise.

private void forEachPointLazPointwise(final ArithmeticDecoder decoder, final LazDecompress[] pointDecompressors, final Consumer<? super LasPoint> action) {
    final LasPointFormat pointFormat = getPointFormat();
    {
        final ChannelReader reader = this.reader;
        final LasPoint point = pointFormat.readLasPoint(this, reader);
        for (final LazDecompress pointDecompressor : pointDecompressors) {
            pointDecompressor.init(point);
        }
        decoder.reset();
        action.accept(point);
    }
    final long pointCount = getPointCount();
    for (int i = 1; i < pointCount; i++) {
        final LasPoint point = pointFormat.newLasPoint(this);
        for (final LazDecompress pointDecompressor : pointDecompressors) {
            pointDecompressor.read(point);
        }
        action.accept(point);
    }
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader) LazDecompress(com.revolsys.elevation.cloud.las.zip.LazDecompress) LasPointFormat(com.revolsys.elevation.cloud.las.pointformat.LasPointFormat) LasPoint(com.revolsys.elevation.cloud.las.pointformat.LasPoint) LasPoint(com.revolsys.elevation.cloud.las.pointformat.LasPoint) Point(com.revolsys.geometry.model.Point)

Example 3 with LasPointFormat

use of com.revolsys.elevation.cloud.las.pointformat.LasPointFormat in project com.revolsys.open by revolsys.

the class LasPointCloud method forEachPoint.

@Override
public void forEachPoint(final Consumer<? super LasPoint> action) {
    final long pointCount = getPointCount();
    try {
        final ChannelReader reader = this.reader;
        if (reader == null) {
            this.points.forEach(action);
        } else if (pointCount == 0) {
            this.reader = null;
        } else if (this.header.isLaszip()) {
            forEachPointLaz(action);
        } else {
            try (BaseCloseable closable = this) {
                final LasPointFormat pointFormat = getPointFormat();
                for (int i = 0; i < pointCount; i++) {
                    final LasPoint point = pointFormat.readLasPoint(this, reader);
                    action.accept(point);
                }
            }
        }
    } finally {
        this.reader = null;
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) ChannelReader(com.revolsys.io.channels.ChannelReader) LasPointFormat(com.revolsys.elevation.cloud.las.pointformat.LasPointFormat) LasPoint(com.revolsys.elevation.cloud.las.pointformat.LasPoint) LasPoint(com.revolsys.elevation.cloud.las.pointformat.LasPoint) Point(com.revolsys.geometry.model.Point)

Example 4 with LasPointFormat

use of com.revolsys.elevation.cloud.las.pointformat.LasPointFormat in project com.revolsys.open by revolsys.

the class LasProjection method setCoordinateSystem.

protected static void setCoordinateSystem(final LasPointCloudHeader header, final CoordinateSystem coordinateSystem) {
    if (coordinateSystem != null) {
        header.removeLasProperties(LASF_PROJECTION);
        final LasPointFormat pointFormat = header.getPointFormat();
        if (pointFormat.getId() <= 5) {
            final int coordinateSystemId = coordinateSystem.getCoordinateSystemId();
            int keyId;
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                keyId = TiffImage.PROJECTED_COORDINATE_SYSTEM_ID;
            } else {
                keyId = TiffImage.GEOGRAPHIC_COORDINATE_SYSTEM_ID;
            }
            final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(1024);
            try (final EndianOutput out = new EndianOutputStream(byteOut)) {
                out.writeLEUnsignedShort(1);
                out.writeLEUnsignedShort(1);
                out.writeLEUnsignedShort(0);
                out.writeLEUnsignedShort(1);
                {
                    out.writeLEUnsignedShort(keyId);
                    out.writeLEUnsignedShort(0);
                    out.writeLEUnsignedShort(1);
                    out.writeLEUnsignedShort(coordinateSystemId);
                }
            }
            final byte[] bytes = byteOut.toByteArray();
            final LasVariableLengthRecord property = new LasVariableLengthRecord(LASF_PROJECTION, LASF_PROJECTION_TIFF_GEO_KEY_DIRECTORY_TAG, "TIFF GeoKeyDirectoryTag", bytes, coordinateSystem);
            header.addProperty(property);
        } else {
            final String wkt = EpsgCoordinateSystems.toWkt(coordinateSystem);
            final byte[] stringBytes = wkt.getBytes(StandardCharsets.UTF_8);
            final byte[] bytes = new byte[stringBytes.length + 1];
            System.arraycopy(stringBytes, 0, bytes, 0, stringBytes.length);
            final LasVariableLengthRecord property = new LasVariableLengthRecord(LASF_PROJECTION, LASF_PROJECTION_WKT_COORDINATE_SYSTEM, "WKT", bytes, coordinateSystem);
            header.addProperty(property);
        }
    }
}
Also used : EndianOutput(com.revolsys.io.endian.EndianOutput) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) EndianOutputStream(com.revolsys.io.endian.EndianOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) LasPointFormat(com.revolsys.elevation.cloud.las.pointformat.LasPointFormat)

Aggregations

LasPointFormat (com.revolsys.elevation.cloud.las.pointformat.LasPointFormat)4 LasPoint (com.revolsys.elevation.cloud.las.pointformat.LasPoint)3 Point (com.revolsys.geometry.model.Point)3 ChannelReader (com.revolsys.io.channels.ChannelReader)3 LazDecompress (com.revolsys.elevation.cloud.las.zip.LazDecompress)2 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 EndianOutput (com.revolsys.io.endian.EndianOutput)1 EndianOutputStream (com.revolsys.io.endian.EndianOutputStream)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1