Example #1
0
    def test_left_hand__rtx(self):
        # t1
        tags = {'highway': 'residential', 'cycleway': 'track'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 3))

        # t2
        tags = {
            'highway': 'residential',
            'cycleway:right': 'track',
            'cycleway:right:oneway': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 3))

        # t3
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'cycleway:right': 'track',
            'oneway:bicycle': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 3))

        # t4
        tags = {'highway': 'residential', 'cycleway:right': 'track'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 1))
Example #2
0
    def test_left_hand__rsx(self):
        # s1
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'oneway:bicycle': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 1))

        # s1
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'cycleway': 'opposite'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 1))

        # s2
        tags = {
            'highway': 'residential',
            'cycleway:left': 'track',
            'cycleway:right': 'lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 3))

        # s3
        tags = {
            'highway': 'residential',
            'segregated': 'yes',
            'cycleway': 'track'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 3))

        # s5
        tags = {
            'highway': 'path',
            'segregated': 'yes',
            'foot': 'designated',
            'bicycle': 'designated'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 3))
Example #3
0
    def test_right_hand_rlx(self):
        tags = {'highway': 'residential', 'cycleway': 'lane'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {
            'highway': 'residential',
            'cycleway:right': 'lane',
            'cycleway:left': 'lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {'highway': 'residential', 'cycleway:both': 'lane'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {
            'highway': 'residential',
            'cycleway:left': 'lane',
            'cycleway:left:oneway': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {'highway': 'residential', 'cycleway': 'lane'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {'highway': 'residential', 'cycleway:left': 'lane'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 1))
Example #4
0
    def test_left_hand__specials(self):
        # general_oneway
        tags = {'highway': 'cycleway', 'oneway': 'yes'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, False, 3, -1))

        # general
        tags = {'highway': 'cycleway'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 3, 3))

        # cyclestreet
        tags = {'highway': 'residential', 'cyclestreet': 'yes'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 1))

        # pedestrians_bicycle
        tags = {'highway': 'pedestrian', 'bicycle': 'yes'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        # pedestrians
        tags = {'highway': 'pedestrian'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 1))

        # has_bicycles
        tags = {'highway': 'path'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {'highway': 'track'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        # nothing
        tags = {'highway': 'residential'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 1))
Example #5
0
    def way(self, w):
        osm_id = w.id
        tags = w.tags

        attributes = dict()
        tags = {tag.k: tag.v for tag in w.tags}

        # 1 GENERAL highway
        if 'highway' not in tags:
            if 'foot' not in tags:
                if 'bicycle' not in tags:
                    if 'pedestrian' not in tags:
                        return
                    else:
                        if tags['pedestrian'] in ['yes', 'true', '1']:
                            attributes['highway'] = 'footway'
                            tags['highway'] = attributes['highway']
                        else:
                            return
                else:
                    if tags['bicycle'] in [
                            'yes', 'true', '1'
                    ] or tags['bicycle'] == 'designated':
                        attributes['highway'] = 'cycleway'
                        tags['highway'] = attributes['highway']
                    else:
                        return
            else:
                if tags['foot'] in ['yes', 'true', '1']:
                    attributes['highway'] = 'pedestrian'
                    tags['highway'] = attributes['highway']
                else:
                    return
        else:
            attributes['highway'] = tags['highway']

        # 2 GENERAL level according to highway
        attributes['level'] = get_level(attributes['highway'])
        if attributes['level'] > self.level_upper_bound or attributes[
                'level'] < self.level_lower_bound:
            return

        # 3 GENERAL oneway (oneway, reverse)
        attributes['oneway'], attributes['reversed'], tags = get_one_way(
            tags, attributes['highway'])

        # 4 GENERAL lanes according to level
        attributes['lanes'] = get_lanes(tags, attributes['level'],
                                        attributes['oneway'])

        # 5 GENERAL width according to lanes
        attributes['width'] = get_width(tags, attributes['lanes'],
                                        attributes['level'], self.country_iso3)

        # 6 SPECIFIC bicycle with rules
        attributes['bicycle_forward'], attributes[
            'bicycle_backward'], attributes[
                'bicycle_safety_forward'], attributes[
                    'bicycle_safety_backward'] = get_bicycle(
                        tags, attributes['level'], self.country_iso3)
        # use bicycle lane to create an alternate

        # 7 SPECIFIC footway with rules
        attributes['foot'], attributes['foot_safety'] = get_foot(
            tags, attributes['highway'], attributes['level'],
            self.country_iso3)
        # 8 SPECIFIC motorcar with rules maxspeed
        attributes['maxspeed'] = get_max_speed(tags)
        attributes['motorcar'] = get_access(self.country_iso3,
                                            attributes['highway'], 'motorcar')

        us = [i.ref for i in w.nodes][:-1]
        vs = [i.ref for i in w.nodes][1:]

        for i, (u, v) in enumerate(zip(us, vs)):
            osm_id_prefix = '{0}-{1}'.format(osm_id, i)
            if self.directed is False:
                self.edges_tuples.append(
                    (osm_id_prefix, u, v, attributes['highway'],
                     attributes['oneway'], attributes['level'],
                     attributes['lanes'], attributes['width'],
                     attributes['bicycle_forward'],
                     attributes['bicycle_safety_forward'], attributes['foot'],
                     attributes['foot_safety'], attributes['maxspeed'],
                     attributes['motorcar']))
            else:
                if attributes['oneway'] is False:
                    # add forward edge
                    self.edges_tuples.append(
                        (osm_id_prefix, u, v, attributes['highway'],
                         attributes['oneway'], attributes['level'],
                         attributes['lanes'], attributes['width'],
                         attributes['bicycle_forward'],
                         attributes['bicycle_safety_forward'],
                         attributes['foot'], attributes['foot_safety'],
                         attributes['maxspeed'], attributes['motorcar']))
                    # add backward edge
                    self.edges_tuples.append(
                        (osm_id_prefix + '-r', v, u, attributes['highway'],
                         attributes['oneway'], attributes['level'],
                         attributes['lanes'], attributes['width'],
                         attributes['bicycle_backward'],
                         attributes['bicycle_safety_backward'],
                         attributes['foot'], attributes['foot_safety'],
                         attributes['maxspeed'], attributes['motorcar']))
                else:
                    # if we have to add only one direction BUT bike is authorize in the other way... or Foot...
                    # depending on the country and the access, we add a reverse footway...
                    if attributes['reversed'] is True:
                        self.edges_tuples.append(
                            (osm_id_prefix + '-1', v, u, attributes['highway'],
                             attributes['oneway'], attributes['level'],
                             attributes['lanes'], attributes['width'],
                             attributes['bicycle_backward'],
                             attributes['bicycle_safety_backward'],
                             attributes['foot'], attributes['foot_safety'],
                             attributes['maxspeed'], attributes['motorcar']))
                        if attributes['bicycle_forward']:
                            self.edges_tuples.append(
                                (osm_id_prefix + '-b', u, v, 'cycleway',
                                 attributes['oneway'], get_level('cycleway'),
                                 1, 1.5, attributes['bicycle_forward'],
                                 attributes['bicycle_safety_forward'], False,
                                 0, 30, False))
                        if attributes['foot']:
                            self.edges_tuples.append(
                                (osm_id_prefix + '-f', u, v, 'footway',
                                 attributes['oneway'], get_level('footway'), 1,
                                 1.5, False, -1, True, 1, 30, False))
                    else:
                        self.edges_tuples.append(
                            (osm_id_prefix, u, v, attributes['highway'],
                             attributes['oneway'], attributes['level'],
                             attributes['lanes'], attributes['width'],
                             attributes['bicycle_forward'],
                             attributes['bicycle_safety_forward'],
                             attributes['foot'], attributes['foot_safety'],
                             attributes['maxspeed'], attributes['motorcar']))
                        if attributes['bicycle_backward']:
                            self.edges_tuples.append(
                                (osm_id_prefix + '-1b', v, u, 'cycleway',
                                 attributes['oneway'], get_level('cycleway'),
                                 1, 1.5, attributes['bicycle_backward'],
                                 attributes['bicycle_safety_backward'], False,
                                 0, 30, False))
                        if attributes['foot']:
                            self.edges_tuples.append(
                                (osm_id_prefix + '-1f', v, u, 'footway',
                                 attributes['oneway'], get_level('footway'), 1,
                                 1.5, False, -1, True, 1, 30, False))
Example #6
0
    def test_left_hand__rbx(self):
        # b1
        tags = {
            'highway': 'residential',
            'lanes': '3',
            'lanes:forward': '2',
            'access:lanes': 'no|yes|yes|no|no',
            'bicycle:lanes': 'designated|yes|yes|designated|yes',
            'bus:lanes': 'no|yes|yes|no|designated',
            'taxi:lanes': 'no|yes|yes|no|designated'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        # b3
        tags = {
            'highway': 'residential',
            'busway:right': 'lane',
            'cycleway:left': 'lane',
            'cycleway:right': 'share_busway'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        # b4
        tags = {
            'highway': 'service',
            'service': 'bus',
            'oneway': 'yes',
            'cycleway:right': 'share_busway'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, False, 2, -1))

        # b5
        tags = {
            'highway': 'residential',
            'lanes': '4',
            'lanes:bus:forward': '1',
            'busway:right': 'lane',
            'cycleway:right': 'share_busway'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 1))

        # b6
        tags = {
            'highway': 'residential',
            'cycleway:left': 'share_busway',
            'busway': 'opposite_lane',
            'oneway': 'yes',
            'oneway:bicycle': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 2))

        tags = {
            'highway': 'residential',
            'cycleway:left': 'share_busway',
            'busway': 'lane',
            'oneway': 'yes',
            'oneway:bus': 'no',
            'oneway:bicycle': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'fra')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 2))
Example #7
0
    def test_right_hand_rmx(self):
        # M1
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'cycleway': 'lane',
            'oneway:bicycle': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'cycleway:right': 'opposite_lane',
            'cycleway:left': 'lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        # m2a
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'cycleway:left': 'lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, False, 2, -1))

        tags = {'highway': 'residential', 'oneway': 'yes', 'cycleway': 'lane'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, False, 2, -1))

        # m2b
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'cycleway:right': 'lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, False, 2, -1))

        tags = {'highway': 'residential', 'oneway': 'yes', 'cycleway': 'lane'}
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, False, 2, -1))

        # m2c
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'lanes': '2',
            'cycleway': 'lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, False, 2, -1))

        # m2d
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'oneway:bicycle': 'no',
            'cycleway:right': 'lane',
            'cycleway:right:oneway': 'no'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 2, 2))

        # m3a
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'oneway:bicycle': 'no',
            'cycleway:right': 'opposite_lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 2))

        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'oneway:bicycle': 'no',
            'cycleway': 'opposite_lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 2))

        # m3b
        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'oneway:bicycle': 'no',
            'cycleway:left': 'opposite_lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 2))

        tags = {
            'highway': 'residential',
            'oneway': 'yes',
            'oneway:bicycle': 'no',
            'cycleway': 'opposite_lane'
        }
        f, b, s_f, s_b = get_bicycle(tags, 3, 'gbr')
        self.assertEqual((f, b, s_f, s_b), (True, True, 1, 2))