Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XqsmB8BBnudp4djsjWpk11
74 lines
3.5 KiB
YAML
74 lines
3.5 KiB
YAML
name: Convert BeST addresses
|
|
run-name: Convert BeST addresses to csv (${{ gitea.ref_name }})
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
tags:
|
|
- '**'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
env:
|
|
GPKG: ca0fd5c0-8146-11e9-9012-482ae30f98d9_geopackage+sqlite3_3812.gpkg
|
|
SOURCE_URL: https://ac.ngi.be/remoteclient-open/GeoBePartners-open/BOSA/ca0fd5c0-8146-11e9-9012-482ae30f98d9_geopackage+sqlite3_3812.zip
|
|
SELECT: SELECT shape AS geom, id, best_id, coalesce(streetname_fr, streetname_nl, streetname_de) AS streetname, postal_info_objectid, municipality_objectid, COALESCE(municipality_fr, municipality_nl, municipality_de) AS municipality, housenumber, boxnumber
|
|
|
|
jobs:
|
|
convert:
|
|
runs-on: cth-ubuntu-latest
|
|
steps:
|
|
- name: install dependencies
|
|
run: |
|
|
apt-get update
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gdal-bin unzip curl ca-certificates
|
|
ogr2ogr --version
|
|
|
|
- name: download
|
|
run: curl --fail --location --silent --show-error --output bestaddresses.zip "$SOURCE_URL"
|
|
|
|
- name: convert
|
|
run: |
|
|
set -eu
|
|
unzip -o bestaddresses.zip
|
|
rm bestaddresses.zip
|
|
ogrinfo "$GPKG" -sql "CREATE INDEX idx_postal_code ON addresses_complete (postal_info_objectid) WHERE status NOT LIKE 'retired'"
|
|
ogr2ogr -sql "select St_Centroid(St_Envelope(St_Collect(shape))) AS center, COALESCE(municipality_fr, municipality_nl, municipality_de) AS municipality_name, postal_info_objectid, municipality_objectid FROM addresses_complete where fid % 10 = 1 AND status NOT LIKE 'retired' GROUP BY COALESCE(municipality_fr, municipality_nl, municipality_de), postal_info_objectid, municipality_objectid" -lco GEOMETRY=AS_XY postals.fr.csv "$GPKG"
|
|
ogr2ogr -sql "$SELECT FROM addresses_complete WHERE status NOT LIKE 'retired' LIMIT 10000" -lco GEOMETRY=AS_XY addresses-extract.fr.csv "$GPKG"
|
|
ogr2ogr -sql "$SELECT FROM addresses_complete WHERE status NOT LIKE 'retired'" -lco GEOMETRY=AS_XY addresses-full.fr.csv "$GPKG"
|
|
for i in 1 2 3 4 5 6 7 8 9; do
|
|
ogr2ogr -sql "$SELECT FROM addresses_complete WHERE postal_info_objectid LIKE '${i}%' AND status NOT LIKE 'retired'" -lco GEOMETRY=AS_XY "addresses-${i}xxx.fr.csv" "$GPKG"
|
|
done
|
|
rm "$GPKG"
|
|
gzip -9 *.csv
|
|
ls -lh *.fr.csv.gz
|
|
|
|
- name: upload to generic package registry
|
|
env:
|
|
TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
|
|
PACKAGE_URL: ${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/addresses/v1.1.1
|
|
run: |
|
|
set -eu
|
|
for f in *.fr.csv.gz; do
|
|
# gitea refuses to overwrite an existing file (409): delete it first, ignore 404
|
|
status=$(curl --silent --output /dev/null --write-out '%{http_code}' -X DELETE -H "Authorization: token $TOKEN" "$PACKAGE_URL/$f")
|
|
echo "DELETE $f: $status"
|
|
curl --fail-with-body --silent --show-error -H "Authorization: token $TOKEN" --upload-file "$f" "$PACKAGE_URL/$f"
|
|
echo "PUT $f: ok"
|
|
done
|
|
|
|
- name: gitea release
|
|
if: gitea.ref_type == 'tag'
|
|
uses: https://github.com/akkuman/gitea-release-action@v1
|
|
with:
|
|
server_url: https://gitea.champs-libres.be
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
name: ${{ gitea.ref_name }}
|
|
tag_name: ${{ gitea.ref_name }}
|
|
files: |-
|
|
*.fr.csv.gz
|