Skip to content

Commit 49f678f

Browse files
authored
Write to Parquet with GeoParquet 1.1 metadata (#40)
* Write to Parquet with GeoParquet 1.1 metadata
1 parent 5ed701e commit 49f678f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module = [
6969
"pandas.*",
7070
"pyarrow.*",
7171
"pypgstac.*",
72+
"pyproj.*",
7273
"rich.*",
7374
"shapely.*",
7475
"tqdm.*",
@@ -78,4 +79,4 @@ ignore_missing_imports = true
7879

7980
[[tool.mypy.overrides]]
8081
module = "stac_geoparquet.*"
81-
disallow_untyped_defs = true
82+
disallow_untyped_defs = true

stac_geoparquet/to_parquet.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
from typing import Any
3+
4+
import pyarrow as pa
5+
import pyarrow.parquet as pq
6+
from pyproj import CRS
7+
8+
WGS84_CRS_JSON = CRS.from_epsg(4326).to_json_dict()
9+
10+
11+
def to_parquet(table: pa.Table, where: Any, **kwargs: Any) -> None:
12+
"""Write an Arrow table with STAC data to GeoParquet
13+
14+
This writes metadata compliant with GeoParquet 1.1.
15+
16+
Args:
17+
table: The table to write to Parquet
18+
where: The destination for saving.
19+
"""
20+
# TODO: include bbox of geometries
21+
column_meta = {
22+
"encoding": "WKB",
23+
# TODO: specify known geometry types
24+
"geometry_types": [],
25+
"crs": WGS84_CRS_JSON,
26+
"edges": "planar",
27+
"covering": {
28+
"bbox": {
29+
"xmin": ["bbox", "xmin"],
30+
"ymin": ["bbox", "ymin"],
31+
"xmax": ["bbox", "xmax"],
32+
"ymax": ["bbox", "ymax"],
33+
}
34+
},
35+
}
36+
geo_meta = {
37+
"version": "1.1.0-dev",
38+
"columns": {"geometry": column_meta},
39+
"primary_column": "geometry",
40+
}
41+
42+
metadata = table.schema.metadata or {}
43+
metadata.update({b"geo": json.dumps(geo_meta).encode("utf-8")})
44+
table = table.replace_schema_metadata(metadata)
45+
46+
pq.write_table(table, where, **kwargs)

0 commit comments

Comments
 (0)