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);
}
}
}
Aggregations