Search in sources :

Example 11 with NoSuchResourceException

use of com.revolsys.spring.resource.NoSuchResourceException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordinateSystem.

private static void loadCoordinateSystem() {
    try (ChannelReader reader = newChannelReader("coordinateSystem")) {
        while (true) {
            final int id = reader.getInt();
            final int type = reader.getByte();
            final boolean deprecated = readBoolean(reader);
            final CoordinateSystemType coordinateSystemType = new CoordinateSystemType(id, type, deprecated);
            COORDINATE_SYSTEM_TYPE_BY_ID.put(id, coordinateSystemType);
        }
    } 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) CoordinateSystemType(com.revolsys.geometry.cs.CoordinateSystemType) EOFException(java.io.EOFException)

Example 12 with NoSuchResourceException

use of com.revolsys.spring.resource.NoSuchResourceException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadUnitOfMeasure.

private static void loadUnitOfMeasure() {
    try (ChannelReader reader = newChannelReader("unitOfMeasure")) {
        if (reader != null) {
            while (true) {
                final int id = reader.getInt();
                final byte type = reader.getByte();
                final int baseId = reader.getInt();
                final boolean deprecated = readBoolean(reader);
                final double conversionFactorB = reader.getDouble();
                final double conversionFactorC = reader.getDouble();
                double conversionFactor;
                if (Double.isFinite(conversionFactorB)) {
                    if (Double.isFinite(conversionFactorC)) {
                        conversionFactor = conversionFactorB / conversionFactorC;
                    } else {
                        conversionFactor = conversionFactorB;
                    }
                } else {
                    conversionFactor = conversionFactorC;
                }
                final String name = reader.getStringUtf8ByteCount();
                final EpsgAuthority authority = new EpsgAuthority(id);
                UnitOfMeasure unit;
                switch(type) {
                    case 0:
                        final ScaleUnit baseScaleUnit = (ScaleUnit) UNIT_BY_ID.get(baseId);
                        unit = new ScaleUnit(name, baseScaleUnit, conversionFactor, authority, deprecated);
                        break;
                    case 1:
                        final LinearUnit baseLinearUnit = (LinearUnit) UNIT_BY_ID.get(baseId);
                        if (id == 9001) {
                            unit = new Metre(name, baseLinearUnit, conversionFactor, authority, deprecated);
                        } else {
                            unit = new LinearUnit(name, baseLinearUnit, conversionFactor, authority, deprecated);
                        }
                        break;
                    case 2:
                        final AngularUnit baseAngularUnit = (AngularUnit) UNIT_BY_ID.get(baseId);
                        if (id == 9102) {
                            unit = new Degree(name, baseAngularUnit, conversionFactor, authority, deprecated);
                        } else if (id == 9105) {
                            unit = new Grad(name, baseAngularUnit, conversionFactor, authority, deprecated);
                        } else if (id == 9110) {
                            unit = new DegreeSexagesimalDMS(name, baseAngularUnit, conversionFactor, authority, deprecated);
                        } else {
                            unit = new AngularUnit(name, baseAngularUnit, conversionFactor, authority, deprecated);
                        }
                        break;
                    case 3:
                        final TimeUnit baseTimeUnit = (TimeUnit) UNIT_BY_ID.get(baseId);
                        unit = new TimeUnit(name, baseTimeUnit, conversionFactor, authority, deprecated);
                        break;
                    default:
                        throw new IllegalArgumentException("Invalid unitId=" + id);
                }
                UNIT_BY_NAME.put(name, unit);
                UNIT_BY_ID.put(id, unit);
            }
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) Metre(com.revolsys.geometry.cs.unit.Metre) UnitOfMeasure(com.revolsys.geometry.cs.unit.UnitOfMeasure) Degree(com.revolsys.geometry.cs.unit.Degree) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) ScaleUnit(com.revolsys.geometry.cs.unit.ScaleUnit) AngularUnit(com.revolsys.geometry.cs.unit.AngularUnit) Grad(com.revolsys.geometry.cs.unit.Grad) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) DegreeSexagesimalDMS(com.revolsys.geometry.cs.unit.DegreeSexagesimalDMS) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) TimeUnit(com.revolsys.geometry.cs.unit.TimeUnit)

Example 13 with NoSuchResourceException

use of com.revolsys.spring.resource.NoSuchResourceException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordOperationParamValue.

private static void loadCoordOperationParamValue(final IntHashMap<CoordinateOperationMethod> methodById, final IntHashMap<Map<ParameterName, ParameterValue>> operationParameters, final IntHashMap<List<Byte>> paramReversal) {
    try (ChannelReader reader = newChannelReader("coordOperationParamValue")) {
        while (true) {
            final int operationId = reader.getInt();
            final CoordinateOperationMethod method = readCode(reader, methodById);
            final ParameterName parameterName = readCode(reader, PARAM_NAME_BY_ID);
            final double value = reader.getDouble();
            final String fileRef = reader.getStringUtf8ByteCount();
            final UnitOfMeasure unit = readCode(reader, UNIT_BY_ID);
            final ParameterValue parameterValue;
            if (Double.isFinite(value)) {
                if (Property.hasValue(fileRef)) {
                    throw new IllegalArgumentException("Cannot have a value and fileRef for coordOperationParamValue=" + operationId + " " + parameterName);
                } else {
                    parameterValue = new ParameterValueNumber(unit, value);
                }
            } else {
                if (Property.hasValue(fileRef)) {
                    parameterValue = new ParameterValueString(fileRef);
                } else {
                    parameterValue = null;
                }
            }
            Map<ParameterName, ParameterValue> parameterValues = operationParameters.get(operationId);
            if (parameterValues == null) {
                parameterValues = Maps.newLinkedHash();
                final List<ParameterName> parameterOrder = method.getParameterNames();
                for (final ParameterName orderParameterName : parameterOrder) {
                    parameterValues.put(orderParameterName, null);
                }
                operationParameters.put(operationId, parameterValues);
            }
            method.setParameter(parameterValues, parameterName, parameterValue);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            Logs.error(EpsgCoordinateSystems.class, "Error loading coordOperationParamValue", e);
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) ParameterValueNumber(com.revolsys.geometry.cs.ParameterValueNumber) UnitOfMeasure(com.revolsys.geometry.cs.unit.UnitOfMeasure) ParameterValue(com.revolsys.geometry.cs.ParameterValue) ParameterName(com.revolsys.geometry.cs.ParameterName) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) ChannelReader(com.revolsys.io.channels.ChannelReader) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) EOFException(java.io.EOFException)

