Class ZoningConverterUtils


  • public class ZoningConverterUtils
    extends Object
    Utilities regarding Zoning conversions that might be useful for implementations supporting the mapping of non-PLANit geometry based entities to PLANit transfer zones and connectoids
    Author:
    markr
    • Constructor Detail

      • ZoningConverterUtils

        public ZoningConverterUtils()
    • Method Detail

      • isWaitingAreaLeftOfAccessLineSegment

        public static boolean isWaitingAreaLeftOfAccessLineSegment​(org.locationtech.jts.geom.Geometry waitingAreaGeometry,
                                                                   MacroscopicLinkSegment accessLinkSegment,
                                                                   org.locationtech.jts.geom.LineSegment accessLinkSegmentLineSegment,
                                                                   PlanitJtsCrsUtils geoUtils)
        Verify if the provided line segment (somewhere along the geometry of the access link segment) resides on the correct side of the waiting area location, assuming this matters
        Parameters:
        waitingAreaGeometry - for which to check location
        accessLinkSegment - the location resides on
        accessLinkSegmentLineSegment - to use
        geoUtils - to use
        Returns:
        true when left of, false otherwise
      • isAvoidCrossTrafficForAccessModeOrAccessNodeWaitingAreaOverwritten

        public static <T> boolean isAvoidCrossTrafficForAccessModeOrAccessNodeWaitingAreaOverwritten​(Mode accessMode,
                                                                                                     String waitingAreaSourceId,
                                                                                                     T accessEntity,
                                                                                                     Function<T,​String> getOverwrittenWaitingAreaSourceId)
        Verify if the waiting area for an access mode's access link(segment) must be on the logical relative location (left hand side for left hand drive) or not. In case the mapping is overwritten it is assumed the driving direction does not matter as it is user defined to be explicitly mapped.
        Type Parameters:
        T - type of access entity
        Parameters:
        accessMode - to check
        waitingAreaSourceId - required to check if user overwrite is present for this waiting area, may be null to
        accessEntity - the access entity that may be mapped to the waiting area under investigation, may be null if not available
        getOverwrittenWaitingAreaSourceId - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwrritten
        Returns:
        true when restricted for driving direction, false otherwise
      • isAvoidCrossTrafficForAccessMode

        public static boolean isAvoidCrossTrafficForAccessMode​(Mode accessMode)
        Verify if the waiting area for an access mode's access link(segment) must be on the logical relative location (left hand side for left hand drive) or not.
        Parameters:
        accessMode - to check
        Returns:
        true when restricted for driving direction, false otherwise
      • excludeLinksOnWrongSideOf

        public static Collection<MacroscopicLink> excludeLinksOnWrongSideOf​(org.locationtech.jts.geom.Geometry location,
                                                                            Collection<MacroscopicLink> links,
                                                                            boolean isLeftHandDrive,
                                                                            Collection<? extends Mode> accessModes,
                                                                            PlanitJtsCrsUtils geoUtils)
        create a subset of links from the passed in ones, removing all links for which we can be certain that geometry is located on the wrong side of the road infrastructure geometry. Note that rails is not excluded in this exercise, i.e., it is assumed rail lines ar bi-rectional. Right or wrong side is verified by checking if the link is one-way. If so, we can be sure (based on the driving direction of the country) if the geometry is located to the closest by (logical) driving direction given the placement of the geometry, i.e., on the left hand side for left hand drive countries, on the right hand side for right hand driving countries
        Parameters:
        location - representing the location of concern expected to have access to the link
        links - to remove in-eligible ones from
        isLeftHandDrive - flag
        accessModes - to consider
        geoUtils - to use
        Returns:
        remaining links that are deemed eligible
      • identifyLinkSegmentsOnWrongSideOf

        public static Collection<LinkSegment> identifyLinkSegmentsOnWrongSideOf​(org.locationtech.jts.geom.Geometry location,
                                                                                Collection<LinkSegment> accessLinkSegments,
                                                                                boolean leftHandDrive,
                                                                                PlanitJtsCrsUtils geoUtils)
        Find the access link segments ineligible given the intended location and the access mode. When transfer zone location differs from the connectoid location determine on which side of the infrastructure it exists and based on the country's driving direction and access mode determine the access link segments
        Parameters:
        accessLinkSegments - to filter
        location - to identify incorrectly located link segments for
        leftHandDrive - is infrastructure left hand drive or not
        geoUtils - to use for determining geographic eligibility
        Returns:
        ineligible link segments to be access link segments for connectoid at this location
      • excludeClosestLinksIncrementallyOnWrongSideOf

        public static Pair<MacroscopicLink,​Boolean> excludeClosestLinksIncrementallyOnWrongSideOf​(org.locationtech.jts.geom.Geometry location,
                                                                                                        Collection<MacroscopicLink> links,
                                                                                                        boolean isLeftHandDrive,
                                                                                                        Collection<? extends Mode> accessModes,
                                                                                                        PlanitJtsCrsUtils geoUtils)
        Exclude the closest link if it is situated on the wrong side of the road, then if links are remaining keep going with removing the then closest if it is also on the wrong side of the road etc.
        Parameters:
        location - to verify against, typically a transfer zone location
        links - to update
        isLeftHandDrive - network driving direction
        accessModes - for the location
        geoUtils - to use
        Returns:
        pair with remaining closest link found and boolean indicating if any closest links were removed before finding a compatible closest links (true when one or more closest links are removed, false otherwise)
      • findAccessEntryLinkSegmentsForWaitingArea

        public static Collection<LinkSegment> findAccessEntryLinkSegmentsForWaitingArea​(String waitingAreaSourceId,
                                                                                        org.locationtech.jts.geom.Geometry waitingAreaGeometry,
                                                                                        MacroscopicLink accessLink,
                                                                                        String accessLinkSourceId,
                                                                                        Node node,
                                                                                        Mode accessMode,
                                                                                        String countryName,
                                                                                        boolean mustAvoidCrossingTraffic,
                                                                                        Function<String,​String> getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId,
                                                                                        Function<Node,​String> getOverwrittenWaitingAreaSourceId,
                                                                                        PlanitJtsCrsUtils geoUtils)
        Find the link segments that are accessible for the given access link, node, mode combination taking into account the relative location of the transfer zone if needed and mode compatibility.
        Parameters:
        waitingAreaSourceId - these link segments pertain to
        waitingAreaGeometry - these link segments pertain to
        accessLink - that is nominated
        accessLinkSourceId - source id of the access link used, this will be matched gainst the overwritten access link source id (if provided)
        node - extreme node of the link
        accessMode - eligible access mode
        countryName - we are considering from which we will extract whether it is a left or right hand drive country
        mustAvoidCrossingTraffic - flag indicating if cross traffic should be avoided for the access link segments that are deemed eligible
        getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId - mapping from waiting area source id to nominated access link source id, which if a match to provided access link source id makes sure that even if there exists crossing traffic this does not render its access link segment(s) invalid, may be null
        getOverwrittenWaitingAreaSourceId - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwrritten
        geoUtils - to use
        Returns:
        found link segments that are deemed valid given the constraints
      • isPotentialAccessEntryLinkSegmentForWaitingArea

        public static boolean isPotentialAccessEntryLinkSegmentForWaitingArea​(String waitingAreaSourceId,
                                                                              org.locationtech.jts.geom.Geometry waitingAreaGeometry,
                                                                              MacroscopicLinkSegment accessLinkSegment,
                                                                              String accessLinkSourceId,
                                                                              Node accessNode,
                                                                              Mode accessMode,
                                                                              Function<Node,​String> getOverwrittenWaitingAreaSourceId,
                                                                              Function<String,​String> getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId,
                                                                              String countryName,
                                                                              PlanitJtsCrsUtils geoUtils)
        Verify if given link segment is potentially viable as access link segment for the given extreme node and access mode, taking into account any explicit overwrites that may exist that are not bounded by any limitations on compatibility.
        Parameters:
        waitingAreaSourceId - we're checking for
        waitingAreaGeometry - we're checking for
        accessLinkSegment - nominated
        accessLinkSourceId - original source id of the PLANit access link
        accessNode - that is nominated
        accessMode - used
        getOverwrittenWaitingAreaSourceId - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwritten
        getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId - mapping from waiting area source id to nominated access link source id, which if a match to provided access link source id makes sure that even if there exists crossing traffic this does not render its access link segment(s) invalid, may be null
        countryName - to extract driving direction from
        geoUtils - gis functionality to apply in finding connectoid location
        Returns:
        true when at least one valid access link segment exists, false otherwise
      • hasWaitingAreaPotentialAccessLinkSegmentForLinkNodeModeCombination

        public static boolean hasWaitingAreaPotentialAccessLinkSegmentForLinkNodeModeCombination​(String waitingAreaSourceId,
                                                                                                 org.locationtech.jts.geom.Geometry waitingAreaGeometry,
                                                                                                 MacroscopicLink accessLink,
                                                                                                 String accessLinkSourceId,
                                                                                                 Node accessNode,
                                                                                                 Mode accessMode,
                                                                                                 Function<Node,​String> getOverwrittenWaitingAreaSourceId,
                                                                                                 Function<String,​String> getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId,
                                                                                                 String countryName,
                                                                                                 PlanitJtsCrsUtils geoUtils)
        Verify if any valid access link segments exist for the given combination of link, one of its extreme nodes, and the access mode, taking into account any explicit overwrites that may exist that are not bounded by any limitations on compatibility.
        Parameters:
        waitingAreaSourceId - we're checking for
        waitingAreaGeometry - we're checking for
        accessLink - nominated
        accessLinkSourceId - original source id of the PLANit access link
        accessNode - that is nominated
        accessMode - used
        getOverwrittenWaitingAreaSourceId - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwritten
        getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId - mapping from waiting area source id to nominated access link source id, which if a match to provided access link source id makes sure that even if there exists crossing traffic this does not render its access link segment(s) invalid, may be null
        countryName - to extract driving direction from
        geoUtils - gis functionality to apply in finding connectoid location
        Returns:
        true when at least one valid access link segment exists, false otherwise
      • findConnectoidLocationForWaitingAreaOnLinkSegment

        public static org.locationtech.jts.geom.Point findConnectoidLocationForWaitingAreaOnLinkSegment​(String waitingAreaSourceId,
                                                                                                        org.locationtech.jts.geom.Geometry waitingAreaGeometry,
                                                                                                        MacroscopicLinkSegment accessLinkSegment,
                                                                                                        String accessLinkSourceId,
                                                                                                        Mode accessMode,
                                                                                                        double maxAllowedDistanceMeters,
                                                                                                        Function<Node,​String> getOverwrittenWaitingAreaSourceIdForNode,
                                                                                                        Function<org.locationtech.jts.geom.Point,​String> getOverwrittenWaitingAreaSourceIdForPoint,
                                                                                                        Function<String,​String> getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId,
                                                                                                        String countryName,
                                                                                                        PlanitJtsCrsUtils geoUtils)
        find a suitable connectoid location on the given link based on the constraints that it must be able to reside on a link segment that is in the correct relative position to the transfer zone and supports the access mode on at least one of the designated link segment(s) that is eligible (if any). If not null is returned, otherwise the returned location may be an existing extreme node's location, or a location internal to the link if the extreme node does not fall within the constraints provided
        Parameters:
        waitingAreaSourceId - supplies a relevant source id of the waiting area in question to use for exceptions or logging when needed
        waitingAreaGeometry - to find location for (which is either sourced from a PLANit transfer zone, or to be created transfer zone) that will reflect this waiting area)
        accessLinkSegment - to find location on
        accessLinkSourceId - the access link's source id
        accessMode - to be compatible with
        maxAllowedDistanceMeters - the maximum allowed distance between stop and waiting area that we allow
        getOverwrittenWaitingAreaSourceIdForNode - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwritten
        getOverwrittenWaitingAreaSourceIdForPoint - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwritten
        getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId - mapping from waiting area source id to nominated access link source id, which if a match to provided access link source id makes sure that even if there exists crossing traffic this does not render its access link segment(s) invalid, may be null
        countryName - to extract driving direction from
        geoUtils - gis functionality to apply in finding connectoid location
        Returns:
        found location either existing node or projected location that is nearest and does not exist as a shape point on the link yet, or null if no valid position could be found
      • findConnectoidLocationForWaitingAreaOnLink

        @Deprecated
        public static org.locationtech.jts.geom.Point findConnectoidLocationForWaitingAreaOnLink​(String waitingAreaSourceId,
                                                                                                 org.locationtech.jts.geom.Geometry waitingAreaGeometry,
                                                                                                 MacroscopicLink accessLink,
                                                                                                 String accessLinkSourceId,
                                                                                                 Mode accessMode,
                                                                                                 double maxAllowedDistanceMeters,
                                                                                                 Function<Node,​String> getOverwrittenWaitingAreaSourceIdForNode,
                                                                                                 Function<org.locationtech.jts.geom.Point,​String> getOverwrittenWaitingAreaSourceIdForPoint,
                                                                                                 Function<String,​String> getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId,
                                                                                                 String countryName,
                                                                                                 PlanitJtsCrsUtils geoUtils)
        Deprecated.
        find a suitable connectoid location on the given link based on the constraints that it must be able to reside on a link segment that is in the correct relative position to the transfer zone and supports the access mode on at least one of the designated link segment(s) that is eligible (if any). If not null is returned, otherwise the returned location may be an existing extreme node's location, or a location internal to the link if the extreme node does not fall within the constraints provided
        Parameters:
        waitingAreaSourceId - supplies a relevant source id of the waiting area in question to use for exceptions or logging when needed
        waitingAreaGeometry - to find location for (which is either sourced from a PLANit transfer zone, or to be created transfer zone) that will reflect this waiting area)
        accessLink - to find location on
        accessLinkSourceId - the access link's source id
        accessMode - to be compatible with
        maxAllowedDistanceMeters - the maximum allowed distance between stop and waiting area that we allow
        getOverwrittenWaitingAreaSourceIdForNode - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwritten
        getOverwrittenWaitingAreaSourceIdForPoint - function that provides the overwritten waiting area source id for a given access node, maybe return null if not overwritten
        getOverwrittenAccessLinkSourceIdForWaitingAreaSourceId - mapping from waiting area source id to nominated access link source id, which if a match to provided access link source id makes sure that even if there exists crossing traffic this does not render its access link segment(s) invalid, may be null
        countryName - to extract driving direction from
        geoUtils - gis functionality to apply in finding connectoid location
        Returns:
        found location either existing node or projected location that is nearest and does not exist as a shape point on the link yet, or null if no valid position could be found
      • createAndRegisterDirectedConnectoid

        public static DirectedConnectoid createAndRegisterDirectedConnectoid​(Zoning zoning,
                                                                             TransferZone accessZone,
                                                                             boolean downstreamAccessNode,
                                                                             MacroscopicLinkSegment linkSegment,
                                                                             Set<Mode> allowedModes)
        create directed connectoid for the link segment provided, all related to the given transfer zone and with access modes provided. When the link segment does not have any of the passed in modes listed as allowed, no connectoid is created and null is returned
        Parameters:
        zoning - to register on
        accessZone - to relate connectoids to
        downstreamAccessNode - when true access node is chosen as the downstream node, when false, upstream node is chosen
        linkSegment - to create connectoid for
        allowedModes - used for the connectoid
        Returns:
        created connectoid when at least one of the allowed modes is also allowed on the link segment
      • createAndRegisterDirectedConnectoids

        public static Collection<DirectedConnectoid> createAndRegisterDirectedConnectoids​(Zoning zoning,
                                                                                          TransferZone transferZone,
                                                                                          Node accessNode,
                                                                                          Iterable<? extends MacroscopicLinkSegment> linkSegments,
                                                                                          Set<Mode> allowedModes)
        create directed connectoids, one per link segment provided, all related to the given transfer zone and with access modes provided. connectoids are only created when the access link segment has at least one of the allowed modes as an eligible mode
        Parameters:
        zoning - to register on
        transferZone - to relate connectoids to
        accessNode - the access node the connectoid utilises (determine the up/downstream connection of the attached link segment(s)
        linkSegments - to create connectoids for (one per segment)
        allowedModes - used for each connectoid
        Returns:
        created connectoids