Exemplo n.º 1
0
 def test_h3_distance(self):
     self.assertEqual(0, h3.h3_distance('89283082993ffff',
                                        '89283082993ffff'))
     self.assertEqual(1, h3.h3_distance('89283082993ffff',
                                        '8928308299bffff'))
     self.assertEqual(5, h3.h3_distance('89283082993ffff',
                                        '89283082827ffff'))
Exemplo n.º 2
0
def geo_hex_distance_features(df: pd.DataFrame, start_point_col: str,
                              end_point_col: str):
    """Get h3 distance between start hexagons and end hexagons

    Args:
        df - dataframe
        start_point_col (str) - start point hexagon column name
        end_point_col (str) - end point hexagon column name
    Returns:
        df - new dataframe with h3 distance column
    """
    df = df.copy()

    df[f"h3_dist_{start_point_col}_{end_point_col}"] = [
        h3.h3_distance(hexagons[0], hexagons[1])
        for hexagons in df[[f"{start_point_col}", f"{end_point_col}"]].values
    ]

    return df
Exemplo n.º 3
0
 def hex_distance(self, src_hex_id: str, dst_hex_id: str) -> int:
     """return distance from two hexagons, which are of the same resolution.
     """
     return h3.h3_distance(src_hex_id, dst_hex_id)