Search in sources :

Example 1 with EndianOutput

use of com.revolsys.io.endian.EndianOutput 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)1 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 EndianOutput (com.revolsys.io.endian.EndianOutput)1 EndianOutputStream (com.revolsys.io.endian.EndianOutputStream)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1