04 rhealpix
rHEALPixPandas key features¶
You can try out vgridpandas by using the cloud-computing platforms below without having to install anything on your computer:
Install vgridpandas¶
In [1]:
Copied!
# %pip install vgridpandas
# %pip install vgridpandas
Latlong to rHEALPix¶
In [2]:
Copied!
import pandas as pd
from vgridpandas import rhealpixpandas
df = pd.read_csv('https://github.com/uber-web/kepler.gl-data/raw/master/nyctrips/data.csv')
df = df.head(100)
df = df.rename({'pickup_longitude': 'lon', 'pickup_latitude': 'lat'}, axis=1)[['lon', 'lat', 'passenger_count']]
resolution = 11
df = df.rhealpix.latlon2rhealpix(resolution)
df.head()
import pandas as pd
from vgridpandas import rhealpixpandas
df = pd.read_csv('https://github.com/uber-web/kepler.gl-data/raw/master/nyctrips/data.csv')
df = df.head(100)
df = df.rename({'pickup_longitude': 'lon', 'pickup_latitude': 'lat'}, axis=1)[['lon', 'lat', 'passenger_count']]
resolution = 11
df = df.rhealpix.latlon2rhealpix(resolution)
df.head()
Out[2]:
lon | lat | passenger_count | rhealpix_res | |
---|---|---|---|---|
rhealpix | ||||
P01127645811 | -73.993896 | 40.750111 | 1 | 11 |
P01127657310 | -73.976425 | 40.739811 | 1 | 11 |
P01127654506 | -73.968704 | 40.754246 | 5 | 11 |
P01127750407 | -73.863060 | 40.769581 | 5 | 11 |
P01127706706 | -73.945541 | 40.779423 | 1 | 11 |
rHEALPix to geo boundary¶
In [3]:
Copied!
df = df.rhealpix.rhealpix2geo()
df.head()
df = df.rhealpix.rhealpix2geo()
df.head()
Out[3]:
lon | lat | passenger_count | rhealpix_res | geometry | |
---|---|---|---|---|---|
rhealpix | |||||
P01127645811 | -73.993896 | 40.750111 | 1 | 11 | POLYGON ((-73.99431 40.75041, -73.9938 40.7504... |
P01127657310 | -73.976425 | 40.739811 | 1 | 11 | POLYGON ((-73.97653 40.74018, -73.97602 40.740... |
P01127654506 | -73.968704 | 40.754246 | 5 | 11 | POLYGON ((-73.96891 40.75439, -73.9684 40.7543... |
P01127750407 | -73.863060 | 40.769581 | 5 | 11 | POLYGON ((-73.86323 40.76975, -73.86272 40.769... |
P01127706706 | -73.945541 | 40.779423 | 1 | 11 | POLYGON ((-73.94604 40.77998, -73.94554 40.779... |
(Multi)Linestring/ (Multi)Polygon to rHEALPix¶
In [4]:
Copied!
from vgridpandas import rhealpixpandas
import geopandas as gpd
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 11
gdf_polyfill = gdf.rhealpix.polyfill(resolution, compact = True, predicate = "intersects", explode = False)
gdf_polyfill.head()
gdf_polyfill = gdf_polyfill.rhealpix.rhealpix2geo("rhealpix")
gdf_polyfill.plot(edgecolor = "white")
from vgridpandas import rhealpixpandas
import geopandas as gpd
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 11
gdf_polyfill = gdf.rhealpix.polyfill(resolution, compact = True, predicate = "intersects", explode = False)
gdf_polyfill.head()
gdf_polyfill = gdf_polyfill.rhealpix.rhealpix2geo("rhealpix")
gdf_polyfill.plot(edgecolor = "white")
Out[4]:
<Axes: >
rHEALPix point binning¶
In [5]:
Copied!
import pandas as pd
import geopandas as gpd
from vgridpandas import rhealpixpandas
resolution = 10
df = pd.read_csv("https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/csv/dist1_pois.csv")
# df = gpd.read_file("https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/dist1_pois.geojson")
df.head()
stats = "count"
df_bin = df.rhealpix.rhealpixbin(resolution=resolution, stats = stats,
# numeric_column="confidence",
# category_column="category",
return_geometry=True)
df_bin.plot(
column=stats, # numeric column to base the colors on
cmap='Spectral_r', # color scheme (matplotlib colormap)
legend=True,
linewidth=0.2 # boundary width (optional)
)
import pandas as pd
import geopandas as gpd
from vgridpandas import rhealpixpandas
resolution = 10
df = pd.read_csv("https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/csv/dist1_pois.csv")
# df = gpd.read_file("https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/dist1_pois.geojson")
df.head()
stats = "count"
df_bin = df.rhealpix.rhealpixbin(resolution=resolution, stats = stats,
# numeric_column="confidence",
# category_column="category",
return_geometry=True)
df_bin.plot(
column=stats, # numeric column to base the colors on
cmap='Spectral_r', # color scheme (matplotlib colormap)
legend=True,
linewidth=0.2 # boundary width (optional)
)
Out[5]:
<Axes: >