# install.packages(c("duckdb"))library(DBI)library(duckdb)con <-dbConnect(duckdb())# Enable spatial operationsdbExecute(con, "INSTALL spatial;")dbExecute(con, "LOAD spatial;")# AWS connectiondbExecute(con, "INSTALL httpfs;")dbExecute(con, "LOAD httpfs;")# Anonymous access to a public S3 bucketdbExecute(con, " CREATE SECRET ( TYPE s3, PROVIDER config, REGION 'us-west-2' )")
s3_path <-"s3://mappingafrica/croplands/geoparquet/zambia_2024_v4.parquet"system.time({ result <-dbGetQuery(con, sprintf(" SELECT COUNT(*) AS n_fields FROM read_parquet('%s') ", s3_path))})district_wkt <- districts %>%slice(48) %>%st_geometry() %>%st_as_text()dbGetQuery(con, sprintf(" SELECT COUNT(*) AS n_fields FROM read_parquet('%s') AS f WHERE ST_Intersects( f.geometry, ST_GeomFromText('%s') )", s3_path, district_wkt))