コード例 #1
0
ファイル: test_srtm.py プロジェクト: danni/cycle-router
def test_extract_point(grid, lat, lon):
    import json
    from cyclerouter.rk import Client

    calc = grid.extract_point(lat, lon)

    # make a request to the Google Elevation API
    client = Client()

    _, content = client.request(
        'http://maps.googleapis.com/maps/api/elevation/json',
        data=dict(locations='{},{}'.format(lat, lon),
                  sensor='false'))

    content = json.loads(content)

    assert content['status'] == 'OK'
    assert 'results' in content
    assert len(content['results']) == 1

    result = content['results'][0]
    desr = result['elevation']
    res = result['resolution']

    # assert the calculated value is within the resolution of Google's value
    assert_allclose(calc, desr, atol=res / 2)
コード例 #2
0
ファイル: test_srtm.py プロジェクト: danni/cycle-router
def test_against_google(grid):

    import json
    from cyclerouter.rk import Client

    client = Client()

    # make a request to the Google Elevation API
    _, content = client.request(
        'http://maps.googleapis.com/maps/api/elevation/json',
        data=dict(path='{},{}|{},{}'.format(grid.lats[0], grid.lons[0],
                                            grid.lats[-1], grid.lons[0]),
                  samples=100,
                  sensor='false'))

    content = json.loads(content)

    assert content['status'] == 'OK'
    assert 'results' in content

    data = np.empty(shape=(len(content['results']), 3))

    for i, rec in enumerate(content['results']):
        data[i] = [rec['location']['lat'],
                   rec['location']['lng'],
                   rec['elevation']]

    data = data.view(type=np.recarray,
                     dtype=[('lats', float),
                            ('lons', float),
                            ('elev', float)])

    fig, ax1 = plt.subplots(1, 1)

    ax1.set_title("SRTM v Google (Lon = {})".format(grid.lons[0]))
    ax1.set_xlabel("Latitude")
    ax1.plot(grid.lats, grid[:, 0])
    ax1.plot(data.lats, data.elev, 'r')
    ax1.set_xlim(-38.5, -33.5)
    ax1.set_ylim(-20, 200)

    plt.show()