-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write to Parquet with GeoParquet 1.1 metadata (#40)
* Write to Parquet with GeoParquet 1.1 metadata
- Loading branch information
1 parent
5ed701e
commit 49f678f
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
from typing import Any | ||
|
||
import pyarrow as pa | ||
import pyarrow.parquet as pq | ||
from pyproj import CRS | ||
|
||
WGS84_CRS_JSON = CRS.from_epsg(4326).to_json_dict() | ||
|
||
|
||
def to_parquet(table: pa.Table, where: Any, **kwargs: Any) -> None: | ||
"""Write an Arrow table with STAC data to GeoParquet | ||
This writes metadata compliant with GeoParquet 1.1. | ||
Args: | ||
table: The table to write to Parquet | ||
where: The destination for saving. | ||
""" | ||
# TODO: include bbox of geometries | ||
column_meta = { | ||
"encoding": "WKB", | ||
# TODO: specify known geometry types | ||
"geometry_types": [], | ||
"crs": WGS84_CRS_JSON, | ||
"edges": "planar", | ||
"covering": { | ||
"bbox": { | ||
"xmin": ["bbox", "xmin"], | ||
"ymin": ["bbox", "ymin"], | ||
"xmax": ["bbox", "xmax"], | ||
"ymax": ["bbox", "ymax"], | ||
} | ||
}, | ||
} | ||
geo_meta = { | ||
"version": "1.1.0-dev", | ||
"columns": {"geometry": column_meta}, | ||
"primary_column": "geometry", | ||
} | ||
|
||
metadata = table.schema.metadata or {} | ||
metadata.update({b"geo": json.dumps(geo_meta).encode("utf-8")}) | ||
table = table.replace_schema_metadata(metadata) | ||
|
||
pq.write_table(table, where, **kwargs) |