use of com.revolsys.geometry.cs.unit.UnitOfMeasure in project com.revolsys.open by revolsys.
the class EpsgCoordinateSystems method loadCoordinateAxis.
private static IntHashMap<List<Axis>> loadCoordinateAxis() {
final IntHashMap<List<Axis>> axisesByCoordinateSystemId = new IntHashMap<>();
try (ChannelReader reader = newChannelReader("coordinateAxis")) {
while (true) {
final int coordinateSystemId = reader.getInt();
final AxisName axisName = readCode(reader, AXIS_NAMES);
final String orientation = reader.getStringUtf8ByteCount();
final Character abbreviation = (char) reader.getByte();
final UnitOfMeasure unitOfMeasure = readCode(reader, UNIT_BY_ID);
final Axis axis = new Axis(axisName, orientation, abbreviation.toString(), unitOfMeasure);
List<Axis> axises = axisesByCoordinateSystemId.get(coordinateSystemId);
if (axises == null) {
axises = new ArrayList<>();
axisesByCoordinateSystemId.put(coordinateSystemId, axises);
}
axises.add(axis);
}
} catch (final NoSuchResourceException e) {
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class)) {
} else {
throw e;
}
}
return axisesByCoordinateSystemId;
}
use of com.revolsys.geometry.cs.unit.UnitOfMeasure 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;
}
}
}
use of com.revolsys.geometry.cs.unit.UnitOfMeasure 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);
}
}
}
Aggregations