Search in sources :

Example 6 with AngularUnit

use of com.revolsys.geometry.cs.unit.AngularUnit 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 7 with AngularUnit

use of com.revolsys.geometry.cs.unit.AngularUnit 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)

Aggregations

AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)7 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)5 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)5 ChannelReader (com.revolsys.io.channels.ChannelReader)3 WrappedException (com.revolsys.util.WrappedException)3 EOFException (java.io.EOFException)3 Authority (com.revolsys.geometry.cs.Authority)2 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)2 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)2 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)2 Maps (com.revolsys.collection.map.Maps)1 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)1 Degree (com.revolsys.geometry.cs.unit.Degree)1 DegreeSexagesimalDMS (com.revolsys.geometry.cs.unit.DegreeSexagesimalDMS)1 Grad (com.revolsys.geometry.cs.unit.Grad)1 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)1 Metre (com.revolsys.geometry.cs.unit.Metre)1 ScaleUnit (com.revolsys.geometry.cs.unit.ScaleUnit)1 TimeUnit (com.revolsys.geometry.cs.unit.TimeUnit)1