Search in sources :

Example 1 with VerticalCoordinateSystem

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

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

the class EsriCsWktWriter method write.

public static void write(final Writer out, final CoordinateSystem coordinateSystem, final int indentLevel) {
    try {
        if (coordinateSystem instanceof ProjectedCoordinateSystem) {
            final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
            write(out, projCs, indentLevel);
        } else if (coordinateSystem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSystem;
            write(out, geoCs, indentLevel);
        } else if (coordinateSystem instanceof VerticalCoordinateSystem) {
            final VerticalCoordinateSystem verticalCs = (VerticalCoordinateSystem) coordinateSystem;
            write(out, verticalCs, indentLevel);
        }
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) IOException(java.io.IOException)

Example 3 with VerticalCoordinateSystem

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

the class EsriCoordinateSystemsLoader method vertical.

private void vertical() {
    final Map<ByteArray, Map<Integer, VerticalCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriVerticalCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Vertical.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final VerticalCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final VerticalDatum datum = coordinateSystem.getDatum();
            if (datum != null) {
                final Map<ParameterName, ParameterValue> parameterValues = coordinateSystem.getParameterValues();
                final LinearUnit linearUnit = coordinateSystem.getLinearUnit();
                final String csName = coordinateSystem.getCoordinateSystemName();
                this.geographicIdByName.put(csName, id);
                final String datumName = datum.getName();
                final String linearUnitName = linearUnit.getName();
                final double conversionFactor = linearUnit.getConversionFactor();
                writer.putInt(id);
                writer.putStringUtf8ByteCount(csName);
                writer.putStringUtf8ByteCount(datumName);
                writeParameters(writer, parameterValues);
                writer.putStringUtf8ByteCount(linearUnitName);
                writer.putDouble(conversionFactor);
            }
        }
    }
    writeDigestFile(csBymd5, "Vertical");
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) RecordReader(com.revolsys.record.io.RecordReader) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ParameterName(com.revolsys.geometry.cs.ParameterName) LinkedHashMap(java.util.LinkedHashMap) ChannelWriter(com.revolsys.io.channels.ChannelWriter) Maps(com.revolsys.collection.map.Maps) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) Record(com.revolsys.record.Record) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with VerticalCoordinateSystem

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

Example 5 with VerticalCoordinateSystem

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

the class EpsgVerticalCoordinateSystems method addCoordinateSystem.

private void addCoordinateSystem(final int id) {
    final VerticalCoordinateSystem coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(id);
    this.coordinateSystems.add(coordinateSystem);
    final List<Object> codeList = Collections.singletonList(coordinateSystem);
    this.codes.put(coordinateSystem, codeList);
    final int coordinateSystemId = coordinateSystem.getCoordinateSystemId();
    this.coordinateSystemById.put(coordinateSystemId, coordinateSystem);
}
Also used : VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem)

Aggregations

VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)5 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)3 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ParameterName (com.revolsys.geometry.cs.ParameterName)2 ParameterValue (com.revolsys.geometry.cs.ParameterValue)2 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)2 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)2 ChannelReader (com.revolsys.io.channels.ChannelReader)2 WrappedException (com.revolsys.util.WrappedException)2 EOFException (java.io.EOFException)2 Maps (com.revolsys.collection.map.Maps)1 Area (com.revolsys.geometry.cs.Area)1 Authority (com.revolsys.geometry.cs.Authority)1 Axis (com.revolsys.geometry.cs.Axis)1 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)1 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)1 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)1 CoordinateSystemType (com.revolsys.geometry.cs.CoordinateSystemType)1 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)1 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)1