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

org.opentripplanner.openstreetmap.model.OSMWay Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.openstreetmap.model;

import gnu.trove.list.TLongList;
import gnu.trove.list.array.TLongArrayList;

public class OSMWay extends OSMWithTags {

    private TLongList nodes = new TLongArrayList();

    public void addNodeRef(OSMNodeRef nodeRef) {
        nodes.add(nodeRef.getRef());
    }

    public void addNodeRef(long nodeRef) {
        nodes.add(nodeRef);
    }

    public void addNodeRef(long nodeRef, int index) {
        nodes.insert(index, nodeRef);
    }

    public TLongList getNodeRefs() {
        return nodes;
    }

    public String toString() {
        return "osm way " + id;
    }

    /**
     * Returns true if bicycle dismounts are forced.
     * 
     * @return
     */
    public boolean isBicycleDismountForced() {
        String bicycle = getTag("bicycle");
        return isTag("cycleway", "dismount") || "dismount".equals(bicycle);
    }

    /**
     * Returns true if these are steps.
     * 
     * @return
     */
    public boolean isSteps() {
        return "steps".equals(getTag("highway"));
    }

    /**
     * Is this way a roundabout?
     * 
     * @return
     */
    public boolean isRoundabout() {
        return "roundabout".equals(getTag("junction"));
    }

    /**
     * Returns true if this is a one-way street for driving.
     * 
     * @return
     */
    public boolean isOneWayForwardDriving() {
        return isTagTrue("oneway");
    }

    /**
     * Returns true if this way is one-way in the opposite direction of its definition.
     * 
     * @return
     */
    public boolean isOneWayReverseDriving() {
        return isTag("oneway", "-1");
    }

    /**
     * Returns true if bikes can only go forward.
     * 
     * @return
     */
    public boolean isOneWayForwardBicycle() {
        String oneWayBicycle = getTag("oneway:bicycle");
        return isTrue(oneWayBicycle) || isTagFalse("bicycle:backwards");
    }

    /**
     * Returns true if bikes can only go in the reverse direction.
     * 
     * @return
     */
    public boolean isOneWayReverseBicycle() {
        return "-1".equals(getTag("oneway:bicycle"));
    }

    /**
     * Returns true if bikes must use sidepath in forward direction
     * 
     * @return 
     */
    public boolean isForwardDirectionSidepath() {
        return "use_sidepath".equals(getTag("bicycle:forward"));
    }

    /**
     * Returns true if bikes must use sidepath in reverse direction
     * 
     * @return 
     */
    public boolean isReverseDirectionSidepath() {
        return "use_sidepath".equals(getTag("bicycle:backward"));
    }

    /**
     * Some cycleways allow contraflow biking.
     * 
     * @return
     */
    public boolean isOpposableCycleway() {
        // any cycleway which is opposite* allows contraflow biking
        String cycleway = getTag("cycleway");
        String cyclewayLeft = getTag("cycleway:left");
        String cyclewayRight = getTag("cycleway:right");

        return (cycleway != null && cycleway.startsWith("opposite"))
                || (cyclewayLeft != null && cyclewayLeft.startsWith("opposite"))
                || (cyclewayRight != null && cyclewayRight.startsWith("opposite"));
    }

    @Override
    public String getOpenStreetMapLink() {
        return String.format("http://www.openstreetmap.org/way/%d", getId());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy