07 qtm
QTMPandas 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 QTM¶
In [ ]:
Copied!
import pandas as pd
from vgridpandas import qtmpandas
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 = 16
df = df.qtm.latlon2qtm(resolution)
df.head()
import pandas as pd
from vgridpandas import qtmpandas
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 = 16
df = df.qtm.latlon2qtm(resolution)
df.head()
Out[ ]:
lon | lat | passenger_count | qtm_res | |
---|---|---|---|---|
qtm | ||||
2022030230110311 | -73.993896 | 40.750111 | 1 | 16 |
2022030230113320 | -73.976425 | 40.739811 | 1 | 16 |
2022030233221012 | -73.968704 | 40.754246 | 5 | 16 |
2022030233011022 | -73.863060 | 40.769581 | 5 | 16 |
2022030233223330 | -73.945541 | 40.779423 | 1 | 16 |
QTM to geo boundary¶
In [3]:
Copied!
df = df.qtm.qtm2geo()
df.head()
df = df.qtm.qtm2geo()
df.head()
Out[3]:
lon | lat | passenger_count | qtm_res | geometry | |
---|---|---|---|---|---|
qtm | |||||
2022030230110311 | -73.993896 | 40.750111 | 1 | 16 | POLYGON ((-73.99364 40.74829, -73.99247 40.751... |
2022030230113320 | -73.976425 | 40.739811 | 1 | 16 | POLYGON ((-73.97353 40.7373, -73.97236 40.7400... |
2022030233221012 | -73.968704 | 40.754246 | 5 | 16 | POLYGON ((-73.97144 40.75378, -73.96647 40.753... |
2022030233011022 | -73.863060 | 40.769581 | 5 | 16 | POLYGON ((-73.86128 40.76752, -73.86009 40.770... |
2022030233223330 | -73.945541 | 40.779423 | 1 | 16 | POLYGON ((-73.94594 40.7785, -73.94097 40.7785... |
(Multi)Linestring/ (Multi)Polygon to QTM¶
In [4]:
Copied!
import geopandas as gpd
from vgridpandas import qtmpandas
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 19
gdf_polyfill = gdf.qtm.polyfill(resolution, predicate = "intersects", compact = True, explode = True)
gdf_polyfill = gdf_polyfill.qtm.qtm2geo(qtm_column = "qtm")
gdf_polyfill.plot(edgecolor = "white")
import geopandas as gpd
from vgridpandas import qtmpandas
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 19
gdf_polyfill = gdf.qtm.polyfill(resolution, predicate = "intersects", compact = True, explode = True)
gdf_polyfill = gdf_polyfill.qtm.qtm2geo(qtm_column = "qtm")
gdf_polyfill.plot(edgecolor = "white")
Out[4]:
<Axes: >
QTM point binning¶
In [6]:
Copied!
import geopandas as gpd
from vgridpandas import qtmpandas
resolution = 17
# 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")
stats = "count"
df_bin = df.qtm.qtmbin(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 geopandas as gpd
from vgridpandas import qtmpandas
resolution = 17
# 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")
stats = "count"
df_bin = df.qtm.qtmbin(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[6]:
<Axes: >