Search in sources :

Example 16 with ChannelReader

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

the class EpsgCoordinateSystems method loadCoordOperationParam.

private static void loadCoordOperationParam() {
    try (ChannelReader reader = newChannelReader("coordOperationParam")) {
        while (true) {
            final int id = reader.getInt();
            String name = reader.getStringUtf8ByteCount();
            if (name != null) {
                name = name.toLowerCase().replaceAll(" ", "_");
            }
            readBoolean(reader);
            final ParameterName parameterName = ParameterNames.getParameterName(id, name);
            PARAM_NAME_BY_ID.put(id, parameterName);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
}
Also used : NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) ParameterName(com.revolsys.geometry.cs.ParameterName) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString)

Example 17 with ChannelReader

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

the class EsriCoordinateSystems method getVerticalCoordinateSystem.

public static VerticalCoordinateSystem getVerticalCoordinateSystem(final int id) {
    VerticalCoordinateSystem coordinateSystem = (VerticalCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Vertical.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final String datumName = reader.getStringUtf8ByteCount();
                final Map<ParameterName, ParameterValue> parameters = readParameters(reader);
                final String linearUnitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    final VerticalDatum verticalDatum = new VerticalDatum(null, datumName, 0);
                    LinearUnit linearUnit = LINEAR_UNITS_BY_NAME.get(linearUnitName);
                    if (linearUnit == null) {
                        linearUnit = new LinearUnit(linearUnitName, conversionFactor, null);
                        LINEAR_UNITS_BY_NAME.put(linearUnitName, linearUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    coordinateSystem = new VerticalCoordinateSystem(authority, csName, verticalDatum, parameters, linearUnit, Collections.emptyList());
                    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) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) Authority(com.revolsys.geometry.cs.Authority) BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) ParameterName(com.revolsys.geometry.cs.ParameterName) SingleParameterName(com.revolsys.geometry.cs.SingleParameterName) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ChannelReader(com.revolsys.io.channels.ChannelReader) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EOFException(java.io.EOFException)

Example 18 with ChannelReader

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

the class EsriCoordinateSystems method getCoordinateSystemIdsByDigest.

private static List<Integer> getCoordinateSystemIdsByDigest(final CoordinateSystem coordinateSystem, final ByteArray digest) {
    List<Integer> ids = COORDINATE_SYSTEM_IDS_BY_DIGEST.get(digest);
    if (ids == null) {
        final byte[] bytes = new byte[16];
        final ByteArray newDigest = new ByteArray(bytes);
        final String type = coordinateSystem.getCoordinateSystemType();
        try (ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/" + type + ".digest")) {
            while (true) {
                reader.getBytes(bytes);
                final short count = reader.getShort();
                if (digest.equals(newDigest)) {
                    ids = new ArrayList<>();
                    for (int i = 0; i < count; i++) {
                        final int csId = reader.getInt();
                        ids.add(csId);
                    }
                    COORDINATE_SYSTEM_IDS_BY_DIGEST.put(digest, ids);
                    return ids;
                } else {
                    for (int i = 0; i < count; i++) {
                        reader.getInt();
                    }
                }
            }
        } catch (final WrappedException e) {
            if (Exceptions.isException(e, EOFException.class)) {
                return Collections.emptyList();
            } else {
                throw e;
            }
        }
    } else {
        return ids;
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException)

Example 19 with ChannelReader

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

Example 20 with ChannelReader

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

the class ScaledIntegerGriddedDigitalElevationModelFile method getFileChannel.

private FileChannel getFileChannel() throws IOException {
    if (this.channel == null && isOpen()) {
        try {
            this.channel = FileChannel.open(this.path, this.openOptions, this.fileAttributes);
            this.reader = new ChannelReader(this.channel);
        } catch (final NoSuchFileException e) {
            if (this.createMissing) {
                createNewFile();
            } else {
                throw e;
            }
        }
        if (!isOpen()) {
            close();
            return null;
        }
    }
    return this.channel;
}
Also used : ChannelReader(com.revolsys.io.channels.ChannelReader) NoSuchFileException(java.nio.file.NoSuchFileException)

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