org.openlr.binary.reader.CoordinateReader Maven / Gradle / Ivy
The newest version!
package org.openlr.binary.reader;
import org.locationtech.jts.geom.Coordinate;
import java.io.ByteArrayInputStream;
import java.io.IOException;
class CoordinateReader {
private final IntegerReader integerReader;
CoordinateReader(IntegerReader integerReader) {
this.integerReader = integerReader;
}
Coordinate readAbsoluteCoordinate(ByteArrayInputStream inputStream) throws IOException {
double x = readAbsoluteOrdinate(inputStream);
double y = readAbsoluteOrdinate(inputStream);
return new Coordinate(x, y);
}
Coordinate readRelativeCoordinate(Coordinate reference, ByteArrayInputStream inputStream) throws IOException {
double x = readRelativeOrdinate(reference.getX(), inputStream);
double y = readRelativeOrdinate(reference.getY(), inputStream);
return new Coordinate(x, y);
}
private double readAbsoluteOrdinate(ByteArrayInputStream inputStream) throws IOException {
int value = integerReader.readSignedInteger(3, inputStream);
return ((double) value - (Math.copySign(1.0, value) * 0.5)) * 360.0 / Math.pow(2, 24);
}
private double readRelativeOrdinate(double reference, ByteArrayInputStream inputStream) throws IOException {
int value = integerReader.readSignedInteger(2, inputStream);
double doubleValue = (double) value / 100000;
return reference + doubleValue;
}
}