Class OsmNetworkReaderSettings

  • All Implemented Interfaces:
    ConverterReaderSettings

    public class OsmNetworkReaderSettings
    extends OsmReaderSettings
    All general settings (and sub-settings classes) for the OSM reader pertaining to parsing network infrastructure. contains additional settings for highway and railway (e.g., highway settings and railway settings members, respectively).
    Author:
    markr
    • Field Detail

      • osmRailwaySettings

        protected OsmRailwaySettings osmRailwaySettings
        all settings specific to osm railway tags
      • osmHighwaySettings

        protected OsmHighwaySettings osmHighwaySettings
        all settings specific to osm highway tags
      • osmWaterwaySettings

        protected OsmWaterwaySettings osmWaterwaySettings
        all settings specific to OSM waterway (ferry) tags
      • speedLimitConfiguration

        protected final OsmSpeedLimitDefaults speedLimitConfiguration
        the default speed limits used in case no explicit information is available on the osmway's tags
      • modeAccessConfiguration

        protected final OsmModeAccessDefaults modeAccessConfiguration
        the default mode access configuration used in case no explicit access information is available on the osmway's tags
      • laneConfiguration

        protected final OsmLaneDefaults laneConfiguration
        the default number of lanes used in case no explicit information is available on the osmway's tags
      • excludedOsmWays

        protected final Set<Long> excludedOsmWays
        allow users to provide OSM way ids for ways that we are not to parse, for example when we know the original coding or tagging is problematic
      • includedOutsideBoundingPolygonOsmWays

        protected final Set<Long> includedOutsideBoundingPolygonOsmWays
        Allow users to provide OSM way ids for ways that we are to keep even if they fall (partially) outside a bounding polygon, for example when we know the OSM way meanders in and outside the polygon and we want to have a connected network and proper lengths for this way
      • includedOutsideBoundingPolygonOsmNodes

        protected final Set<Long> includedOutsideBoundingPolygonOsmNodes
        Allow users to provide OSM node ids for nodes that we are not to keep even if they fall outside a bounding polygon
      • overwriteOsmWayModeAccess

        protected final Map<Long,​Set<String>> overwriteOsmWayModeAccess
        track overwritten mode access values for specific osm ways by osm id. Can be used in case the OSM file is incorrectly tagged which causes problems in the memory model. Here one can be manually overwrite the allowable modes for this particular way.
      • sourceCRS

        protected org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS
        the crs of the OSM source
      • removeDanglingSubNetworks

        protected boolean removeDanglingSubNetworks
        flag indicating if dangling subnetworks should be removed after parsing the network OSM network often have small roads that appear to be connected to larger roads, but in fact are not. All subnetworks that are not part of the largest subnetwork that is parsed will be removed by default.
      • discardSubNetworkBelowSize

        protected int discardSubNetworkBelowSize
        When dangling subnetworks are marked for removal, this threshold determines the minimum subnetwork size for it NOT to be removed. In other words, all subnetworks below this number will be removed
      • discardSubNetworkAboveSize

        protected int discardSubNetworkAboveSize
        When dangling subnetworks are marked for removal, this threshold determines the maximum subnetwork size for it NOT to be removed. In other words, all subnetworks above this number will be removed, including the largest one if it does not match the value
      • alwaysKeepLargestsubNetwork

        protected boolean alwaysKeepLargestsubNetwork
        indicate whether or not to keep the largest subnetwork when removeDanglingSubNetworks is set to true even when it does not adhere to the criteria of discardSubNetworkBelowSize and/or discardSubNetworkAbovesize
      • DEFAULT_SOURCE_CRS

        public static org.opengis.referencing.crs.CoordinateReferenceSystem DEFAULT_SOURCE_CRS
        the default crs is set to PlanitJtsUtils.DEFAULT_GEOGRAPHIC_CRS
      • DEFAULT_REMOVE_DANGLING_SUBNETWORK

        public static boolean DEFAULT_REMOVE_DANGLING_SUBNETWORK
        Default whether we are removing dangling subnetworks after parsing: true
      • DEFAULT_MINIMUM_SUBNETWORK_SIZE

        public static int DEFAULT_MINIMUM_SUBNETWORK_SIZE
        Default minimum size of subnetwork for it not to be removed when dangling subnetworks are removed, size indicates number of vertices: 20
      • DEFAULT_ALWAYS_KEEP_LARGEST_SUBNETWORK

        public static boolean DEFAULT_ALWAYS_KEEP_LARGEST_SUBNETWORK
        by default we always keep the largest subnetwork
    • Constructor Detail

      • OsmNetworkReaderSettings

        public OsmNetworkReaderSettings()
        Default constructor. Here no specific locale is provided, meaning that all defaults will use global settings. This is especially relevant for speed limits and mdoe access restrictions (unless manually adjusted by the user)
      • OsmNetworkReaderSettings

        public OsmNetworkReaderSettings​(String countryName)
        Constructor with country to base (i) default speed limits and (ii) mode access on, for various OSM highway types in case maximum speed limit information is missing
        Parameters:
        countryName - the full country name to use speed limit data for, see also the OsmSpeedLimitDefaultsByCountry class
      • OsmNetworkReaderSettings

        public OsmNetworkReaderSettings​(String inputSource,
                                        String countryName)
        Constructor with country to base (i) default speed limits and (ii) mode access on, for various OSM highway types in case maximum speed limit information is missing
        Parameters:
        inputSource - to use, expected local file location
        countryName - the full country name to use speed limit data for, see also the OsmSpeedLimitDefaultsByCountry class
      • OsmNetworkReaderSettings

        public OsmNetworkReaderSettings​(URL inputSource,
                                        String countryName)
        Constructor with country to base (i) default speed limits and (ii) mode access on, for various OSM highway types in case maximum speed limit information is missing
        Parameters:
        inputSource - to use
        countryName - the full country name to use speed limit data for, see also the OsmSpeedLimitDefaultsByCountry class
    • Method Detail

      • initialise

        protected void initialise()
        Conduct general initialisation for any instance of this class
      • initialiseDefaultMappingFromOsmModes2PlanitModes

        protected void initialiseDefaultMappingFromOsmModes2PlanitModes()
        Map both road and rail modes from OSM modes to PLANit modes
      • reset

        public void reset()
        be able to reset all settings if needed
      • logSettings

        public void logSettings()
        Log relevant settings
      • activateRailwayParser

        public OsmRailwaySettings activateRailwayParser​(boolean activate)
        activate the parsing of railways
        Parameters:
        activate - when true activate railway parsing, when false deactivate
        Returns:
        railway settings that are activated, null when deactivated
      • activateWaterwayParser

        public OsmWaterwaySettings activateWaterwayParser​(boolean activate)
        activate the parsing of waterways
        Parameters:
        activate - when true activate waterway parsing, when false deactivate
        Returns:
        waterway settings that are activated, null when deactivated
      • activateHighwayParser

        public OsmHighwaySettings activateHighwayParser​(boolean activate)
        activate the parsing of highways
        Parameters:
        activate - when true activate highway parsing, when false deactivate
        Returns:
        highway settings that are activated, null when deactivated
      • isRailwayParserActive

        public boolean isRailwayParserActive()
        Verify if railway parser is active
        Returns:
        true when active false otherwise
      • isHighwayParserActive

        public boolean isHighwayParserActive()
        Verify if railway parser is active
        Returns:
        true when active false otherwise
      • isWaterwayParserActive

        public boolean isWaterwayParserActive()
        Verify if waterway parser is active
        Returns:
        true when active false otherwise
      • getSourceCRS

        public final org.opengis.referencing.crs.CoordinateReferenceSystem getSourceCRS()
        Chosen crs, default is PlanitGeoUtils.DEFAULT_GEOGRAPHIC_CRS
        Returns:
        source CRS
      • setSourceCRS

        public void setSourceCRS​(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS)
        Override source CRS
        Parameters:
        sourceCRS - to use
      • excludeOsmWayTypesWithoutActivatedModes

        public void excludeOsmWayTypesWithoutActivatedModes()
        explicitly exclude all osmWay types that are included but have no more activated modes due to deactivation of their default assigned modes. Doing so avoids the reader to log warnings that supported way types cannot be injected in the network because they have no viable modes attached :TODO move somewhere else, not used from perspective of user
      • setRemoveDanglingSubnetworks

        public void setRemoveDanglingSubnetworks​(boolean removeDanglingSubnetworks)
        Indicate whether to remove dangling subnetworks or not
        Parameters:
        removeDanglingSubnetworks - yes or no
      • isRemoveDanglingSubnetworks

        public boolean isRemoveDanglingSubnetworks()
        Verify if dangling subnetworks are removed from the final network
        Returns:
        flag if dangling networks are removed
      • getLaneConfiguration

        public OsmLaneDefaults getLaneConfiguration()
        collect the current configuration setup for applying number of lanes in case the lanes tag is not available on the parsed osmway
        Returns:
        lane configuration containing all defaults for various osm highway types
      • getDefaultSpeedLimitByOsmWayType

        public Double getDefaultSpeedLimitByOsmWayType​(Map<String,​String> tags)
        Collect the default speed limit for a given highway/railway/waterway tag value, where we extract the key and value from the passed in tags, if available
        Parameters:
        tags - to extract way key value pair from (highway,railway keys currently supported)
        Returns:
        speedLimit in km/h (for highway types, the outside or inside urban area depending on the setting of the flag setSpeedLimitDefaultsBasedOnUrbanArea is collected)
      • getDefaultDirectionalLanesByWayType

        public Integer getDefaultDirectionalLanesByWayType​(String osmWayKey,
                                                           String osmWayValue)
        Collect the number of lanes/tracks for a given OSM way key/value for either direction (not total), e.g. highway=value, railway=value based on the defaults provided
        Parameters:
        osmWayKey - way key to collect default lanes for
        osmWayValue - way value to collect default lanes for
        Returns:
        number of default lanes
      • getMappedOsmModes

        public TreeSet<String> getMappedOsmModes​(PredefinedModeType planitModeType)
        Collect the mapped OSM modes based on the provided PLANit mode
        Parameters:
        planitModeType - to get mapped PLANit modes for
        Returns:
        mapped OSM modes, empty if no matches
      • getMappedOsmModes

        public Set<String> getMappedOsmModes​(Collection<PredefinedModeType> planitModeTypes)
        Collect the mapped OSM modes based on the provided PLANit mode types (if any)
        Parameters:
        planitModeTypes - to get mapped OSM modes for
        Returns:
        mapped OSM modes, empty if no matches
      • getMappedPlanitModeType

        public PredefinedModeType getMappedPlanitModeType​(String osmMode)
        convenience method that collects the currently mapped PLANit mode (road or rail) for the given OSM mode
        Parameters:
        osmMode - to collect mapped mode for (if any)
        Returns:
        mapped PLANit mode, if not available null is returned
      • getActivatedPlanitModeTypes

        public SortedSet<PredefinedModeType> getActivatedPlanitModeTypes​(Collection<String> osmModes)
        convenience method that collects the currently mapped PLANit modes (road or rail) for the given OSM modes
        Parameters:
        osmModes - to collect mapped mode for (if any)
        Returns:
        mapped PLANit modes, if not available empty set is returned
      • getActivatedPlanitModeTypes

        public SortedSet<PredefinedModeType> getActivatedPlanitModeTypes()
        Convenience method that collects all currently mapped PLANit mode types (road, rail, water)
        Returns:
        mapped PLANit mode types, if not available empty set is returned
      • hasMappedPlanitModeType

        public boolean hasMappedPlanitModeType​(String osmMode)
        Verify if the passed in osmMode is mapped (either to road or rail mode type), i.e., if it is actively included when reading the network
        Parameters:
        osmMode - to verify
        Returns:
        true if mapped, false otherwise
      • hasAnyMappedPlanitModeType

        public boolean hasAnyMappedPlanitModeType​(String... osmModes)
        Verify if any of the passed in osmModes are mapped, i.e., if it is actively included when reading the network
        Parameters:
        osmModes - to verify
        Returns:
        true if any is mapped, false otherwise
      • hasAnyMappedPlanitModeType

        public boolean hasAnyMappedPlanitModeType​(Collection<String> osmModes)
        Verify if any of the passed in osmModes are mapped, i.e., if it is actively included when reading the network
        Parameters:
        osmModes - to verify
        Returns:
        true if any is mapped, false otherwise
      • setDiscardDanglingNetworksBelow

        public void setDiscardDanglingNetworksBelow​(int discardBelow)
        the minimum size an identified dangling network must have for it to NOT be removed when danlging networks are removed
        Parameters:
        discardBelow - this number of vertices
      • setDiscardDanglingNetworksAbove

        public void setDiscardDanglingNetworksAbove​(int discardAbove)
        allows you to set a maximum size for dangling subnetwork. Practically only useful for debugging purposes
        Parameters:
        discardAbove - this number of vertices
      • getDiscardDanglingNetworkBelowSize

        public Integer getDiscardDanglingNetworkBelowSize()
        collect the size above which dangling networks are kept even if they are smaller than the largest connected network
        Returns:
        dangling network size
      • getDiscardDanglingNetworkAboveSize

        public Integer getDiscardDanglingNetworkAboveSize()
        collect the size below which networks are removed
        Returns:
        dangling network size
      • isAlwaysKeepLargestSubnetwork

        public boolean isAlwaysKeepLargestSubnetwork()
        Verify if the largest subnetwork is always kept when we are removing dangling subnetworks
        Returns:
        true when kept false otherwise
      • setAlwaysKeepLargestSubnetwork

        public void setAlwaysKeepLargestSubnetwork​(boolean alwaysKeepLargestSubnetwork)
        indicate to keep the largest subnetwork always even when removing dangling subnetworks and the largest one does not fit the set criteria
        Parameters:
        alwaysKeepLargestSubnetwork - when true we always keep it, otherwise not
      • deactivateAllOsmWayTypes

        public void deactivateAllOsmWayTypes()
        deactivate all types for both rail and highway
      • deactivateAllOsmWayTypesExcept

        public void deactivateAllOsmWayTypesExcept​(String... osmWaytypes)
        deactivate all osm way types except the ones indicated, meaning that if the ones passed in are not already active, they will be marked as activate afterwards. Note that this deactivates all types across both railways and highways. If you want to do this within highways only, use the same method under highway settings.
        Parameters:
        osmWaytypes - to mark as activated
      • deactivateAllOsmWayTypesExcept

        public void deactivateAllOsmWayTypesExcept​(List<String> osmWaytypes)
        deactivate all osm way types except the ones indicated, meaning that if the ones passed in are not already active, they will be marked as activate afterwards. Note that this deactivates all types across both railways and highways. If you want to do this within highways only, use the same method under highway settings.
        Parameters:
        osmWaytypes - to mark as activated
      • excludeOsmWayFromParsing

        public void excludeOsmWayFromParsing​(Number osmWayId)
        exclude specific OSM ways from being parsed based on their id
        Parameters:
        osmWayId - to mark as excluded (int or long)
      • excludeOsmWaysFromParsing

        public void excludeOsmWaysFromParsing​(Number... osmWayIds)
        exclude specific OSM ways from being parsed based on their id
        Parameters:
        osmWayIds - to mark as excluded (int or long)
      • excludeOsmWaysFromParsing

        public void excludeOsmWaysFromParsing​(List<Number> osmWayIds)
        exclude specific OSM ways from being parsed based on their id. It is expected that the way ids are either an integer or long
        Parameters:
        osmWayIds - to mark as excluded
      • isOsmWayExcluded

        public boolean isOsmWayExcluded​(Number osmWayId)
        Verify if provided way id is excluded or not
        Parameters:
        osmWayId - to verify (int or long)
        Returns:
        true if excluded, false otherwise
      • overwriteModeAccessByOsmWayId

        public void overwriteModeAccessByOsmWayId​(Number osmWayId,
                                                  String... allowedOsmModes)
        set the mode access for the given osm way id
        Parameters:
        osmWayId - this mode access will be applied on (int or long)
        allowedOsmModes - to set as the only modes allowed
      • overwriteModeAccessByOsmWayId

        public void overwriteModeAccessByOsmWayId​(Number osmWayId,
                                                  List<String> allowedOsmModes)
        set the mode access for the given osm way id
        Parameters:
        osmWayId - this mode access will be applied on (int or long)
        allowedOsmModes - to set as the only modes allowed
      • isModeAccessOverwrittenByOsmWayId

        public boolean isModeAccessOverwrittenByOsmWayId​(Number osmWayId)
        check if defaults should be overwritten
        Parameters:
        osmWayId - to check (int or long)
        Returns:
        true when alternative mode access is provided, false otherwise
      • getModeAccessOverwrittenByOsmWayId

        public final Set<String> getModeAccessOverwrittenByOsmWayId​(Number osmWayId)
        collect the overwrite type values that should be used
        Parameters:
        osmWayId - to collect overwrite values for (int or long)
        Returns:
        the osm modes with allowed access
      • logUnsupportedOsmWayTypes

        public void logUnsupportedOsmWayTypes()
        Log all de-activated OSM way types
      • getRailwaySettings

        public OsmRailwaySettings getRailwaySettings()
        provide railway specific settings
        Returns:
        railway settings
      • getHighwaySettings

        public OsmHighwaySettings getHighwaySettings()
        provide highway specific settings
        Returns:
        highway settings
      • getWaterwaySettings

        public OsmWaterwaySettings getWaterwaySettings()
        provide waterway specific settings
        Returns:
        waterway settings
      • setKeepOsmWaysOutsideBoundingPolygon

        public void setKeepOsmWaysOutsideBoundingPolygon​(Number... osmWays)
        When a bounding polygon is set, some ways might partially be in and/or outside this bounding box. For such OSM ways the complete geometry is available, but this is not known to the parser since it only considers nodes within the bounding box (from which the OSM ways are constructed). Hence without explicitly stating this OSM way needs to be preserved in full it is truncated for the portions outside the bounding box. This method allows the user to explicitly state the full geometry needs to be retained.
        Parameters:
        osmWays - to keep geometry even if it falls (partially) outside the bounding polygon (int or long)
      • setKeepOsmWaysOutsideBoundingPolygon

        public void setKeepOsmWaysOutsideBoundingPolygon​(List<Number> osmWays)
        When a bounding polygon is set, some ways might partially be in and/or outside this bounding box. For such OSM ways the complete geometry is available, but this is not known to the parser since it only considers nodes within the bounding box (from which the OSM ways are constructed). Hence without explicitly stating this OSM way needs to be preserved in full it is truncated for the portions outside the bounding box. This method allows the user to explicitly state the full geometry needs to be retained.
        Parameters:
        osmWays - to keep geometry even if it falls (partially) outside the bounding polygon (int or long)
      • hasKeepOsmWaysOutsideBoundingPolygon

        public boolean hasKeepOsmWaysOutsideBoundingPolygon()
        check if any OSM ways are marked for keeping outside bounding polygon
        Returns:
        true when present, false otherwise
      • isKeepOsmWayOutsideBoundingPolygon

        public boolean isKeepOsmWayOutsideBoundingPolygon​(Number osmWayId)
        check if OSM way is marked for keeping outside bounding polygon
        Parameters:
        osmWayId - to verify (int or long)
        Returns:
        true when present, false otherwise
      • setKeepOsmNodeOutsideBoundingPolygon

        public void setKeepOsmNodeOutsideBoundingPolygon​(Number osmNodeId)
        When a bounding polygon is set, some nodes might reside outside this bounding box but you want to make them available anyway for some reason. For such OSM nodes this method allows the user to explicitly include the OSM node even if it falls outside the bounding polygon
        Parameters:
        osmNodeId - to keep
      • getNumberOfKeepOsmNodesOutsideBoundingPolygon

        public int getNumberOfKeepOsmNodesOutsideBoundingPolygon()
        count number of marked OSM nodes to keep
        Returns:
        count
      • getNumberOfKeepOsmWaysOutsideBoundingPolygon

        public long getNumberOfKeepOsmWaysOutsideBoundingPolygon()
        count number of marked OSM ways to keep
        Returns:
        count
      • hasKeepOsmNodesOutsideBoundingPolygon

        public boolean hasKeepOsmNodesOutsideBoundingPolygon()
        check if any OSM nodes are marked for keeping outside bounding polygon
        Returns:
        true when present, false otherwise
      • isKeepOsmNodeOutsideBoundingPolygon

        public boolean isKeepOsmNodeOutsideBoundingPolygon​(Number osmNodeId)
        check if OSM node is marked for keeping outside bounding polygon
        Parameters:
        osmNodeId - to verify (int or long)
        Returns:
        true when present, false otherwise