Search in sources :

Example 11 with ParameterName

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

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

the class EpsgCsWktWriter method write.

public static void write(final PrintWriter out, final ProjectedCoordinateSystem coordinateSystem) {
    if (coordinateSystem != null) {
        out.print("PROJCS[");
        write(out, coordinateSystem.getCoordinateSystemName());
        final GeographicCoordinateSystem geoCs = coordinateSystem.getGeographicCoordinateSystem();
        out.print(",");
        write(out, geoCs);
        final CoordinateOperationMethod coordinateOperationMethod = coordinateSystem.getCoordinateOperationMethod();
        write(out, coordinateOperationMethod);
        for (final Entry<ParameterName, Object> parameter : coordinateSystem.getParameters().entrySet()) {
            final ParameterName name = parameter.getKey();
            final Object value = parameter.getValue();
            write(out, name, value);
        }
        final LinearUnit unit = coordinateSystem.getLinearUnit();
        if (unit != null) {
            write(out, unit);
        }
        final Authority authority = coordinateSystem.getAuthority();
        write(out, authority);
        out.write(']');
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) Authority(com.revolsys.geometry.cs.Authority) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 13 with ParameterName

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

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

Example 15 with ParameterName

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

the class EsriCoordinateSystemsLoader method projected.

private void projected() {
    final Map<ByteArray, Map<Integer, ProjectedCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriProjectedCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Projected.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final ProjectedCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final String csName = coordinateSystem.getCoordinateSystemName();
            final GeographicCoordinateSystem geographicCoordinateSystem = coordinateSystem.getGeographicCoordinateSystem();
            final String geographicCoordinateSystemName = geographicCoordinateSystem.getCoordinateSystemName();
            final int geographicCoordinateSystemId = this.geographicIdByName.getOrDefault(geographicCoordinateSystemName, 0);
            if (geographicCoordinateSystemId == 0) {
                System.out.println(wkt);
            }
            final String projectionName = coordinateSystem.getCoordinateOperationMethod().getName();
            final Map<ParameterName, ParameterValue> parameterValues = coordinateSystem.getParameterValues();
            final LinearUnit linearUnit = coordinateSystem.getLinearUnit();
            final String unitName = linearUnit.getName();
            final double conversionFactor = linearUnit.getConversionFactor();
            writer.putInt(id);
            writer.putStringUtf8ByteCount(csName);
            writer.putInt(geographicCoordinateSystemId);
            writer.putStringUtf8ByteCount(projectionName);
            writeParameters(writer, parameterValues);
            writer.putStringUtf8ByteCount(unitName);
            writer.putDouble(conversionFactor);
        }
    }
    writeDigestFile(csBymd5, "Projected");
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) RecordReader(com.revolsys.record.io.RecordReader) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) LinkedHashMap(java.util.LinkedHashMap) ChannelWriter(com.revolsys.io.channels.ChannelWriter) Maps(com.revolsys.collection.map.Maps) Record(com.revolsys.record.Record) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ParameterName (com.revolsys.geometry.cs.ParameterName)15 ParameterValue (com.revolsys.geometry.cs.ParameterValue)11 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)8 ChannelReader (com.revolsys.io.channels.ChannelReader)7 WrappedException (com.revolsys.util.WrappedException)7 EOFException (java.io.EOFException)7 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)6 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)5 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)5 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)4 Authority (com.revolsys.geometry.cs.Authority)3 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 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)2 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)2 ChannelWriter (com.revolsys.io.channels.ChannelWriter)2 Record (com.revolsys.record.Record)2