Metrics¶
Measure spherical distances, areas, edge lengths, and grid size.
great_circle_distance¶
plh3.great_circle_distance(
s_lat_deg: IntoExprColumn,
s_lng_deg: IntoExprColumn,
e_lat_deg: IntoExprColumn,
e_lng_deg: IntoExprColumn,
unit: Literal["km", "m"] = "km",
) -> pl.Expr
Return the spherical distance between two latitude-longitude pairs.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame(
{
"start_lat": [37.7749],
"start_lng": [-122.4194],
"end_lat": [40.7128],
"end_lng": [-74.0060],
}
)
df.select(
distance_km=plh3.great_circle_distance(
"start_lat", "start_lng", "end_lat", "end_lng"
)
)
shape: (1, 1)
┌─────────────┐
│ distance_km │
│ --- │
│ f64 │
╞═════════════╡
│ 4130.382378 │
└─────────────┘
average_hexagon_area¶
plh3.average_hexagon_area(
resolution: IntoExprColumn,
unit: Literal["km^2", "m^2"] = "km^2",
) -> pl.Expr
Return the average area of a hexagon at each resolution.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame({"resolution": [5]})
df.select(area_km2=plh3.average_hexagon_area("resolution"))
shape: (1, 1)
┌────────────┐
│ area_km2 │
│ --- │
│ f64 │
╞════════════╡
│ 252.903858 │
└────────────┘
cell_area¶
Return the spherical area of each cell.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame(
{"cell": [599686042433355775]},
schema_overrides={"cell": pl.UInt64},
)
df.select(area_km2=plh3.cell_area("cell"))
shape: (1, 1)
┌────────────┐
│ area_km2 │
│ --- │
│ f64 │
╞════════════╡
│ 265.092558 │
└────────────┘
edge_length¶
Return the spherical length of each directed edge.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame(
{"edge": [1608492358964346879]},
schema_overrides={"edge": pl.UInt64},
)
df.select(length_km=plh3.edge_length("edge"))
average_hexagon_edge_length¶
plh3.average_hexagon_edge_length(
resolution: IntoExprColumn,
unit: Literal["km", "m"] = "km",
) -> pl.Expr
Return the average edge length of a hexagon at each resolution.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame({"resolution": [5]})
df.select(length_km=plh3.average_hexagon_edge_length("resolution"))
get_num_cells¶
Return the number of H3 cells at each resolution.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame({"resolution": [5]})
df.select(cells=plh3.get_num_cells("resolution"))
get_pentagons¶
Return the 12 pentagons at each resolution.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame({"resolution": [5]})
df.select(pentagons=plh3.get_pentagons("resolution"))
shape: (1, 1)
┌───────────────────────────┐
│ pentagons │
│ --- │
│ list[u64] │
╞═══════════════════════════╡
│ [599119489002373119, 599… │
└───────────────────────────┘
Units
Distance functions accept "km" or "m". Area functions accept "km^2"
or "m^2".