Search in sources :

Example 6 with Ellipsoid

use of com.revolsys.geometry.cs.Ellipsoid in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadEllipsoid.

private static IntHashMap<Ellipsoid> loadEllipsoid() {
    final IntHashMap<Ellipsoid> ellipsoids = new IntHashMap<>();
    try (ChannelReader reader = newChannelReader("ellipsoid")) {
        while (true) {
            final int id = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final int unitId = reader.getInt();
            final LinearUnit unit = (LinearUnit) UNIT_BY_ID.get(unitId);
            final double semiMinorAxis = unit.toBase(reader.getDouble());
            final double semiMajorAxis = unit.toBase(reader.getDouble());
            final double inverseFlattening = unit.toBase(reader.getDouble());
            final int ellipsoidShape = reader.getByte();
            final boolean deprecated = readBoolean(reader);
            final EpsgAuthority authority = new EpsgAuthority(id);
            final Ellipsoid ellipsoid = new Ellipsoid(name, semiMajorAxis, semiMinorAxis, inverseFlattening, authority, deprecated);
            ellipsoids.put(id, ellipsoid);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
    return ellipsoids;
}
Also used : WrappedException(com.revolsys.util.WrappedException) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) IntHashMap(com.revolsys.collection.map.IntHashMap) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 7 with Ellipsoid

use of com.revolsys.geometry.cs.Ellipsoid in project com.revolsys.open by revolsys.

the class EpsgCsWktWriter method write.

public static void write(final PrintWriter out, final GeodeticDatum geodeticDatum) {
    if (geodeticDatum != null) {
        out.print(",DATUM[");
        write(out, geodeticDatum.getName());
        final Ellipsoid ellipsoid = geodeticDatum.getEllipsoid();
        if (ellipsoid != null) {
            write(out, ellipsoid);
        }
        final Authority authority = geodeticDatum.getAuthority();
        write(out, authority);
        out.write(']');
    }
}
Also used : Authority(com.revolsys.geometry.cs.Authority) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 8 with Ellipsoid

use of com.revolsys.geometry.cs.Ellipsoid 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

Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)8 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)3 ChannelReader (com.revolsys.io.channels.ChannelReader)3 Record (com.revolsys.record.Record)3 RecordReader (com.revolsys.record.io.RecordReader)3 WrappedException (com.revolsys.util.WrappedException)3 EOFException (java.io.EOFException)3 HashMap (java.util.HashMap)3 Authority (com.revolsys.geometry.cs.Authority)2 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)2 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)2 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)2 IntHashMap (com.revolsys.collection.map.IntHashMap)1 Maps (com.revolsys.collection.map.Maps)1 Area (com.revolsys.geometry.cs.Area)1 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)1 Datum (com.revolsys.geometry.cs.datum.Datum)1 EngineeringDatum (com.revolsys.geometry.cs.datum.EngineeringDatum)1