All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openlr.binary.writer.CoordinateWriter Maven / Gradle / Ivy

The newest version!
package org.openlr.binary.writer;

import org.locationtech.jts.geom.Coordinate;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

class CoordinateWriter {
    private final IntegerWriter integerWriter;

    CoordinateWriter(IntegerWriter integerWriter) {
        this.integerWriter = integerWriter;
    }

    void writeAbsoluteCoordinate(Coordinate coordinate, ByteArrayOutputStream outputStream) throws IOException {
        writeAbsoluteOrdinate(coordinate.getX(), outputStream);
        writeAbsoluteOrdinate(coordinate.getY(), outputStream);
    }

    void writeRelativeCoordinate(Coordinate coordinate, Coordinate reference, ByteArrayOutputStream outputStream) throws IOException {
        writeRelativeOrdinate(coordinate.getX(), reference.getX(), outputStream);
        writeRelativeOrdinate(coordinate.getY(), reference.getY(), outputStream);
    }

    private void writeAbsoluteOrdinate(double ordinate, ByteArrayOutputStream outputStream) throws IOException {
        int value = (int) Math.round((Math.copySign(1.0, ordinate) * 0.5) + (ordinate * Math.pow(2, 24) / 360.0));
        integerWriter.write(value, 3, outputStream);
    }

    private void writeRelativeOrdinate(double ordinate, double reference, ByteArrayOutputStream outputStream) throws IOException {
        int value = (int) Math.round((ordinate - reference) * 100000);
        integerWriter.write(value, 2, outputStream);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy