Skip to content

Commit

Permalink
Update generate_example to include geometry_bbox parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jwass committed Nov 27, 2023
1 parent 0882e85 commit e74af7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Binary file modified examples/example.parquet
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/example_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
},
"edges": "planar",
"encoding": "WKB",
"geometry_bbox": {
"column": "bbox"
},
"geometry_types": [
"Polygon",
"MultiPolygon"
Expand Down
15 changes: 11 additions & 4 deletions scripts/generate_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
>>> import json, pprint, pyarrow.parquet as pq
>>> pprint.pprint(json.loads(pq.read_schema("example.parquet").metadata[b"geo"]))
"""
from collections import OrderedDict
import json
import pathlib

Expand All @@ -19,6 +20,14 @@

df = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
df = df.to_crs("ogc:84")

geometry_bbox = df.bounds.rename(
OrderedDict(
[("minx", "xmin"), ("miny", "ymin"), ("maxx", "xmax"), ("maxy", "ymax")]
),
axis=1,
)
df["bbox"] = geometry_bbox.to_dict("records")
table = pa.Table.from_pandas(df.head().to_wkb())


Expand All @@ -39,14 +48,12 @@ def get_version() -> str:
"crs": json.loads(df.crs.to_json()),
"edges": "planar",
"bbox": [round(x, 4) for x in df.total_bounds],
"geometry_bbox": {"column": "bbox"},
},
},
}

schema = (
table.schema
.with_metadata({"geo": json.dumps(metadata)})
)
schema = table.schema.with_metadata({"geo": json.dumps(metadata)})
table = table.cast(schema)

pq.write_table(table, HERE / "../examples/example.parquet")

0 comments on commit e74af7d

Please sign in to comment.