Created
December 30, 2025 16:58
-
-
Save do-me/31969ba0da87438fb311336fa3253d89 to your computer and use it in GitHub Desktop.
DuckDB spatial convert normal geoparquet to lat lon
This file contains hidden or 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 duckdb | |
| con = duckdb.connect() | |
| con.execute("INSTALL spatial; LOAD spatial;") | |
| input_path = '30M_sample_index.parquet' | |
| output_path = '30M_sample_index_with_lat_lon.parquet' | |
| # Use ST_X and ST_Y directly on the 'geometry' column | |
| con.execute(f""" | |
| COPY ( | |
| SELECT | |
| ST_X(geometry) AS lon, | |
| ST_Y(geometry) AS lat, | |
| * EXCLUDE (geometry) | |
| FROM read_parquet('{input_path}') | |
| ) TO '{output_path}' (FORMAT 'parquet'); | |
| """) | |
| # To verify and load into a dataframe if needed: | |
| df = con.execute(f"SELECT * FROM '{output_path}' LIMIT 5").df() | |
| con.close() | |
| df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment