org.openlr.binary.writer.PointAlongLineLocationReferenceWriter Maven / Gradle / Ivy
The newest version!
package org.openlr.binary.writer;
import org.locationtech.jts.geom.Coordinate;
import org.openlr.binary.format.*;
import org.openlr.locationreference.LocationReferencePoint;
import org.openlr.locationreference.PathAttributes;
import org.openlr.locationreference.PointAlongLineLocationReference;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
class PointAlongLineLocationReferenceWriter {
private final StatusWriter statusWriter;
private final CoordinateWriter coordinateWriter;
private final AttributesWriter attributesWriter;
private final OffsetWriter offsetWriter;
PointAlongLineLocationReferenceWriter(StatusWriter statusWriter, CoordinateWriter coordinateWriter, AttributesWriter attributesWriter, OffsetWriter offsetWriter) {
this.statusWriter = statusWriter;
this.coordinateWriter = coordinateWriter;
this.attributesWriter = attributesWriter;
this.offsetWriter = offsetWriter;
}
void write(PointAlongLineLocationReference pointAlongLineLocationReference, ByteArrayOutputStream outputStream) throws IOException {
Status status = new Status(3, true, 0, true);
statusWriter.write(status, outputStream);
LocationReferencePoint firstLocationReferencePoint = pointAlongLineLocationReference.getFirstLocationReferencePoint();
Coordinate firstCoordinate = firstLocationReferencePoint.getCoordinate();
coordinateWriter.writeAbsoluteCoordinate(firstCoordinate, outputStream);
Attributes5 firstAttributes5 = new Attributes5(pointAlongLineLocationReference.getOrientation(), firstLocationReferencePoint.getFunctionalRoadClass(), firstLocationReferencePoint.getFormOfWay());
attributesWriter.writeAttributes5(firstAttributes5, outputStream);
PathAttributes firstPathAttributes = firstLocationReferencePoint.getPathAttributes().orElseThrow(() -> new IllegalArgumentException());
Attributes2 firstAttributes2 = new Attributes2(firstPathAttributes.getLowestFunctionalRoadClass(), firstLocationReferencePoint.getBearing());
attributesWriter.writeAttributes2(firstAttributes2, outputStream);
Attributes3 firstAttributes3 = new Attributes3(firstPathAttributes.getDistance());
attributesWriter.writeAttributes3(firstAttributes3, outputStream);
LocationReferencePoint lastLocationReferencePoint = pointAlongLineLocationReference.getLastLocationReferencePoint();
Coordinate lastCoordinate = lastLocationReferencePoint.getCoordinate();
coordinateWriter.writeRelativeCoordinate(lastCoordinate, firstCoordinate, outputStream);
Attributes6 lastAttributes6 = new Attributes6(pointAlongLineLocationReference.getSideOfRoad(), lastLocationReferencePoint.getFunctionalRoadClass(), lastLocationReferencePoint.getFormOfWay());
attributesWriter.writeAttributes6(lastAttributes6, outputStream);
boolean positiveOffset = pointAlongLineLocationReference.getRelativePositiveOffset() > 0;
Attributes4 lastAttributes4 = new Attributes4(positiveOffset, false, lastLocationReferencePoint.getBearing());
attributesWriter.writeAttributes4(lastAttributes4, outputStream);
if (positiveOffset) {
offsetWriter.write(pointAlongLineLocationReference.getRelativePositiveOffset(), outputStream);
}
}
}