How to use the uszipcode.packages.haversine.great_circle function in uszipcode

To help you get started, we’ve selected a few uszipcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_search_by_coordinate(self):
        with ZipcodeSearchEngine() as search:
            # 在马里兰选一个坐标, 返回1000条, 但实际上不到1000条
            lat, lng = 39.114407, -77.205758

            # 返回的结果必须按照距离是从小到大的
            res1 = search.by_coordinate(lat, lng, ascending=True, returns=1000)
            len(res1) < 1000
            dist_array = [
                great_circle((lat, lng), (z.Latitude, z.Longitude), miles=True) for z in res1]
            is_all_ascending(dist_array)

            res2 = search.by_coordinate(
                lat, lng, ascending=False, returns=1000)
            dist_array = [
                great_circle((lat, lng), (z.Latitude, z.Longitude), miles=True) for z in res2]
            is_all_descending(dist_array)

            # 当returns = 0时, 返回所有符合条件的
            res3 = search.by_coordinate(lat, lng, returns=0)
            assert len(res1) == len(res3)

            # 当没有符合条件的zipcode时, 返回空列表
            res3 = search.by_coordinate(lat, lng, radius=-1)
            assert len(res3) == 0
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
assert z.Zipcode.startswith("95")
            is_all_descending([z.HouseOfUnits for z in res])

            # Find top 10 richest zipcode near Silicon Valley
            lat, lng = 37.391184, -122.082235
            radius = 100
            res = search.find(
                lat=lat,
                lng=lng,
                radius=radius,
                sort_by="Wealthy", ascending=False,
                returns=10,
            )
            assert len(res) == 10
            for z in res:
                assert great_circle(
                    (lat, lng), (z.Latitude, z.Longitude)) <= radius
            is_all_descending([z.Wealthy for z in res])

            # Find zipcode that average personal annual income greater than
            # 100000 near Silicon Valley, order by distance
            lat, lng = 37.391184, -122.082235
            radius = 100
            res = search.find(
                lat=lat,
                lng=lng,
                radius=radius,
                wealthy_lower=60000,
                sort_by=None,
                returns=0,
            )
            assert len(res) > 5
github MacHu-GWU / uszipcode-project / tests / test_haversine.py View on Github external
def test_all():
    lyon = (45.7597, 4.8422)
    paris = (48.8567, 2.3508)

    delta = 0.01
    assert abs(great_circle(lyon, paris, miles=False)/392.001248 - 1.0) <= delta
    assert abs(great_circle(lyon, paris, miles=True)/243.589575 - 1.0) <= delta