org.openlr.binary.reader.PointOfInterestWithAccessPointLocationReferenceReader Maven / Gradle / Ivy
The newest version!
package org.openlr.binary.reader;
import org.locationtech.jts.geom.Coordinate;
import org.openlr.binary.format.*;
import org.openlr.locationreference.LocationReferenceFactory;
import org.openlr.locationreference.LocationReferencePoint;
import org.openlr.locationreference.PointOfInterestWithAccessPointLocationReference;
import java.io.ByteArrayInputStream;
import java.io.IOException;
class PointOfInterestWithAccessPointLocationReferenceReader {
private final LocationReferenceFactory locationReferenceFactory;
private final StatusReader statusReader;
private final CoordinateReader coordinateReader;
private final AttributesReader attributesReader;
private final OffsetReader offsetReader;
PointOfInterestWithAccessPointLocationReferenceReader(LocationReferenceFactory locationReferenceFactory, StatusReader statusReader, CoordinateReader coordinateReader, AttributesReader attributesReader, OffsetReader offsetReader) {
this.locationReferenceFactory = locationReferenceFactory;
this.statusReader = statusReader;
this.coordinateReader = coordinateReader;
this.attributesReader = attributesReader;
this.offsetReader = offsetReader;
}
PointOfInterestWithAccessPointLocationReference read(ByteArrayInputStream inputStream) throws IOException {
Status status = statusReader.read(inputStream);
if (status.getVersion() != 3) {
throw new IllegalArgumentException();
}
if (!status.isAttributeFlag()) {
throw new IllegalArgumentException();
}
if (status.getAreaFlag() != 0) {
throw new IllegalArgumentException();
}
if (!status.isPointFlag()) {
throw new IllegalArgumentException();
}
Coordinate firstCoordinate = coordinateReader.readAbsoluteCoordinate(inputStream);
Attributes5 firstAttributes5 = attributesReader.readAttributes5(inputStream);
Attributes2 firstAttributes2 = attributesReader.readAttributes2(inputStream);
Attributes3 firstAttributes3 = attributesReader.readAttributes3(inputStream);
LocationReferencePoint firstLocationReferencePoint = locationReferenceFactory.createLocationReferencePoint(
firstCoordinate,
firstAttributes2.getBearing(),
firstAttributes5.getFunctionalRoadClass(),
firstAttributes5.getFormOfWay(),
firstAttributes3.getDistance(),
firstAttributes2.getFunctionalRoadClass());
Coordinate lastCoordinate = coordinateReader.readRelativeCoordinate(firstCoordinate, inputStream);
Attributes6 lastAttributes6 = attributesReader.readAttributes6(inputStream);
Attributes4 lastAttributes4 = attributesReader.readAttributes4(inputStream);
LocationReferencePoint lastLocationReferencePoint = locationReferenceFactory.createLocationReferencePoint(
lastCoordinate,
lastAttributes4.getBearing(),
lastAttributes6.getFunctionalRoadClass(),
lastAttributes6.getFormOfWay());
double relativePositiveOffset = lastAttributes4.isPositiveOffset() ? offsetReader.read(inputStream) : 0;
Coordinate coordinate = coordinateReader.readRelativeCoordinate(firstCoordinate, inputStream);
return locationReferenceFactory.createPointOfInterestWithAccessPointLocationReference(
firstLocationReferencePoint,
lastLocationReferencePoint,
relativePositiveOffset,
firstAttributes5.getOrientation(),
lastAttributes6.getSideOfRoad(),
coordinate);
}
}