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);
}
}
}
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(']');
}
}
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;
}
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));
}
}
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");
}
Aggregations