Example #1
0
    def test_check_validity(self):
        exception_raised = False
        try:
            pgh.geohash_approximate_distance('shibu', 'shiba', check_validity=True)
        except ValueError:
            exception_raised = True

        self.assertTrue(exception_raised)
Example #2
0
    def test_distance(self):
        # test the fast geohash distance approximations
        self.assertEqual(pgh.geohash_approximate_distance('bcd3u', 'bc83n'), 625441)
        self.assertEqual(pgh.geohash_approximate_distance('bcd3uasd', 'bcd3n'), 19545)
        self.assertEqual(pgh.geohash_approximate_distance('bcd3u', 'bcd3uasd'), 3803)
        self.assertEqual(pgh.geohash_approximate_distance('bcd3ua', 'bcd3uasdub'), 610)

        # test the haversine great circle distance calculations
        self.assertAlmostEqual(pgh.geohash_haversine_distance('testxyz', 'testwxy'), 6339.483649071294, places=4)
Example #3
0
    def test_check_validity(self):
        exception_raised = False
        try:
            pgh.geohash_approximate_distance('shibu',
                                             'shiba',
                                             check_validity=True)
        except ValueError:
            exception_raised = True

        self.assertTrue(exception_raised)
Example #4
0
    def test_distance(self):
        # test the fast geohash distance approximations
        self.assertEqual(pgh.geohash_approximate_distance('bcd3u', 'bc83n'),
                         625441)
        self.assertEqual(pgh.geohash_approximate_distance('bcd3uasd', 'bcd3n'),
                         19545)
        self.assertEqual(pgh.geohash_approximate_distance('bcd3u', 'bcd3uasd'),
                         3803)
        self.assertEqual(
            pgh.geohash_approximate_distance('bcd3ua', 'bcd3uasdub'), 610)

        # test the haversine great circle distance calculations
        self.assertAlmostEqual(pgh.geohash_haversine_distance(
            'testxyz', 'testwxy'),
                               6339.483649071294,
                               places=4)
Example #5
0
def calculateDistance(route):
    distance = 0
    for i, j in pairwise(route['gp']):
        if i and j:
            calc = round(pgh.geohash_approximate_distance(i, j) / 1000)
            distance = distance + calc
    return distance
Location: 
    - Categorized Long/Lat


    https://datascience.stackexchange.com/questions/13567/ways-to-deal-with-longitude-latitude-feature
    https://datascience.stackexchange.com/questions/23651/can-gps-coordinates-latitude-and-longitude-be-used-as-features-in-a-linear-mod
    - GeoHash: 
            http://www.movable-type.co.uk/scripts/geohash.html
'''

#Create Geohash for train
import pygeohash as pgh

Train_start_geohash = [pgh.encode(x,y) for x,y in zip(Trainlat1, Trainlon1)]
Train_end_geohash = [pgh.encode(x,y) for x,y in zip(Trainlat2, Trainlon2)]
Train_geodistance = [pgh.geohash_approximate_distance(x,y) for x,y in zip(Train_start_geohash, Train_end_geohash)]

len(Train_start_geohash) #12905715
len(set(Train_start_geohash)) #9753342
len(Train_end_geohash) #12905715
len(set(Train_end_geohash)) #10832199

len(Train_geodistance) #12905715
len(set(Train_geodistance)) #9  


start_geohash_TrainDF = pd.DataFrame({'start_geohash': Train_start_geohash})
end_geohash_TrainDF = pd.DataFrame({'end_geohash': Train_end_geohash})
geodistance_TrainDF = pd.DataFrame({'geoDist': Train_geodistance})

Train = pd.concat([Train, geodistance_TrainDF], axis=1)
Example #7
0
def approx_dist(a_lat, a_long, b_lat, b_long):
    a = pgh.encode(a_lat, a_long)
    b = pgh.encode(b_lat, b_long)
    return pgh.geohash_approximate_distance(a, b) / 1000
Example #8
0
Location: 
    - Categorized Long/Lat
    - IsBusyLocation(start/end), 

    https://datascience.stackexchange.com/questions/13567/ways-to-deal-with-longitude-latitude-feature
    https://datascience.stackexchange.com/questions/23651/can-gps-coordinates-latitude-and-longitude-be-used-as-features-in-a-linear-mod
    - GeoHash: 
            http://www.movable-type.co.uk/scripts/geohash.html
'''

#Create Geohash for train
import pygeohash as pgh

Train_start_geohash = [pgh.encode(x,y) for x,y in zip(Trainlat1, Trainlon1)]
Train_end_geohash = [pgh.encode(x,y) for x,y in zip(Trainlat2, Trainlon2)]
Train_geodistance = [pgh.geohash_approximate_distance(x,y) for x,y in zip(Train_start_geohash, Train_end_geohash)]

len(Train_start_geohash) #12905715
len(set(Train_start_geohash)) #9753342
len(Train_end_geohash) #12905715
len(set(Train_end_geohash)) #10832199

len(Train_geodistance) #12905715
len(set(Train_geodistance)) #9  


start_geohash_TrainDF = pd.DataFrame({'start_geohash': Train_start_geohash})
end_geohash_TrainDF = pd.DataFrame({'end_geohash': Train_end_geohash})
geodistance_TrainDF = pd.DataFrame({'geoDist': Train_geodistance})

Train = pd.concat([Train, geodistance_TrainDF], axis=1)