Skip to content

Commit b59c95f

Browse files
authored
Cleaner data repro for point and polygon examples (#45)
* Point example data repro * repro for polygon data
1 parent a4c143f commit b59c95f

File tree

9 files changed

+3207
-62
lines changed

9 files changed

+3207
-62
lines changed

examples/point/README.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
todo: try portal again (had issue with mismatched deck.gl versions)
2-
3-
```json
4-
"@geoarrow/deck.gl-layers": "portal:../../modules/deck.gl-geoarrow",
5-
```
6-
7-
8-
9-
10-
11-
12-
13-
14-
1+
## Example: Use `@geoarrow/deck.gl-layers` with GeoArrow point data
152

3+
## Data for example:
164

5+
```
6+
wget https://ookla-open-data.s3.us-west-2.amazonaws.com/parquet/performance/type=mobile/year=2019/quarter=1/2019-01-01_performance_mobile_tiles.parquet
7+
poetry install
8+
poetry run python generate_data.py
9+
```
1710

18-
## Example: Use deck.gl with react-map-gl and Webpack
11+
## Serve data
1912

20-
Uses [Vite](https://vitejs.dev/) to bundle and serve files.
13+
```
14+
npx http-server --cors
15+
```
2116

2217
## Usage
2318

@@ -30,9 +25,6 @@ yarn
3025
```
3126

3227
Commands:
28+
3329
* `npm start` is the development target, to serve the app and hot reload.
3430
* `npm run build` is the production target, to create the final bundle and write to disk.
35-
36-
### Basemap
37-
38-
The basemap in this example is provided by [CARTO free basemap service](https://carto.com/basemaps). To use an alternative base map solution, visit [this guide](https://deck.gl/docs/get-started/using-with-map#using-other-basemap-services)

examples/point/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GeoArrowScatterplotLayer } from "@geoarrow/deck.gl-layers";
66
import * as arrow from "apache-arrow";
77

88
const GEOARROW_POINT_DATA =
9-
"http://localhost:8080/2019-01-01_performance_mobile_tiles_color.feather";
9+
"http://localhost:8080/2019-01-01_performance_mobile_tiles.feather";
1010

1111
const INITIAL_VIEW_STATE = {
1212
latitude: 20,
@@ -57,8 +57,8 @@ function Root() {
5757
new GeoArrowScatterplotLayer({
5858
id: "geoarrow-points",
5959
data: table,
60-
getFillColor: [255, 0, 0],
61-
// getFillColor: "colors",
60+
// getFillColor: [255, 0, 0],
61+
getFillColor: table.getChild("colors"),
6262
radiusMinPixels: 1,
6363
getPointRadius: 10,
6464
pointRadiusMinPixels: 0.8,

examples/point/generate_data.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1+
from pathlib import Path
2+
3+
import geopandas as gpd
14
import pandas as pd
25
import pyarrow as pa
36
import pyarrow.feather as feather
47
import shapely
8+
from lonboard.colormap import apply_continuous_cmap
9+
from lonboard.geoarrow.geopandas_interop import geopandas_to_geoarrow
10+
from palettable.colorbrewer.diverging import BrBG_10
511

12+
url = "https://ookla-open-data.s3.us-west-2.amazonaws.com/parquet/performance/type=mobile/year=2019/quarter=1/2019-01-01_performance_mobile_tiles.parquet"
613

7-
class PointGeometryType(pa.ExtensionType):
8-
def __init__(self):
9-
pa.ExtensionType.__init__(self, self._storage_type, self._extension_name)
10-
11-
_storage_type = pa.list_(pa.field("xy", pa.float64()), 2)
12-
_extension_name = "geoarrow.point"
13-
14-
def __arrow_ext_serialize__(self):
15-
# since we don't have a parameterized type, we don't need extra
16-
# metadata to be deserialized
17-
return b""
18-
19-
@classmethod
20-
def __arrow_ext_deserialize__(cls, storage_type, serialized):
21-
# return an instance of this subclass given the serialized
22-
# metadata.
23-
return PointGeometryType()
24-
25-
26-
# https://ookla-open-data.s3.us-west-2.amazonaws.com/parquet/performance/type=mobile/year=2019/quarter=1/2019-01-01_performance_mobile_tiles.parquet
14+
path = Path("2019-01-01_performance_mobile_tiles.parquet")
2715

2816

2917
def main():
30-
df = pd.read_parquet("2019-01-01_performance_mobile_tiles.parquet")
18+
if not path.exists():
19+
msg = f"Please download file to this directory from {url=}."
20+
raise ValueError(msg)
21+
22+
df = pd.read_parquet(path)
3123
centroids = shapely.centroid(shapely.from_wkt(df["tile"]))
3224

3325
# Save space by using a smaller data type
3426
df_cols = ["avg_d_kbps", "avg_u_kbps", "avg_lat_ms"]
3527
for col in df_cols:
3628
df[col] = pd.to_numeric(df[col], downcast="unsigned")
3729

38-
table = pa.Table.from_pandas(df[df_cols])
39-
coords = shapely.get_coordinates(centroids)
40-
parr = pa.FixedSizeListArray.from_arrays(coords.flatten(), 2)
41-
extension_arr = pa.ExtensionArray.from_storage(PointGeometryType(), parr)
42-
table = table.append_column("geometry", extension_arr)
30+
gdf = gpd.GeoDataFrame(df[df_cols], geometry=centroids)
31+
table = geopandas_to_geoarrow(gdf, preserve_index=False)
32+
33+
min_bound = 5000
34+
max_bound = 50000
35+
download_speed = gdf["avg_d_kbps"]
36+
normalized_download_speed = (download_speed - min_bound) / (max_bound - min_bound)
37+
38+
colors = apply_continuous_cmap(normalized_download_speed, BrBG_10)
39+
table = table.append_column(
40+
"colors", pa.FixedSizeListArray.from_arrays(colors.flatten("C"), 3)
41+
)
42+
4343
feather.write_feather(
4444
table, "2019-01-01_performance_mobile_tiles.feather", compression="uncompressed"
4545
)

0 commit comments

Comments
 (0)