Class OsmSpeedLimitDefaultsByCountry


  • public class OsmSpeedLimitDefaultsByCountry
    extends Object
    Convenience class for quickly collecting the speed limits for various countries, where possible based on https://wiki.openstreetmap.org/wiki/OSM_tags_for_routing/Maxspeed (highway types)

    Note that a distinction is made between inside or outside a place, which refers to the road being inside or outside an urban area. this significantly impacts the speed limit.

    Unfortunately, the link cannot judge if it is inside or outside. So, we leave it to the user of this class to indicate which of the two values should be used (if there are two available).

    Note 1: railway speed limits are not known in OSM, so we use a global default for all types, which the user may override if required. Also no distinction is made between inside or outside an urban area.

    Author:
    markr
    • Field Detail

      • GLOBAL_SPEED_LIMIT_DEFAULTS

        protected static final OsmSpeedLimitDefaults GLOBAL_SPEED_LIMIT_DEFAULTS
        store the global railway defaults as fall back option
      • speedLimitDefaultsByCountryCode

        protected static Map<String,​OsmSpeedLimitDefaults> speedLimitDefaultsByCountryCode
        store all defaults per country by ISO2 code
    • Constructor Detail

      • OsmSpeedLimitDefaultsByCountry

        public OsmSpeedLimitDefaultsByCountry()
    • Method Detail

      • populateGlobalSpeedLimits

        protected static void populateGlobalSpeedLimits()
                                                 throws PlanItException
        populate the global defaults for highway/railway types
        Throws:
        PlanItException - thrown if error
      • populateCountrySpecificSpeedLimits

        protected static void populateCountrySpecificSpeedLimits()
                                                          throws PlanItException
        Populate the country specific defaults for highway/railway types for supported countries
        Throws:
        PlanItException - thrown if error
      • populateCountrySpecificRailwayDefaultSpeedLimits

        protected static void populateCountrySpecificRailwayDefaultSpeedLimits​(InputStreamReader inputReader,
                                                                               String fullCountryName)
        The speed limit defaults are parsed as CSV format and overwrite the global defaults for this country. If no explicit value is provided, we revert to the global defaults instead.
        Parameters:
        inputReader - to extract speed limit defaults from
        fullCountryName - these defaults relate to
      • populateCountrySpecificHighwayDefaultSpeedLimits

        protected static void populateCountrySpecificHighwayDefaultSpeedLimits​(InputStreamReader inputReader,
                                                                               String fullCountryName)
        The speed limit defaults are parsed as CSV format and overwrite the global defaults for this country. If no explicit value is provided, we revert to the global defaults instead.
        Parameters:
        inputReader - to extract speed limit defaults from
        fullCountryName - these defaults relate to
      • setGlobalHighwaySpeedLimitDefaults

        protected static void setGlobalHighwaySpeedLimitDefaults​(String type,
                                                                 double urbanSpeedLimit,
                                                                 double nonUrbanSpeedLimit)
        Set global defaults for highways
        Parameters:
        type - of highway
        urbanSpeedLimit - urban limit
        nonUrbanSpeedLimit - non-urban limit
      • setGlobalRailwaySpeedLimitDefaults

        protected static void setGlobalRailwaySpeedLimitDefaults​(String type,
                                                                 double speedLimit)
        Set global defaults for railways
        Parameters:
        type - of railway
        speedLimit - to use
      • populateGlobalDefaultHighwaySpeedLimits

        protected static void populateGlobalDefaultHighwaySpeedLimits()
        Populate the global defaults for highway types in case the country is not available, or in case the road type for that country is not available
      • populateDefaultRailwaySpeedLimits

        protected static void populateDefaultRailwaySpeedLimits​(OsmSpeedLimitDefaultsCategory toPopulate)
        Populate the defaults for railway types for given country (or global). Currently, we set the OsmSpeedLimitDefaults.GLOBAL_DEFAULT_RAILWAY_SPEEDLIMIT_KMH as the default for all modes. This can overwritten by the user if required
        Parameters:
        toPopulate - to populate
      • populateDefaultWaterwaySpeedLimits

        protected static void populateDefaultWaterwaySpeedLimits​(OsmSpeedLimitDefaultsCategory speedLimitsToPopulate)
        Populate the defaults for waterway types for given country (or global). Currently, we set the OsmSpeedLimitDefaults.GLOBAL_DEFAULT_WATERWAY_SPEEDLIMIT_KMH as the default for all modes. This can overwritten by the user if required
        Parameters:
        speedLimitsToPopulate - to populate
      • populateGlobalDefaultRailwaySpeedLimits

        protected static void populateGlobalDefaultRailwaySpeedLimits()
        populate the global defaults for railway types in case the country is not available, or in case the railway type for that country is not available. Currently, we set the OsmSpeedLimitDefaults.GLOBAL_DEFAULT_RAILWAY_SPEEDLIMIT_KMH as the default for all modes. This can overwritten by the user if required
      • populateGlobalDefaultWaterwaySpeedLimits

        protected static void populateGlobalDefaultWaterwaySpeedLimits()
        populate the global defaults for waterway types in case the country is not available, or in case the waterway type for that country is not available. Currently, we set the OsmSpeedLimitDefaults.GLOBAL_DEFAULT_WATERWAY_SPEEDLIMIT_KMH as the default for all modes. This can overwritten by the user if required
      • populateAustralianSpeedLimits

        protected static void populateAustralianSpeedLimits()
        Populate the defaults for Australia
      • getSpeedLimitByHighwayType

        protected static double getSpeedLimitByHighwayType​(OsmSpeedLimitDefaults countryDefaults,
                                                           boolean outside,
                                                           String type)
        Collect the speed limit based on the highway type, e.g. highway=type, inside an urban area. Speed limit is collected based on the chosen country. If either the country is not defined or the highway type is not available on the country's defaults, the global defaults will be used
        Parameters:
        countryDefaults - to use
        outside - indicates to use urban or non-urban defaults
        type - highway type value
        Returns:
        speed limit inside urban area for this type
      • setDefaultsByCountry

        protected static void setDefaultsByCountry​(OsmSpeedLimitDefaults countrySpeedLimits)
        Register speed limits for a specific country
        Parameters:
        countrySpeedLimits - speed limits by highway type
      • getDefaultsByCountryName

        protected static OsmSpeedLimitDefaults getDefaultsByCountryName​(String countryName)
        collect the (original) speed limit defaults (outside,inside urban areas) for a given country name
        Parameters:
        countryName - to collect for
        Returns:
        speed limits, null if not presently available
      • getDefaultsByCountryISO2

        protected static OsmSpeedLimitDefaults getDefaultsByCountryISO2​(String countryISO2)
        collect the (original) speed limit defaults (outside,inside urban areas) for a given country ISO2 code
        Parameters:
        countryISO2 - to collect for
        Returns:
        speed limits, null if not presently available
      • create

        public static OsmSpeedLimitDefaults create()
        Factory method to create global defaults only.
        Returns:
        created defaults
      • create

        public static OsmSpeedLimitDefaults create​(String countryName)
        Factory method to create speed limits for a particular country. It will utilise this country's defaults. If not available, or particular road type's are not available it will revert to the globally set defaults
        Parameters:
        countryName - to use
        Returns:
        created defaults
      • getGlobalUrbanHighwayDefaults

        public static OsmSpeedLimitDefaultsCategory getGlobalUrbanHighwayDefaults()
        collect the (original) highway-urban speed limit defaults
        Returns:
        global speed limit defaults
      • getGlobalNonUrbanHighwayDefaults

        public static OsmSpeedLimitDefaultsCategory getGlobalNonUrbanHighwayDefaults()
        collect the (original) highway-non-urban speed limit defaults
        Returns:
        global speed limit defaults
      • getGlobalRailwayDefaults

        public static OsmSpeedLimitDefaultsCategory getGlobalRailwayDefaults()
        collect the (original) railway speed limit defaults
        Returns:
        global speed limit defaults