Skip to content

Instantly share code, notes, and snippets.

@marklit
Last active August 7, 2024 11:40
Show Gist options
  • Save marklit/10b17d087b9d87f3ecf1b86b12b717ee to your computer and use it in GitHub Desktop.
Save marklit/10b17d087b9d87f3ecf1b86b12b717ee to your computer and use it in GitHub Desktop.
Partition Denmark by Address
$ aws s3 --no-sign-request sync \
    s3://overturemaps-us-west-2/release/2024-07-22.0/theme=addresses/type=address/ \
    ~/addresses
$ cd ~/addresses
$ ~/duckdb
INSTALL spatial;
LOAD spatial;

INSTALL parquet;
LOAD parquet;

INSTALL lindel FROM community;
LOAD lindel;

COPY (
    WITH a AS (
        select *, row_number() OVER () as rn
        from read_parquet('*.parquet') 
        WHERE country = 'DK'
        ORDER BY morton_encode([bbox.xmin, bbox.ymin]::float[2])
    )
    SELECT round(rn / 3_918_869 * 100)::INT as batch,
           {min_x: MIN(bbox.xmin),
            min_y: MIN(bbox.ymin),
            max_x: MAX(bbox.xmax),
            max_y: MAX(bbox.ymax)}::BOX_2D::GEOMETRY AS geom
    FROM a
    GROUP BY batch
    ORDER BY ST_AREA(geom) DESC
) TO 'dk.partitions.morton.gpkg'
        WITH (FORMAT GDAL,
              DRIVER 'GPKG',
              LAYER_CREATION_OPTIONS 'WRITE_BBOX=YES');
@marklit
Copy link
Author

marklit commented Aug 7, 2024

qgis-bin_mm66WbZtE7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment