import { DuckDBClient as latestDuckClient } from "@kimmolinna/duckdb-latest/2"
function convertToGeoJSON(data) {
const features = data.map((item) => {
const geometry = JSON.parse(item.GEOJSON);
return {
type: "Feature",
geometry,
properties: {
iso_a3: item.iso_a3,
area: item.area
}
};
});
return features;
}
client = {
const con = new latestDuckClient();
await con.query(`INSTALL spatial`);
await con.query(`LOAD spatial`);
await con.insertParquet("example_parquet", parquet_array);
return con;
}
parquet_array = new Uint8Array(
await FileAttachment("example.parquet").arrayBuffer()
)
geoparquet = client.sql`
SELECT continent, iso_a3, ST_AREA(ST_GeomFromWkb(geometry)) as area , ST_AsGeoJSON(ST_GeomFromWkb(geometry)) AS GEOJSON, ST_AREA(ST_GeomFromWkb(geometry)) as area
FROM example_parquet
WHERE area > 1000`
valid_geojson = convertToGeoJSON(geoparquet)