Example 14 with NoSuchResourceException

use of com.revolsys.spring.resource.NoSuchResourceException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordinateReferenceSystem.

private static void loadCoordinateReferenceSystem(final IntHashMap<List<Axis>> axisMap) {
    try (ChannelReader reader = newChannelReader("coordinateReferenceSystem")) {
        while (true) {
            final int id = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final Area area = readCode(reader, AREA_BY_ID);
            final int type = reader.getByte();
            final CoordinateSystemType coordinateSystemType = readCode(reader, COORDINATE_SYSTEM_TYPE_BY_ID);
            final Datum datum = readCode(reader, DATUM_BY_ID);
            final CoordinateSystem sourceCoordinateSystem = readCode(reader, COORDINATE_SYSTEM_BY_ID);
            final CoordinateOperation operation = readCode(reader, OPERATION_BY_ID);
            final CoordinateSystem horizontalCoordinateSystem = readCode(reader, COORDINATE_SYSTEM_BY_ID);
            final VerticalCoordinateSystem verticalCoordinateSystem = (VerticalCoordinateSystem) readCode(reader, COORDINATE_SYSTEM_BY_ID);
            final boolean deprecated = readBoolean(reader);
            final List<Axis> axis;
            if (coordinateSystemType == null) {
                axis = null;
            } else {
                axis = axisMap.get(coordinateSystemType.getId());
            }
            CoordinateSystem coordinateSystem = null;
            if (type == 0) {
                // geocentric
                coordinateSystem = newCoordinateSystemGeocentric(id, name, datum, axis, area, deprecated);
            } else if (type == 1) {
                // geographic 3D
                coordinateSystem = new GeographicCoordinateSystem(id, name, (GeodeticDatum) datum, axis, area, sourceCoordinateSystem, operation, deprecated);
            } else if (type == 2) {
                // geographic 2D
                coordinateSystem = new GeographicCoordinateSystem(id, name, (GeodeticDatum) datum, axis, area, sourceCoordinateSystem, operation, deprecated);
            } else if (type == 3) {
                // projected
                coordinateSystem = newCoordinateSystemProjected(id, name, area, sourceCoordinateSystem, operation, axis, deprecated);
            } else if (type == 4) {
                // engineering
                coordinateSystem = new EngineeringCoordinateSystem(id, name, (EngineeringDatum) datum, axis, area, deprecated);
            } else if (type == 5) {
                // vertical
                coordinateSystem = new VerticalCoordinateSystem(id, name, (VerticalDatum) datum, axis, area, deprecated);
            } else if (type == 6) {
                coordinateSystem = new CompoundCoordinateSystem(id, name, horizontalCoordinateSystem, verticalCoordinateSystem, area, deprecated);
            } else {
                coordinateSystem = null;
            }
            addCoordinateSystem(coordinateSystem);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) Datum(com.revolsys.geometry.cs.datum.Datum) EngineeringDatum(com.revolsys.geometry.cs.datum.EngineeringDatum) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeocentricCoordinateSystem(com.revolsys.geometry.cs.GeocentricCoordinateSystem) CompoundCoordinateSystem(com.revolsys.geometry.cs.CompoundCoordinateSystem) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EngineeringCoordinateSystem(com.revolsys.geometry.cs.EngineeringCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) CoordinateSystemType(com.revolsys.geometry.cs.CoordinateSystemType) CompoundCoordinateSystem(com.revolsys.geometry.cs.CompoundCoordinateSystem) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) EngineeringCoordinateSystem(com.revolsys.geometry.cs.EngineeringCoordinateSystem) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) EngineeringDatum(com.revolsys.geometry.cs.datum.EngineeringDatum) Area(com.revolsys.geometry.cs.Area) ChannelReader(com.revolsys.io.channels.ChannelReader) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EOFException(java.io.EOFException) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Axis(com.revolsys.geometry.cs.Axis)

Aggregations

ChannelReader (com.revolsys.io.channels.ChannelReader)14 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)14 WrappedException (com.revolsys.util.WrappedException)14 EOFException (java.io.EOFException)14 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)12 ParameterName (com.revolsys.geometry.cs.ParameterName)5 Area (com.revolsys.geometry.cs.Area)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)3 UnitOfMeasure (com.revolsys.geometry.cs.unit.UnitOfMeasure)3 Axis (com.revolsys.geometry.cs.Axis)2 AxisName (com.revolsys.geometry.cs.AxisName)2 CoordinateSystemType (com.revolsys.geometry.cs.CoordinateSystemType)2 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)2 ParameterValue (com.revolsys.geometry.cs.ParameterValue)2 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)2 Datum (com.revolsys.geometry.cs.datum.Datum)2 EngineeringDatum (com.revolsys.geometry.cs.datum.EngineeringDatum)2 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)2 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)2