Search in sources :

Example 11 with LinearUnit

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

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

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

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

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class WktCsParser method processVerticalCoordinateSystem.

private VerticalCoordinateSystem processVerticalCoordinateSystem(final List<Object> values) {
    final String name = (String) values.get(0);
    VerticalDatum verticalDatum = null;
    final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
    LinearUnit linearUnit = null;
    Authority authority = null;
    final List<Axis> axises = new ArrayList<>();
    for (int i = 1; i < values.size(); i++) {
        final Object value = values.get(i);
        if (value instanceof VerticalDatum) {
            verticalDatum = (VerticalDatum) value;
        } else if (value instanceof LinearUnit) {
            linearUnit = (LinearUnit) value;
        } else if (value instanceof Axis) {
            final Axis axis = (Axis) value;
            axises.add(axis);
        } else if (value instanceof Authority) {
            authority = (Authority) value;
        } else if (value instanceof Map) {
            final Map<String, List<Object>> map = (Map<String, List<Object>>) value;
            final String key = map.keySet().iterator().next();
            if (key.equals("PARAMETER")) {
                final List<Object> paramValues = map.get(key);
                final String paramName = (String) paramValues.get(0);
                final ParameterName parameterName = new SingleParameterName(paramName);
                final BigDecimal paramValue = (BigDecimal) paramValues.get(1);
                parameters.put(parameterName, new ParameterValueBigDecimal(paramValue));
            }
        }
    }
    return new VerticalCoordinateSystem(authority, name, verticalDatum, parameters, linearUnit, axises);
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ArrayList(java.util.ArrayList) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)17 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)9 ParameterName (com.revolsys.geometry.cs.ParameterName)8 Map (java.util.Map)8 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)7 ParameterValue (com.revolsys.geometry.cs.ParameterValue)7 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)7 LinkedHashMap (java.util.LinkedHashMap)7 Authority (com.revolsys.geometry.cs.Authority)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)4 ChannelReader (com.revolsys.io.channels.ChannelReader)4 WrappedException (com.revolsys.util.WrappedException)4 EOFException (java.io.EOFException)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)3 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)3 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)3 HashMap (java.util.HashMap)3 Maps (com.revolsys.collection.map.Maps)2