Search in sources :

Example 31 with ChannelReader

use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.

the class EsriCoordinateSystems method getGeographicCoordinateSystem.

public static GeographicCoordinateSystem getGeographicCoordinateSystem(final int id) {
    GeographicCoordinateSystem coordinateSystem = (GeographicCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Geographic.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final String datumName = reader.getStringUtf8ByteCount();
                final String spheroidName = reader.getStringUtf8ByteCount();
                final double semiMajorAxis = reader.getDouble();
                final double inverseFlattening = reader.getDouble();
                final String primeMeridianName = reader.getStringUtf8ByteCount();
                final double longitude = reader.getDouble();
                final String angularUnitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    final Ellipsoid ellipsoid = new Ellipsoid(spheroidName, semiMajorAxis, inverseFlattening, null);
                    final PrimeMeridian primeMeridian = new PrimeMeridian(primeMeridianName, longitude, null);
                    final GeodeticDatum geodeticDatum = new GeodeticDatum(null, datumName, null, false, ellipsoid, primeMeridian);
                    AngularUnit angularUnit = ANGULAR_UNITS_BY_NAME.get(angularUnitName);
                    if (angularUnit == null) {
                        angularUnit = new AngularUnit(angularUnitName, conversionFactor, null);
                        ANGULAR_UNITS_BY_NAME.put(angularUnitName, angularUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    coordinateSystem = new GeographicCoordinateSystem(coordinateSystemId, csName, geodeticDatum, primeMeridian, angularUnit, null, authority);
                    COORDINATE_SYSTEM_BY_ID.put(id, coordinateSystem);
                    return coordinateSystem;
                }
            }
        } catch (final WrappedException e) {
            if (Exceptions.isException(e, EOFException.class)) {
                return null;
            } else {
                Logs.error("Cannot load coordinate system=" + id, e);
                throw e;
            }
        }
    }
    return coordinateSystem;
}
Also used : BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) WrappedException(com.revolsys.util.WrappedException) Authority(com.revolsys.geometry.cs.Authority) BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) AngularUnit(com.revolsys.geometry.cs.unit.AngularUnit) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 32 with ChannelReader

use of com.revolsys.io.channels.ChannelReader 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 33 with ChannelReader

use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.

the class ArithmeticDecoder method reset.

public void reset() {
    this.length = AC_MAX_LENGTH;
    final ChannelReader reader = this.reader;
    int value = (reader.getByte() & 0xff) << 24;
    value |= (reader.getByte() & 0xff) << 16;
    value |= (reader.getByte() & 0xff) << 8;
    value |= reader.getByte() & 0xff;
    this.value = value;
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader)

Example 34 with ChannelReader

use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.

the class AbstractScaledIntegerPointCloudGeometryReader method initDo.

@Override
protected void initDo() {
    super.initDo();
    final ChannelReader reader = this.resource.newChannelReader(this.byteBuffer);
    this.reader = reader;
    if (reader == null) {
        this.exists = false;
    } else {
        this.exists = true;
        // File
        final String fileType = reader.getString(4, StandardCharsets.UTF_8);
        // type
        if (!ScaledIntegerPointCloud.FILE_TYPE_HEADER.equals(fileType)) {
            throw new IllegalArgumentException("File must start with the text: " + ScaledIntegerPointCloud.FILE_TYPE_HEADER + " not " + fileType);
        }
        @SuppressWarnings("unused") final short version = reader.getShort();
        @SuppressWarnings("unused") final short flags = reader.getShort();
        this.geometryFactory = GeometryFactory.readOffsetScaled3d(reader);
    }
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader)

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