Exemple #1
0
def test_bbox_russia():
    # Start with two coords on either side of the antimeridan on the Bearing Straight.
    bbox = BBox.from_coords([(63.7, -167.3)])
    bbox = bbox.union(BBox.from_coords([(69.2, 173.6)]))
    assert bbox.west == 173.6
    assert bbox.south == 63.7
    assert bbox.east == -167.3
    assert bbox.north == 69.2

    # Add a far western point in Europe.
    bbox = bbox.union(BBox.from_coords([(59.8, 26.0)]))
    assert bbox.west == 26.0
    assert bbox.south == 59.8
    assert bbox.east == -167.3
    assert bbox.north == 69.2

    # Add the embassy in London. We should continue to wrap to the west.
    bbox = bbox.union(BBox.from_coords([(51.5, -0.1)]))
    assert bbox.west == -0.1
    assert bbox.south == 51.5
    assert bbox.east == -167.3
    assert bbox.north == 69.2

    # Add the embassy in Washington. We should continue to wrap to the west.
    # The BBox is now wrapping more than halfway around the world, but includes
    # all previous bboxes. Our eastern edge hasn't gotten confused.
    bbox = bbox.union(BBox.from_coords([(38.9, -77.0)]))
    assert bbox.west == -77.0
    assert bbox.south == 38.9
    assert bbox.east == -167.3
    assert bbox.north == 69.2
Exemple #2
0
def test_bbox_from_coords():
    a = AffectedArea()
    coords = [
        (43.9493, -73.2548),  # SW corner
        (43.997, -73.0),  # middle, east
        (43.95, -73.10),  # middle
        (44.0461, -73.20),  # north, middle.
    ]
    a.record_affected(BBox.from_coords(coords))

    b = a.get_affected_bbox()
    assert b.west == -73.2548, "West should be equal"
    assert b.south == 43.9493, "South should be equal"
    assert b.east == -73.0, "East should be equal"
    assert b.north == 44.0461, "North should be equal"

    tiles = a.get_affected_tiles(max_zoom=9, min_zoom=3)
    expected_tiles = {
        Tile(x=151, y=186, z=9),
        Tile(x=152, y=186, z=9),
        Tile(x=75, y=93, z=8),
        Tile(x=76, y=93, z=8),
        Tile(x=37, y=46, z=7),
        Tile(x=38, y=46, z=7),
        Tile(x=18, y=23, z=6),
        Tile(x=19, y=23, z=6),
        Tile(x=9, y=11, z=5),
        Tile(x=4, y=5, z=4),
        Tile(x=2, y=2, z=3)
    }
    assert tiles == expected_tiles
Exemple #3
0
def test_bbox_from_coords_performance():
    coords = [
        (43.9493, -73.2548),  # SW corner
        (43.997, -73.0),  # middle, east
        (43.95, -73.10),  # middle
        (44.0461, -73.20),  # north, middle.
    ]
    for i in range(0, 10000):
        coords.append((43.95, -73.10))
    start_time = time.time()
    bbox = BBox.from_coords(coords)
    elapsed = time.time() - start_time
    assert elapsed < 0.1, "Creating a 10,000 coord bbox should take less than 0.1 seconds"
Exemple #4
0
def test_bbox_round_trip_through_geojson():
    coords = [
        (43.9493, -73.2548),  # SW corner
        (43.997, -73.0),  # middle, east
        (43.95, -73.10),  # middle
        (44.0461, -73.20),  # north, middle.
    ]
    bbox = BBox.from_coords(coords)
    geojson = bbox.as_geojson_string()

    new_bbox = BBox.from_geojson_string(geojson)
    assert new_bbox.west == -73.2548, "West should be equal"
    assert new_bbox.south == 43.9493, "South should be equal"
    assert new_bbox.east == -73.0, "East should be equal"
    assert new_bbox.north == 44.0461, "North should be equal"

    new_geojson = new_bbox.as_geojson_string()
    assert geojson == new_geojson