08 olc
OLCPandas 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 OLC¶
In [2]:
Copied!
import pandas as pd
from vgridpandas import olcpandas
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 = 10
df = df.olc.latlon2olc(resolution)
df.head()
import pandas as pd
from vgridpandas import olcpandas
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 = 10
df = df.olc.latlon2olc(resolution)
df.head()
Out[2]:
lon | lat | passenger_count | olc_res | |
---|---|---|---|---|
olc | ||||
87G8Q224+2C | -73.993896 | 40.750111 | 1 | 10 |
87G8P2QF+WC | -73.976425 | 40.739811 | 1 | 10 |
87G8Q23J+MG | -73.968704 | 40.754246 | 5 | 10 |
87G8Q49P+RQ | -73.863060 | 40.769581 | 5 | 10 |
87G8Q3H3+QQ | -73.945541 | 40.779423 | 1 | 10 |
OLC to geo boundary¶
In [3]:
Copied!
df = df.olc.olc2geo()
df.head()
df = df.olc.olc2geo()
df.head()
Out[3]:
lon | lat | passenger_count | olc_res | geometry | |
---|---|---|---|---|---|
olc | |||||
87G8Q224+2C | -73.993896 | 40.750111 | 1 | 10 | POLYGON ((-73.994 40.75, -73.99388 40.75, -73.... |
87G8P2QF+WC | -73.976425 | 40.739811 | 1 | 10 | POLYGON ((-73.9765 40.73975, -73.97638 40.7397... |
87G8Q23J+MG | -73.968704 | 40.754246 | 5 | 10 | POLYGON ((-73.96875 40.75412, -73.96862 40.754... |
87G8Q49P+RQ | -73.863060 | 40.769581 | 5 | 10 | POLYGON ((-73.86312 40.7695, -73.863 40.7695, ... |
87G8Q3H3+QQ | -73.945541 | 40.779423 | 1 | 10 | POLYGON ((-73.94562 40.77938, -73.9455 40.7793... |
(Multi)Linestring/ (Multi)Polygon to OLC¶
In [4]:
Copied!
import geopandas as gpd
from vgridpandas import olcpandas
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 8
gdf_polyfill = gdf.olc.polyfill(resolution, predicate = "intersects", compact = False)
gdf_polyfill.head()
gdf_polyfill = gdf_polyfill.olc.olc2geo(olc_column = "olc")
gdf_polyfill.plot(edgecolor = "white")
import geopandas as gpd
from vgridpandas import olcpandas
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 8
gdf_polyfill = gdf.olc.polyfill(resolution, predicate = "intersects", compact = False)
gdf_polyfill.head()
gdf_polyfill = gdf_polyfill.olc.olc2geo(olc_column = "olc")
gdf_polyfill.plot(edgecolor = "white")
Out[4]:
<Axes: >
OLC point binning¶
In [5]:
Copied!
from vgridpandas import olcpandas
# 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")
resolution = 8
stats = "count"
df_bin = df.olc.olcbin(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)
)
from vgridpandas import olcpandas
# 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")
resolution = 8
stats = "count"
df_bin = df.olc.olcbin(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: >