Rewrite a Parquet layer as GeoParquet#
Write a new GeoParquet file when a local Parquet relation contains geometry that another reader needs to interpret as geometry. This example uses the native writer’s plain XY fixture and verifies the resulting file independently.
Choose the geometry column and its metadata#
Identify the source encoding, whether coordinates are planar XY or XYZ, and the CRS justified by the input. Check the supported encodings, dimensions and CRS representations in File formats, layers and coordinate metadata.
The fixture plain-xy.parquet has a binary WKB geometry column named geom and an id attribute. Its plain binary input has no CRS, so the writer records a null CRS rather than guessing one. For an existing GeoParquet input, an omitted CRS means CRS84. A valid PROJJSON CRS is preserved verbatim.
Write a new GeoParquet file#
From the cugeo-geometry-execution crate example context, use the same native path as the live write test. Choose a fresh destination distinct from the source. The request defaults to replace=false and supplies a bounding-box covering.
use cugeo_geometry_execution::{
geoparquet_write::GeoParquetWriteRequest,
query_cli::{write_local_geoparquet, NativeQueryBootstrap},
};
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let bootstrap = NativeQueryBootstrap::from_process_env()?;
let source = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/geoparquet-write/plain-xy.parquet");
let output = PathBuf::from("/tmp/plain-xy-geoparquet.parquet");
let request = GeoParquetWriteRequest::new(&source, &output, "geom");
let (_plan, _summary) = write_local_geoparquet(&request, &bootstrap)?;
Ok(())
}
Change output to a fresh path on your system. The live test asserts that this fixture produces four rows, retains the id attribute, and records Point geometry and a null CRS.
Verify the file another reader will open#
Reopen the output with an independent Parquet reader. For example, with PyArrow installed, compare its rows with the source and inspect the GeoParquet footer.
import json
import pyarrow.parquet as pq
source = "tests/fixtures/geoparquet-write/plain-xy.parquet"
output = "/tmp/plain-xy-geoparquet.parquet"
source_table = pq.read_table(source)
output_table = pq.read_table(output)
geo = json.loads(pq.read_metadata(output).metadata[b"geo"])
column = geo["primary_column"]
metadata = geo["columns"][column]
print("geometry column:", column)
print("encoding:", metadata["encoding"])
print("geometry types:", metadata["geometry_types"])
print("CRS:", metadata.get("crs"))
print("source IDs:", source_table["id"].to_pylist())
print("output IDs:", output_table["id"].to_pylist())
assert column == "geom"
assert metadata["encoding"] == "WKB"
assert metadata["geometry_types"] == ["Point"]
assert metadata["crs"] is None
assert len(output_table) == len(source_table) == 4
assert output_table["id"].to_pylist() == source_table["id"].to_pylist()
Run this from the crate directory, and use the same destination path as the writer. The footer identifies how another reader should interpret the geometry, and the row and ID checks confirm that the fixture’s records remain present. For a spatial query and pruning check, the live test also rewrites a 180-row sample and compares the Q1 result with its oracle.