Beispiel #1
0
def test_collector_doesnt_drop_unjoined_ways(vermont_125_and_us_7):
    collector = WayCollector()
    collections = []

    collector.parse(vermont_125_and_us_7,
                    callback=lambda collection: collections.append(collection))
    assert len(collections) == 4  # VT 30, VT 125, two for US 7
    # First collection, could not be joined to the others since it has no refs in common.
    collection = next(
        filter(
            lambda c: c['join_data'] == 'US 7' and c['ways'][0]['id'] == 20001,
            collections), None)
    assert collection['join_type'] == 'ref'
    assert collection['join_data'] == 'US 7'
    assert len(collection['ways']) == 2
    assert collection['ways'][0]['id'] == 20001
    assert collection['ways'][1]['id'] == 30001

    # Second collection, could be joined to the others
    collection = next(
        filter(
            lambda c: c['join_data'] == 'US 7' and c['ways'][0]['id'] == 30002,
            collections), None)
    assert collection['join_type'] == 'ref'
    assert collection['join_data'] == 'US 7'
    assert len(collection['ways']) == 1
    assert collection['ways'][0]['id'] == 30002
Beispiel #2
0
def test_collector_joins_past_roundabout(us2):
    collector = WayCollector()
    collections = []

    collector.parse(us2,
                    callback=lambda collection: collections.append(collection))

    assert collections[0]['ways'][8][
        'id'] == 19724163, "Low-id two-direction way. Should be base. Bailey Avenue"
    assert collections[0]['ways'][7][
        'id'] == 143178266, "2nd two-direction way. Memorial Drive."
    assert collections[0]['ways'][6][
        'id'] == 28483253, "3rd two-direction way. Berlin Street."
    assert collections[0]['ways'][5][
        'id'] == 158420752, "4th two-direction way. River Street."
    assert collections[0]['ways'][4][
        'id'] == 158420747, "Roundabout-exit, west-bound. River Street."
    assert collections[0]['ways'][3][
        'id'] == 172791608, "Roundabout, west-bound."
    assert collections[0]['ways'][2][
        'id'] == 158420755, "Roundabout-entrance, west-bound. River Street."
    assert collections[0]['ways'][1][
        'id'] == 195936126, "Two-direction way east of circle. River Street."
    assert collections[0]['ways'][0][
        'id'] == 195936143, "Two-direction way east of circle (bridge). River Street."

    assert collections[1]['ways'][0][
        'id'] == 158420750, "Roundabout-exit, east-bound. River Street."
    assert collections[1]['ways'][1][
        'id'] == 172791605, "Roundabout, east-bound."
    assert collections[1]['ways'][2][
        'id'] == 158420754, "Roundabout-entrance, east-bound. River Street."
    assert len(collections) == 2  # VT 30, VT 125, two for US 7
Beispiel #3
0
def test_collector_ref_matching():
    collector = WayCollector(parser_class=Vermont125Parser)
    collections = []

    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))
    assert len(collections) == 3 # VT 30, VT 125, US 7
    # Get the collection for VT 125.
    found = False
    for collection in collections:
        if collection['join_type'] == 'ref' and collection['join_data'] == 'VT 125':
            found = True
            break
    assert len(collection['ways']) == 5
    assert collection['join_type'] == 'ref'
    assert collection['join_data'] == 'VT 125'

    expected =  [
          {'coords': [(-73.00024, 43.70024),
                      (-73.00023, 43.70023),
                      (-73.00022, 43.70022),
                      (-73.00021, 43.70021)],
           'id': 20002,
           'refs': [224, 223, 222, 221],
           'tags': {'highway': 'secondary',
                    'name': 'Main Street',
                    'ref': 'VT 125;VT 30'}},
          {'coords': [(-73.00021, 43.70021),
                      (-73.0002, 43.7002),
                      (-73.00019, 43.70019),
                      (-73.00018, 43.70018)],
           'id': 20001,
           'refs': [221, 220, 219, 218],
           'tags': {'highway': 'primary',
                    'name': 'Court Street',
                    'ref': 'US 7;VT 125'}},
          {'coords': [(-73.00018, 43.70018),
                      (-73.00017, 43.70017),
                      (-73.00016, 43.70016),
                      (-73.00015, 43.70015)],
           'id': 20000,
           'refs': [218, 217, 216, 215],
           'tags': {'highway': 'secondary',
                    'name': 'South Main Street',
                    'ref': 'VT 125'}},
          {'coords': [(-73.00015, 43.70015),
                      (-73.00014, 43.70014),
                      (-73.00013, 43.70013),
                      (-73.00012, 43.70012)],
           'id': 20003,
           'refs': [215, 214, 213, 212],
           'tags': {'highway': 'secondary', 'name': 'Ripton Road', 'ref': 'VT 125'}},
          {'coords': [(-73.00012, 43.70012),
                      (-73.00011, 43.70011),
                      (-73.0001, 43.7001),
                      (-73.00009, 43.70009)],
           'id': 20004,
           'refs': [212, 211, 210, 209],
           'tags': {'highway': 'secondary', 'name': 'Hancock Road', 'ref': 'VT 125'}}]
    assert collection['ways'] == expected
Beispiel #4
0
def test_collector_ref_matching():
    collector = WayCollector(parser_class=Vermont125Parser)
    collections = []

    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))
    assert len(collections) == 3 # VT 30, VT 125, US 7
    # Get the collection for VT 125.
    found = False
    for collection in collections:
        if collection['join_type'] == 'ref' and collection['join_data'] == 'VT 125':
            found = True
            break
    assert len(collection['ways']) == 5
    assert collection['join_type'] == 'ref'
    assert collection['join_data'] == 'VT 125'

    expected = [{'coords': [(-73.00009, 43.70009),
                          (-73.0001, 43.7001),
                          (-73.00011, 43.70011),
                          (-73.00012, 43.70012)],
               'id': 20004,
               'refs': [209, 210, 211, 212],
               'tags': {'highway': 'secondary', 'name': 'Hancock Road', 'ref': 'VT 125'}},
              {'coords': [(-73.00012, 43.70012),
                          (-73.00013, 43.70013),
                          (-73.00014, 43.70014),
                          (-73.00015, 43.70015)],
               'id': 20003,
               'refs': [212, 213, 214, 215],
               'tags': {'highway': 'secondary', 'name': 'Ripton Road', 'ref': 'VT 125'}},
              {'coords': [(-73.00015, 43.70015),
                          (-73.00016, 43.70016),
                          (-73.00017, 43.70017),
                          (-73.00018, 43.70018)],
               'id': 20000,
               'refs': [215, 216, 217, 218],
               'tags': {'highway': 'secondary', 'name': 'South Main Street', 'ref': 'VT 125'}},
              {'coords': [(-73.00018, 43.70018),
                          (-73.00019, 43.70019),
                          (-73.0002, 43.7002),
                          (-73.00021, 43.70021)],
               'id': 20001,
               'refs': [218, 219, 220, 221],
               'tags': {'highway': 'primary', 'name': 'Court Street', 'ref': 'US 7;VT 125'}},
              {'coords': [(-73.00021, 43.70021),
                          (-73.00022, 43.70022),
                          (-73.00023, 43.70023),
                          (-73.00024, 43.70024)],
                'id': 20002,
                'refs': [221, 222, 223, 224],
                'tags': {'highway': 'secondary', 'name': 'Main Street', 'ref': 'VT 125;VT 30'}}
        ]
    assert collection['ways'] == expected
Beispiel #5
0
def test_collector_road_a():
    collector = WayCollector(parser_class=RoadAParser)
    collections = []
    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))
    assert len(collections) == 1
    assert len(collections[0]['ways']) == 5
    assert collections[0]['join_type'] == 'name'
    assert collections[0]['join_data'] == 'Road A'

    expected =  [
        {'coords': [(-73.00024, 43.70024),
                      (-73.00023, 43.70023),
                      (-73.00022, 43.70022),
                      (-73.00021, 43.70021)],
         'id': 10002,
         'refs': [24, 23, 22, 21],
         'tags': {'highway': 'unclassified', 'name': 'Road A'}},
        {'coords': [(-73.00021, 43.70021),
                  (-73.0002, 43.7002),
                  (-73.00019, 43.70019),
                  (-73.00018, 43.70018)],
         'id': 10001,
         'refs': [21, 20, 19, 18],
         'tags': {'highway': 'unclassified', 'name': 'Road A'}},
        {'coords': [(-73.00018, 43.70018),
                  (-73.00017, 43.70017),
                  (-73.00016, 43.70016),
                  (-73.00015, 43.70015)],
         'id': 10000,
         'refs': [18, 17, 16, 15],
         'tags': {'highway': 'unclassified', 'name': 'Road A'}},
        {'coords': [(-73.00015, 43.70015),
                  (-73.00014, 43.70014),
                  (-73.00013, 43.70013),
                  (-73.00012, 43.70012)],
         'id': 10003,
         'refs': [15, 14, 13, 12],
         'tags': {'highway': 'unclassified', 'name': 'Road A'}},
        {'coords': [(-73.00012, 43.70012),
                  (-73.00011, 43.70011),
                  (-73.0001, 43.7001),
                  (-73.00009, 43.70009)],
         'id': 10004,
         'refs': [12, 11, 10, 9],
         'tags': {'highway': 'unclassified', 'name': 'Road A'}}]

    assert collections[0]['ways'] == expected
Beispiel #6
0
def test_collector_road_a():
    collector = WayCollector(parser_class=RoadAParser)
    collections = []
    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))
    assert len(collections) == 1
    assert len(collections[0]['ways']) == 5
    assert collections[0]['join_type'] == 'name'
    assert collections[0]['join_data'] == 'Road A'

    expected = [{'coords': [(-73.00009, 43.70009),
                          (-73.0001, 43.7001),
                          (-73.00011, 43.70011),
                          (-73.00012, 43.70012)],
               'id': 10004,
               'refs': [9, 10, 11, 12],
               'tags': {'highway': 'unclassified', 'name': 'Road A'}},
              {'coords': [(-73.00012, 43.70012),
                          (-73.00013, 43.70013),
                          (-73.00014, 43.70014),
                          (-73.00015, 43.70015)],
               'id': 10003,
               'refs': [12, 13, 14, 15],
               'tags': {'highway': 'unclassified', 'name': 'Road A'}},
              {'coords': [(-73.00015, 43.70015),
                          (-73.00016, 43.70016),
                          (-73.00017, 43.70017),
                          (-73.00018, 43.70018)],
               'id': 10000,
               'refs': [15, 16, 17, 18],
               'tags': {'highway': 'unclassified', 'name': 'Road A'}},
              {'coords': [(-73.00018, 43.70018),
                          (-73.00019, 43.70019),
                          (-73.0002, 43.7002),
                          (-73.00021, 43.70021)],
               'id': 10001,
               'refs': [18, 19, 20, 21],
               'tags': {'highway': 'unclassified', 'name': 'Road A'}},
              {'coords': [(-73.00021, 43.70021),
                          (-73.00022, 43.70022),
                          (-73.00023, 43.70023),
                          (-73.00024, 43.70024)],
                'id': 10002,
                'refs': [21, 22, 23, 24],
                'tags': {'highway': 'unclassified', 'name': 'Road A'}}
        ]

    assert collections[0]['ways'] == expected
Beispiel #7
0
def test_collector_doesnt_drop_unjoined_ways():
    collector = WayCollector(parser_class=Vermont125AndUs7Parser)
    collections = []

    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))
    assert len(collections) == 4 # VT 30, VT 125, two for US 7

    # First collection, could not be joined to the others since it has no refs in common.
    assert collections[2]['join_type'] == 'ref'
    assert collections[2]['join_data'] == 'US 7'
    assert len(collections[2]['ways']) == 1
    assert collections[2]['ways'][0]['id'] == 30002

    # Second collection, could be joined to the others
    assert collections[3]['join_type'] == 'ref'
    assert collections[3]['join_data'] == 'US 7'
    assert len(collections[3]['ways']) == 2
    assert collections[3]['ways'][0]['id'] == 20001
    assert collections[3]['ways'][1]['id'] == 30001
Beispiel #8
0
def test_collector_doesnt_drop_unjoined_ways():
    collector = WayCollector(parser_class=Vermont125AndUs7Parser)
    collections = []

    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))
    assert len(collections) == 4 # VT 30, VT 125, two for US 7

    # First collection, could not be joined to the others since it has no refs in common.
    assert collections[2]['join_type'] == 'ref'
    assert collections[2]['join_data'] == 'US 7'
    assert len(collections[2]['ways']) == 2
    assert collections[2]['ways'][0]['id'] == 20001
    assert collections[2]['ways'][1]['id'] == 30001

    # Second collection, could be joined to the others
    assert collections[3]['join_type'] == 'ref'
    assert collections[3]['join_data'] == 'US 7'
    assert len(collections[3]['ways']) == 1
    assert collections[3]['ways'][0]['id'] == 30002
Beispiel #9
0
def test_collector_joins_past_roundabout():
    collector = WayCollector(parser_class=US2Parser)
    collections = []

    collector.parse('doesnt_exist.pbf', callback=lambda collection: collections.append(collection))

    assert collections[0]['ways'][8]['id'] == 19724163, "Low-id two-direction way. Should be base. Bailey Avenue"
    assert collections[0]['ways'][7]['id'] == 143178266, "2nd two-direction way. Memorial Drive."
    assert collections[0]['ways'][6]['id'] == 28483253, "3rd two-direction way. Berlin Street."
    assert collections[0]['ways'][5]['id'] == 158420752, "4th two-direction way. River Street."
    assert collections[0]['ways'][4]['id'] == 158420747, "Roundabout-exit, west-bound. River Street."
    assert collections[0]['ways'][3]['id'] == 172791608, "Roundabout, west-bound."
    assert collections[0]['ways'][2]['id'] == 158420755, "Roundabout-entrance, west-bound. River Street."
    assert collections[0]['ways'][1]['id'] == 195936126, "Two-direction way east of circle. River Street."
    assert collections[0]['ways'][0]['id'] == 195936143, "Two-direction way east of circle (bridge). River Street."

    assert collections[1]['ways'][0]['id'] == 158420750, "Roundabout-exit, east-bound. River Street."
    assert collections[1]['ways'][1]['id'] == 172791605, "Roundabout, east-bound."
    assert collections[1]['ways'][2]['id'] == 158420754, "Roundabout-entrance, east-bound. River Street."
    assert len(collections) == 2 # VT 30, VT 125, two for US 7
Beispiel #10
0
def test_joining_stays_on_higher_class_roads(forlandet):
    collector = WayCollector()
    collections = []
    collector.parse(forlandet,
                    callback=lambda collection: collections.append(collection))
    assert len(collections) == 2
    assert len(collections[0]['ways']) == 3
    assert collections[0]['join_type'] == 'name'
    assert collections[0]['join_data'] == 'Forlandet'

    # Verify the IDs of our three tertiary roads.
    assert collections[0]['ways'][0]['id'] == 20001
    assert collections[0]['ways'][0]['tags']['highway'] == 'tertiary'
    assert collections[0]['ways'][1]['id'] == 20005
    assert collections[0]['ways'][1]['tags']['highway'] == 'tertiary'
    assert collections[0]['ways'][2]['id'] == 20004
    assert collections[0]['ways'][2]['tags']['highway'] == 'tertiary'

    # Verify that the service road ended up in its own collection
    assert len(collections[1]['ways']) == 1
    assert collections[1]['ways'][0]['id'] == 20003
    assert collections[1]['ways'][0]['tags']['highway'] == 'service'
Beispiel #11
0
parser.add_argument('--max_lon_bound', type=float, default=None, help='The maximum longitude to include.')
parser.add_argument('--straight_segment_split_threshold', type=float, default=1.5, help='If a way has a series of non-curved segments longer than this (miles), the way will be split on that straight section. Use 0 to never split ways. The default is 1.5')
parser.add_argument('file', type=argparse.FileType('r'), nargs='+', help='the input file. Should be an OSM XML file.')
args = parser.parse_args()

rad_earth_mi = 3960 # Radius of the earth in miles
rad_earth_m = 6373000 # Radius of the earth in meters

# Validate our limit_points argument.
if args.limit_points < 2:
	if args.limit_points != 0:
		sys.stderr.write("\n--limit_points must be 0 or >= 2.")
		exit(2);

# Instantiate our collector
collector = WayCollector()
default_filter = WayFilter()

# Configure settings based on the command-line arguments
collector.verbose = args.v
default_filter.min_length = args.min_length
default_filter.max_length = args.max_length
default_filter.min_curvature = args.min_curvature
default_filter.max_curvature = args.max_curvature
collector.ignored_surfaces = args.ignored_surfaces.split(',')
collector.roads = args.highway_types.split(',')
collector.level_1_max_radius = args.level_1_max_radius
collector.level_1_weight = args.level_1_weight
collector.level_2_max_radius = args.level_2_max_radius
collector.level_2_weight = args.level_2_weight
collector.level_3_max_radius = args.level_3_max_radius
Beispiel #12
0
def test_collector_road_b(road_b):
    collector = WayCollector()
    collections = []
    collector.parse(road_b,
                    callback=lambda collection: collections.append(collection))
    assert len(collections) == 1
    assert len(collections[0]['ways']) == 5
    assert collections[0]['join_type'] == 'ref'
    assert collections[0]['join_data'] == 'CR123'

    expected = [{
        'coords': [(-73.00009, 43.70009), (-73.0001, 43.7001),
                   (-73.00011, 43.70011), (-73.00012, 43.70012)],
        'id':
        10004,
        'refs': [9, 10, 11, 12],
        'nodes': {},
        'tags': {
            'highway': 'unclassified',
            'name': 'Road E',
            'admin_ref': 'CR123'
        }
    }, {
        'coords': [(-73.00012, 43.70012), (-73.00013, 43.70013),
                   (-73.00014, 43.70014), (-73.00015, 43.70015)],
        'id':
        10003,
        'refs': [12, 13, 14, 15],
        'nodes': {},
        'tags': {
            'highway': 'unclassified',
            'name': 'Road D',
            'highway_authority_ref': 'CR123'
        }
    }, {
        'coords': [(-73.00015, 43.70015), (-73.00016, 43.70016),
                   (-73.00017, 43.70017), (-73.00018, 43.70018)],
        'id':
        10000,
        'refs': [15, 16, 17, 18],
        'nodes': {},
        'tags': {
            'highway': 'unclassified',
            'name': 'Road A',
            'ref': 'CR123'
        }
    }, {
        'coords': [(-73.00018, 43.70018), (-73.00019, 43.70019),
                   (-73.0002, 43.7002), (-73.00021, 43.70021)],
        'id':
        10001,
        'refs': [18, 19, 20, 21],
        'nodes': {},
        'tags': {
            'highway': 'unclassified',
            'name': 'Road B',
            'official_ref': 'CR123'
        }
    }, {
        'coords': [(-73.00021, 43.70021), (-73.00022, 43.70022),
                   (-73.00023, 43.70023), (-73.00024, 43.70024)],
        'id':
        10002,
        'refs': [21, 22, 23, 24],
        'nodes': {},
        'tags': {
            'highway': 'unclassified',
            'name': 'Road C',
            'highway_ref': 'CR123'
        }
    }]

    assert collections[0]['ways'] == expected
Beispiel #13
0
                    type=argparse.FileType('r'),
                    nargs='+',
                    help='the input file. Should be an OSM XML file.')
args = parser.parse_args()

rad_earth_mi = 3960  # Radius of the earth in miles
rad_earth_m = 6373000  # Radius of the earth in meters

# Validate our limit_points argument.
if args.limit_points < 2:
    if args.limit_points != 0:
        sys.stderr.write("\n--limit_points must be 0 or >= 2.")
        exit(2)

# Instantiate our collector
collector = WayCollector()
default_filter = WayFilter()

# Configure settings based on the command-line arguments
collector.verbose = args.v
default_filter.min_length = args.min_length
default_filter.max_length = args.max_length
default_filter.min_curvature = args.min_curvature
default_filter.max_curvature = args.max_curvature
collector.ignored_surfaces = args.ignored_surfaces.split(',')
collector.roads = args.highway_types.split(',')
collector.level_1_max_radius = args.level_1_max_radius
collector.level_1_weight = args.level_1_weight
collector.level_2_max_radius = args.level_2_max_radius
collector.level_2_weight = args.level_2_weight
collector.level_3_max_radius = args.level_3_max_radius