Created
July 17, 2023 10:51
-
-
Save m-mohr/dd7c603c95671d1c08956810fef95728 to your computer and use it in GitHub Desktop.
Adds geoparquet metadata to a parquet file
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
import json | |
import pyarrow.parquet as pq | |
path1 = "pf.parquet" | |
path2 = "pf.geoparquet" | |
geo_metadata = { | |
"version": "1.0.0-beta.1", | |
"primary_column": "geometry", | |
"columns": { | |
"geometry": { | |
"encoding": "WKB", | |
"geometry_types": [ | |
"Polygon" | |
], | |
"bbox": [ | |
-21.922951, | |
63.623751, | |
-18.40089, | |
65.565982 | |
] | |
} | |
} | |
} | |
table = pq.read_table(path1) | |
metadata = { | |
**(table.schema.metadata or {}), | |
b"geo": json.dumps(geo_metadata).encode(), | |
} | |
new_table = table.replace_schema_metadata(metadata) | |
pq.write_table(new_table, path2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment