Search in sources :

Example 6 with ParameterValue

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

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

the class EpsgCoordinateSystems method newCoordinateSystemProjected.

private static ProjectedCoordinateSystem newCoordinateSystemProjected(final int id, final String name, final Area area, final CoordinateSystem sourceCoordinateSystem, final CoordinateOperation operation, final List<Axis> axis, final boolean deprecated) {
    final EpsgAuthority authority = new EpsgAuthority(id);
    final LinearUnit linearUnit = (LinearUnit) axis.get(0).getUnit();
    final CoordinateOperationMethod method = operation.getMethod();
    final Map<ParameterName, ParameterValue> parameterValues = operation.getParameterValues();
    if (sourceCoordinateSystem instanceof GeographicCoordinateSystem) {
        final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) sourceCoordinateSystem;
        return new ProjectedCoordinateSystem(id, name, geographicCoordinateSystem, area, method, parameterValues, linearUnit, axis, authority, deprecated);
    } else if (!Arrays.asList(5819, 5820, 5821).contains(id)) {
        Logs.error(EpsgCoordinateSystems.class, id + " " + name + " has a projected coordinate system");
        return null;
    } else {
        return null;
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 8 with ParameterValue

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

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

the class EsriCoordinateSystems method getProjectedCoordinateSystem.

public static ProjectedCoordinateSystem getProjectedCoordinateSystem(final int id) {
    ProjectedCoordinateSystem coordinateSystem = (ProjectedCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Projected.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final int geographicCoordinateSystemId = reader.getInt();
                final String projectionName = reader.getStringUtf8ByteCount();
                final Map<ParameterName, ParameterValue> parameters = readParameters(reader);
                final String unitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    LinearUnit linearUnit = LINEAR_UNITS_BY_NAME.get(unitName);
                    if (linearUnit == null) {
                        linearUnit = new LinearUnit(unitName, conversionFactor);
                        LINEAR_UNITS_BY_NAME.put(unitName, linearUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    final GeographicCoordinateSystem geographicCoordinateSystem = getGeographicCoordinateSystem(geographicCoordinateSystemId);
                    coordinateSystem = new ProjectedCoordinateSystem(coordinateSystemId, csName, geographicCoordinateSystem, projectionName, parameters, linearUnit, 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) 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) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) SingleParameterName(com.revolsys.geometry.cs.SingleParameterName) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 10 with ParameterValue

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

the class EsriCoordinateSystemsLoader method writeParameters.

private void writeParameters(final ChannelWriter writer, final Map<ParameterName, ParameterValue> parameterValues) {
    final int parameterCount = parameterValues.size();
    writer.putByte((byte) parameterCount);
    for (final Entry<ParameterName, ParameterValue> entry : parameterValues.entrySet()) {
        final ParameterName parameterName = entry.getKey();
        final ParameterValue parameterValue = entry.getValue();
        final String name = parameterName.getName();
        final Object value = parameterValue.getOriginalValue();
        writer.putStringUtf8ByteCount(name);
        writer.putStringUtf8ByteCount(DataTypes.toString(value));
    }
}
Also used : ParameterValue(com.revolsys.geometry.cs.ParameterValue) ParameterName(com.revolsys.geometry.cs.ParameterName)

Aggregations

ParameterName (com.revolsys.geometry.cs.ParameterName)11 ParameterValue (com.revolsys.geometry.cs.ParameterValue)11 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)7 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)4 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)4 ChannelReader (com.revolsys.io.channels.ChannelReader)4 WrappedException (com.revolsys.util.WrappedException)4 EOFException (java.io.EOFException)4 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)3 SingleParameterName (com.revolsys.geometry.cs.SingleParameterName)3 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)3 LinkedHashMap (java.util.LinkedHashMap)3 Maps (com.revolsys.collection.map.Maps)2 Authority (com.revolsys.geometry.cs.Authority)2 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)2 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)2 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)2 ChannelWriter (com.revolsys.io.channels.ChannelWriter)2 Record (com.revolsys.record.Record)2 RecordReader (com.revolsys.record.io.RecordReader)2