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

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

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

import org.locationtech.jts.geom.Coordinate;
import org.openlr.binary.format.Status;
import org.openlr.locationreference.PolygonLocationReference;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;

class PolygonLocationReferenceWriter {
    private final StatusWriter statusWriter;
    private final CoordinateWriter coordinateWriter;

    PolygonLocationReferenceWriter(StatusWriter statusWriter, CoordinateWriter coordinateWriter) {
        this.statusWriter = statusWriter;
        this.coordinateWriter = coordinateWriter;
    }

    void write(PolygonLocationReference polygonLocationReference, ByteArrayOutputStream outputStream) throws IOException {
        Status status = new Status(3, false, 1, false);
        statusWriter.write(status, outputStream);

        List coordinates = polygonLocationReference.getCoordinates();
        Coordinate firstCoordinate = coordinates.get(0);
        coordinateWriter.writeAbsoluteCoordinate(firstCoordinate, outputStream);

        Coordinate reference = firstCoordinate;

        for (int i = 1; i < coordinates.size(); i++) {
            Coordinate coordinate = coordinates.get(i);
            coordinateWriter.writeRelativeCoordinate(coordinate, reference, outputStream);
            reference = coordinate;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy