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

org.openlr.encoder.LocationReferencePointCreator Maven / Gradle / Ivy

The newest version!
package org.openlr.encoder;

import org.locationtech.jts.geom.Coordinate;
import org.openlr.locationreference.LocationReferenceFactory;
import org.openlr.locationreference.LocationReferencePoint;
import org.openlr.map.*;

import java.util.Comparator;

class LocationReferencePointCreator {
    private final LocationReferenceFactory locationReferenceFactory;
    private final MapOperations mapOperations;
    private final double bearingDistance;

    LocationReferencePointCreator(LocationReferenceFactory locationReferenceFactory, MapOperations mapOperations, double bearingDistance) {
        this.locationReferenceFactory = locationReferenceFactory;
        this.mapOperations = mapOperations;
        this.bearingDistance = bearingDistance;
    }

    > LocationReferencePoint create(PointAlongLine pointAlongLine, Path pathToNext) {
        Coordinate coordinate = pointAlongLine.getGeometry().getCoordinate();
        double bearing = mapOperations.calculateBearing(pointAlongLine, true, bearingDistance);

        L line = pointAlongLine.getLine();
        FunctionalRoadClass functionalRoadClass = line.getFunctionalRoadClass();
        FormOfWay formOfWay = line.getFormOfWay();

        double distance = pathToNext.getLength();
        FunctionalRoadClass lowestFunctionalRoadClass = pathToNext.getLines().stream()
                .map(Line::getFunctionalRoadClass)
                .max(Comparator.comparingInt(FunctionalRoadClass::ordinal))
                .get();

        return locationReferenceFactory.createLocationReferencePoint(
                coordinate,
                bearing,
                functionalRoadClass,
                formOfWay,
                distance,
                lowestFunctionalRoadClass);
    }

    > LocationReferencePoint create(PointAlongLine pointAlongLine) {
        Coordinate coordinate = pointAlongLine.getGeometry().getCoordinate();
        double bearing = mapOperations.calculateBearing(pointAlongLine, false, bearingDistance);

        L line = pointAlongLine.getLine();
        FunctionalRoadClass functionalRoadClass = line.getFunctionalRoadClass();
        FormOfWay formOfWay = line.getFormOfWay();

        return locationReferenceFactory.createLocationReferencePoint(
                coordinate,
                bearing,
                functionalRoadClass,
                formOfWay);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy