Class OsmModeUtils


  • public class OsmModeUtils
    extends Object
    Utilities in relation to parsing OSM modes when constructing a PLANit model from it. All utility methods are static in that they do not require any additional information regarding the configuration of the OSM reader, i.e., only generic utilities regarding OSM modes are included here.
    Author:
    markr
    • Constructor Detail

      • OsmModeUtils

        public OsmModeUtils()
    • Method Detail

      • getPrefixedOrPostfixedOsmRoadModesWithValueTag

        protected static Set<String> getPrefixedOrPostfixedOsmRoadModesWithValueTag​(boolean isprefix,
                                                                                    String alteration,
                                                                                    Map<String,​String> tags,
                                                                                    String... modeAccessValueTags)
        Collect all OSM modes with either preFix:<OSM mode name>= or postFix:<OSM mode name>= any of the modeAccessValueTags that are passed in. Note that the actual value of the tags will be stripped from special characters to make it more universal to match the pre-specified mode access value tags that we expect to be passed in.
        Parameters:
        isprefix - when true prefix applied, when false, postfix
        alteration - , the post or prefix alteration of the mode key
        tags - to find explicitly included/excluded (PLANit) modes from
        modeAccessValueTags - used to filter the modes by
        Returns:
        modes found with specified value tag
      • getOsmModesWithValueTag

        protected static Set<String> getOsmModesWithValueTag​(Map<String,​String> tags,
                                                             Collection<String> supportedOsmModes,
                                                             String... modeAccessValueTags)
        Collect all OSM modes with key=<OSM mode name> value=the access value tags that are passed in and available from the supported modes (also passed in). Note that the actual value of the tags will be stripped from special characters to make it more universal to match the pre-specified mode access value tags that we expect to be passed in
        Parameters:
        tags - to find explicitly included/excluded (planit) modes from
        supportedOsmModes - supportedOsmModes to filer on
        modeAccessValueTags - used to filter the modes by (yes/no)
        Returns:
        modes found with specified value tag
      • collectEligibleOsmModesOnPtOsmEntity

        protected static Set<String> collectEligibleOsmModesOnPtOsmEntity​(Map<String,​String> tags,
                                                                          Set<String> selectableOsmModes,
                                                                          String defaultOsmMode)
        Collect the OSM modes that are deemed eligible for this entity (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. ferry=yes, or when none are marked explicitly we assume the the default (if provided). When modes are marked as non-accessible, they are removed from the explicitly included modes. We use a selected set of supported modes passed in to select from
        Parameters:
        tags - related to the node
        selectableOsmModes - to choose from
        defaultOsmMode - used when no explicit modes can be found (can be null)
        Returns:
        list of eligible osm modes, can be empty if no modes are found and default is null
      • getOsmRoadModesWithValueTag

        public static Set<String> getOsmRoadModesWithValueTag​(Map<String,​String> tags,
                                                              String... modeAccessValueTags)
        collect all OSM road going modes with key=<OSM mode name> value=the access value tags that are passed in. Note that the actual value of the tags will be stripped from special characters to make it more universal to match the pre-specified mode access value tags that we expect to be passed in
        Parameters:
        tags - to find explicitly included/excluded (planit) modes from
        modeAccessValueTags - used to filter the modes by (yes/no)
        Returns:
        modes found with specified value tag
      • getOsmRailModesWithValueTag

        public static Set<String> getOsmRailModesWithValueTag​(Map<String,​String> tags,
                                                              String... modeAccessValueTags)
        collect all OSM rail modes with key=<OSM mode name> value=the access value tags that are passed in. Note that the actual value of the tags will be stripped from special characters to make it more universal to match the pre-specified mode access value tags that we expect to be passed in
        Parameters:
        tags - to find explicitly included/excluded (planit) modes from
        modeAccessValueTags - used to filter the modes by (yes/no)
        Returns:
        modes found with specified value tag
      • getPostfixedOsmRoadModesWithValueTag

        public static Set<String> getPostfixedOsmRoadModesWithValueTag​(String postFix,
                                                                       Map<String,​String> tags,
                                                                       String... modeAccessValueTags)
        collect all OSM modes with key=<OSM mode name>:postFix= any of the modeAccessValueTags that are passed in. Note that the actual value of the tags will be stripped from special characters to make it more universal to match the pre-specified mode access value tags that we expect to be passed in
        Parameters:
        postFix - to utilise
        tags - to find explicitly included/excluded (planit) modes from
        modeAccessValueTags - used to filter the modes by (yes/no)
        Returns:
        modes found with specified value tag
      • getPrefixedOsmRoadModesWithValueTag

        public static Collection<String> getPrefixedOsmRoadModesWithValueTag​(String prefix,
                                                                             Map<String,​String> tags,
                                                                             String... modeAccessValueTags)
        collect all OSM modes with key=preFix:<OSM mode name>= any of the modeAccessValueTags that are passed in. Note that the actual value of the tags will be stripped from special characters to make it more universal to match the pre-specified mode access value tags that we expect to be passed in
        Parameters:
        prefix - considered
        tags - to find explicitly included/excluded (planit) modes from
        modeAccessValueTags - used to filter the modes by
        Returns:
        modes found with specified value tag
      • collectEligibleOsmWaterModesOnPtOsmEntity

        public static Set<String> collectEligibleOsmWaterModesOnPtOsmEntity​(Map<String,​String> tags,
                                                                            String defaultOsmMode)
        Collect the water modes that are deemed eligible for this entity (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. ferry=yes, or when none are marked explicitly we assume the the default (if provided). When modes are marked as non-accessible, they are removed from the explicitly included modes.
        Parameters:
        tags - related to the node
        defaultOsmMode - used when no explicit modes can be found (can be null)
        Returns:
        list of eligible osm modes, can be empty if no modes are found and default is null
      • collectEligibleOsmRailModesOnPtOsmEntity

        public static Set<String> collectEligibleOsmRailModesOnPtOsmEntity​(Map<String,​String> tags,
                                                                           String defaultOsmMode)
        Collect the rail modes that are deemed eligible for this node (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. subway=yes, or when none are marked explicitly we assume the default (if provided)
        Parameters:
        tags - related to the node
        defaultOsmMode - used when no explicit modes can be found (can be null)
        Returns:
        list of eligible osm modes, can be empty if no modes are found and default is null
      • collectEligibleOsmRoadModesOnPtOsmEntity

        public static Set<String> collectEligibleOsmRoadModesOnPtOsmEntity​(long osmEntityId,
                                                                           Map<String,​String> tags,
                                                                           String defaultOsmMode)
        Collect the rail modes that are deemed eligible for this entity (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. bus=yes, or when none are marked explicitly we assume the the default (if provided). When modes are marked as non-accessible, they are removed from the explicitly included modes.
        Parameters:
        osmEntityId - to use
        tags - related to the node
        defaultOsmMode - used when no explicit modes can be found (can be null)
        Returns:
        list of eligible osm modes, can be empty if no modes are found and default is null
      • collectEligibleOsmModesOnPtOsmEntity

        public static Collection<String> collectEligibleOsmModesOnPtOsmEntity​(long osmEntityId,
                                                                              Map<String,​String> tags)
        Collect the modes that are deemed eligible for this node (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. subway=yes.
        Parameters:
        osmEntityId - to use
        tags - related to the node
        Returns:
        list of eligible osm modes, can be empty if no modes are found
      • collectEligibleOsmModesOnPtOsmEntity

        public static Collection<String> collectEligibleOsmModesOnPtOsmEntity​(long osmPtEntityId,
                                                                              Map<String,​String> tags,
                                                                              String defaultOsmMode)
        Collect the modes that are deemed eligible for this node (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. subway=yes, or when none are marked explicitly we assume the default (if provided).
        Parameters:
        osmPtEntityId - to use
        tags - related to the node
        defaultOsmMode - used when no explicit modes can be found (can be null)
        Returns:
        list of eligible osm modes, can be empty if no modes are found and default is null
      • collectEligibleOsmPublicTransportModesOnPtOsmEntity

        public static TreeSet<String> collectEligibleOsmPublicTransportModesOnPtOsmEntity​(long osmPtEntityId,
                                                                                          Map<String,​String> tags,
                                                                                          String defaultOsmMode)
        Collect the public transport modes that are deemed eligible for this node (platform, station, halt, etc.). A mode is eligible when marked as yes, e.g. subway=yes, or when none are marked explicitly we assume the default (if provided).
        Parameters:
        osmPtEntityId - to use
        tags - related to the node
        defaultOsmMode - used when no explicit modes can be found (can be null)
        Returns:
        list of eligible osm public transport modes, can be empty if no modes are found and default is null
      • identifyPtv1DefaultMode

        public static String identifyPtv1DefaultMode​(long osmId,
                                                     Map<String,​String> tags,
                                                     boolean suppressWarning)
        If the tags contain Ptv1 related tagging, we use it to identify the most likely mode that is expected to be supported,
        • highway=bus_stop gives bus
        • highway=station gives bus
        • highway=platform gives bus
        • highway=platform_edge gives bus
        • railway=station gives train
        • railway=platform gives train
        • railway=platform_edge gives train
        • railway=halt gives train
        • railway=stop gives train
        • railway=tram_stop gives tram
        • amenity=ferry_terminal gives ferry
        Parameters:
        osmId - this relates to
        tags - to extract information from
        suppressWarning - when true suppress any warnings, do not otherwise
        Returns:
        default mode found, null if nothing is found
      • identifyPtv1DefaultMode

        public static String identifyPtv1DefaultMode​(long osmId,
                                                     Map<String,​String> tags)
        Identical to identifyPtv1DefaultMode(long, Map, boolean) without suppressing warnings
        Parameters:
        osmId - this relates to
        tags - to extract information from
        Returns:
        default mode found, null if nothing is found
      • identifyPtv1DefaultMode

        public static String identifyPtv1DefaultMode​(long osmId,
                                                     Map<String,​String> tags,
                                                     String backupDefaultMode,
                                                     boolean suppressWarning)
        If the tags contain Ptv1 related tagging, we use it to identify the most likely mode that is expected to be supported. We are slightly more tolerant to ferries due to their high likelihood of erroneous or incomplete tagging. In those cases we verify a few more tags than one would normally do
        • highway=bus_stop gives bus
        • highway=station gives bus
        • highway=platform gives bus
        • highway=platform_edge gives bus
        • railway=station gives train
        • railway=platform gives train
        • railway=platform_edge gives train
        • railway=halt gives train
        • railway=stop gives train
        • railway=tram_stop gives tram
        • railway=tram_stop gives tram
        • amenity=ferry_terminal gives ferry
        • ferry=yes gives ferry
        Parameters:
        osmId - this relates to
        tags - to extract information from
        backupDefaultMode - if none can be found, this mode is used, may be null
        suppressWarning - when true do not log warning if no match could be found,
        Returns:
        default mode, null if no match could be made
      • identifyPtv1DefaultMode

        public static String identifyPtv1DefaultMode​(long osmId,
                                                     Map<String,​String> tags,
                                                     String backupDefaultMode)
        Identical to identifyPtv1DefaultMode(long, Map, String, boolean) without suppressing warnings
        Parameters:
        osmId - to use
        tags - to extract information from
        backupDefaultMode - if none can be found, this mode is used, may be null
        Returns:
        default mode, null if no match could be made
      • extractCompatibleOsmModes

        public static Collection<String> extractCompatibleOsmModes​(Collection<String> osmModesToCheck,
                                                                   Collection<String> referenceOsmModes,
                                                                   boolean allowPseudoMatches)
        Find out if modes to check are compatible with the reference OSM modes. Mode compatible means at least one overlapping OSM mode. When one allows for pseudo compatibility we relax the restrictions such that any rail/road/water mode is considered a match with any other rail/road/water mode. This can be useful when you do not want to make super strict matches but still want to filter out definite non-matches.
        Parameters:
        osmModesToCheck - the modes to check
        referenceOsmModes - modes to check against
        allowPseudoMatches - when true, we consider all road modes compatible, i.e., bus is compatible with car, train is compatible with tram, etc., when false only exact matches are accepted
        Returns:
        compatible modes found
      • extractPublicTransportModesFrom

        public static TreeSet<String> extractPublicTransportModesFrom​(Collection<String> eligibleOsmModes)
        Collect all pt modes available from the passed in modes across all major mode types (road, rail, water)
        Parameters:
        eligibleOsmModes - to extract from
        Returns:
        found public transport based modes, can be null
      • hasEligibleOsmMode

        public static boolean hasEligibleOsmMode​(Pair<? extends SortedSet<String>,​SortedSet<PredefinedModeType>> modeResult)
        Check to see if pair with eligible modes contains any eligible OSM mode
        Parameters:
        modeResult - of collectEligibleModes on zoning base handler
        Returns:
        true when has at least one mapped PLANit mode present
      • hasMappedPlanitMode

        public static boolean hasMappedPlanitMode​(Pair<? extends SortedSet<String>,​SortedSet<PredefinedModeType>> modeResult)
        Check to see if pair with eligible modes contains any mapped PLANit mode
        Parameters:
        modeResult - of collectEligibleModes on zoning base handler
        Returns:
        true when has at least one mapped PLANit mode present