Search in sources :

Example 1 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class ScaledIntegerTriangulatedIrregularNetworkReader method forEachTriangle.

public void forEachTriangle(final TriangleConsumer action) {
    open();
    final GeometryFactory geometryFactory = this.geometryFactory;
    final ChannelReader in = this.in;
    try {
        boolean hasMore = true;
        while (hasMore) {
            int triangleVertexCount = 0;
            try {
                final double x1 = geometryFactory.toDoubleX(in.getInt());
                final double y1 = geometryFactory.toDoubleY(in.getInt());
                final double z1 = geometryFactory.toDoubleZ(in.getInt());
                final double x2 = geometryFactory.toDoubleX(in.getInt());
                final double y2 = geometryFactory.toDoubleY(in.getInt());
                final double z2 = geometryFactory.toDoubleZ(in.getInt());
                final double x3 = geometryFactory.toDoubleX(in.getInt());
                final double y3 = geometryFactory.toDoubleY(in.getInt());
                final double z3 = geometryFactory.toDoubleZ(in.getInt());
                action.accept(x1, y1, z1, x2, y2, z2, x3, y3, z3);
                triangleVertexCount = 9;
            } catch (final WrappedException e) {
                if (Exceptions.isException(e, EOFException.class) && triangleVertexCount == 0) {
                    hasMore = false;
                } else {
                    throw e;
                }
            }
        }
    } finally {
        close();
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ChannelReader(com.revolsys.io.channels.ChannelReader)

Example 2 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class ScaledIntegerTriangulatedIrregularNetworkReader method newTriangulatedIrregularNetwork.

public TriangulatedIrregularNetwork newTriangulatedIrregularNetwork() {
    open();
    int capacity = 10;
    int[] triangleXCoordinates = new int[capacity];
    int[] triangleYCoordinates = new int[capacity];
    int[] triangleZCoordinates = new int[capacity];
    int coordinateIndex = 0;
    boolean hasMore = true;
    while (hasMore) {
        try {
            if (coordinateIndex >= capacity) {
                final int minCapacity = coordinateIndex + 1;
                capacity = capacity + (capacity >> 1);
                if (capacity - minCapacity < 0) {
                    capacity = minCapacity;
                }
                if (capacity - MAX_ARRAY_SIZE > 0) {
                    if (minCapacity < 0) {
                        throw new OutOfMemoryError();
                    } else if (minCapacity > MAX_ARRAY_SIZE) {
                        capacity = Integer.MAX_VALUE;
                    } else {
                        capacity = MAX_ARRAY_SIZE;
                    }
                }
                triangleXCoordinates = Arrays.copyOf(triangleXCoordinates, capacity);
                triangleYCoordinates = Arrays.copyOf(triangleYCoordinates, capacity);
                triangleZCoordinates = Arrays.copyOf(triangleZCoordinates, capacity);
            }
            triangleXCoordinates[coordinateIndex] = this.in.getInt();
            triangleYCoordinates[coordinateIndex] = this.in.getInt();
            triangleZCoordinates[coordinateIndex] = this.in.getInt();
            coordinateIndex++;
        } catch (final WrappedException e) {
            if (Exceptions.isException(e, EOFException.class) && coordinateIndex % 3 == 0) {
                hasMore = false;
            } else {
                throw e;
            }
        }
    }
    triangleXCoordinates = Arrays.copyOf(triangleXCoordinates, coordinateIndex);
    triangleYCoordinates = Arrays.copyOf(triangleYCoordinates, coordinateIndex);
    triangleZCoordinates = Arrays.copyOf(triangleZCoordinates, coordinateIndex);
    final int triangleCount = coordinateIndex / 3;
    final IntArrayScaleTriangulatedIrregularNetwork tin = new IntArrayScaleTriangulatedIrregularNetwork(this.geometryFactory, this.boundingBox, triangleCount, triangleXCoordinates, triangleYCoordinates, triangleZCoordinates);
    tin.setProperties(getProperties());
    return tin;
}
Also used : WrappedException(com.revolsys.util.WrappedException) IntArrayScaleTriangulatedIrregularNetwork(com.revolsys.elevation.tin.IntArrayScaleTriangulatedIrregularNetwork)

Example 3 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class AbstractScaledIntegerPointCloudGeometryReader method getNext.

@SuppressWarnings("unchecked")
@Override
protected G getNext() {
    final ChannelReader reader = this.reader;
    if (reader == null) {
        throw new NoSuchElementException();
    } else {
        try {
            final int xInt = reader.getInt();
            final int yInt = reader.getInt();
            final int zInt = reader.getInt();
            final double x = this.geometryFactory.toDoubleX(xInt);
            final double y = this.geometryFactory.toDoubleY(yInt);
            final double z = this.geometryFactory.toDoubleZ(zInt);
            return (G) this.geometryFactory.point(x, y, z);
        } catch (final WrappedException e) {
            if (e.getCause() instanceof EOFException) {
                throw new NoSuchElementException();
            } else {
                throw e;
            }
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordinateAxis.

private static IntHashMap<List<Axis>> loadCoordinateAxis() {
    final IntHashMap<List<Axis>> axisesByCoordinateSystemId = new IntHashMap<>();
    try (ChannelReader reader = newChannelReader("coordinateAxis")) {
        while (true) {
            final int coordinateSystemId = reader.getInt();
            final AxisName axisName = readCode(reader, AXIS_NAMES);
            final String orientation = reader.getStringUtf8ByteCount();
            final Character abbreviation = (char) reader.getByte();
            final UnitOfMeasure unitOfMeasure = readCode(reader, UNIT_BY_ID);
            final Axis axis = new Axis(axisName, orientation, abbreviation.toString(), unitOfMeasure);
            List<Axis> axises = axisesByCoordinateSystemId.get(coordinateSystemId);
            if (axises == null) {
                axises = new ArrayList<>();
                axisesByCoordinateSystemId.put(coordinateSystemId, axises);
            }
            axises.add(axis);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
    return axisesByCoordinateSystemId;
}
Also used : WrappedException(com.revolsys.util.WrappedException) UnitOfMeasure(com.revolsys.geometry.cs.unit.UnitOfMeasure) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) IntHashMap(com.revolsys.collection.map.IntHashMap) AxisName(com.revolsys.geometry.cs.AxisName) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) List(java.util.List) ArrayList(java.util.ArrayList) Axis(com.revolsys.geometry.cs.Axis)

Example 5 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordOperationMethod.

private static IntHashMap<CoordinateOperationMethod> loadCoordOperationMethod(final IntHashMap<List<ParameterName>> paramOrderByMethodId, final IntHashMap<List<Byte>> paramReversalByMethodId) {
    final IntHashMap<CoordinateOperationMethod> methodById = new IntHashMap<>();
    try (ChannelReader reader = newChannelReader("coordOperationMethod")) {
        while (true) {
            final int id = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final boolean reverse = readBoolean(reader);
            final boolean deprecated = readBoolean(reader);
            final List<ParameterName> parameterNames = paramOrderByMethodId.getOrDefault(id, Collections.emptyList());
            final List<Byte> reversal = paramReversalByMethodId.getOrDefault(id, Collections.emptyList());
            final CoordinateOperationMethod method = new CoordinateOperationMethod(id, name, reverse, deprecated, parameterNames);
            methodById.put(id, method);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
    return methodById;
}
Also used : WrappedException(com.revolsys.util.WrappedException) ParameterName(com.revolsys.geometry.cs.ParameterName) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) IntHashMap(com.revolsys.collection.map.IntHashMap) ChannelReader(com.revolsys.io.channels.ChannelReader) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) EOFException(java.io.EOFException)

Aggregations

WrappedException (com.revolsys.util.WrappedException)28 ChannelReader (com.revolsys.io.channels.ChannelReader)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 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 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)3 UnitOfMeasure (com.revolsys.geometry.cs.unit.UnitOfMeasure)3