Created
April 3, 2022 04:09
-
-
Save grischard/9b29b157a0d726cd7d24279450f5f89d to your computer and use it in GitHub Desktop.
Update trp-vc from data.public.lu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -Eeuo pipefail | |
# Don't glob | |
set -f | |
url="https://data.public.lu/fr/datasets/r/e74aadad-77c2-441e-98fe-e08a441484a2" | |
useragent="openstreetmap.lu bot" | |
outfile="transport-et-voies-de-communication-shape.zip" | |
process_download () { | |
# Save timestamp | |
date --rfc-2822 -d "@$(stat -c %Y $outfile)" > $outfile.timestamp | |
### ↓ CUSTOM IMPORT CODE HERE | |
echo "drop index if exists idx_place_osm, idx_addr_caclr, idx_alt_name_osm, idx_rue_osm" | psql osmlu | |
echo "truncate trp_vc;" | psql -d osmlu | |
unzip -o transport-et-voies-de-communication-shape.zip | |
echo "Importing trp-vc…" | |
ogr2ogr -progress -f "PostgreSQL" PG:"dbname=osmlu" -s_srs "EPSG:2169" -t_srs "EPSG:3857" TRP_VC.shp | |
# Use names from csventrifuge | |
echo "update trp_vc set nom_rue=addresses.rue from addresses where trp_vc.nom_rue not like addresses.rue and trp_vc.id_rue_cac = addresses.id_caclr_rue" | psql -d osmlu | |
# Drop garbage | |
echo "update trp_vc set nom_rue = NULL where nom_rue in ('Chalet', 'Chemin Privé', 'Ferme', 'Maison')" | psql -d osmlu | |
echo "Indexing…" | |
psql -d osmlu -qAt -f index-trp.sql | |
echo "Cleaning up…" | |
rm $outfile TRP_VC.dbf TRP_VC.prj TRP_VC.shp TRP_VC.shx | |
### ↑ CUSTOM IMPORT CODE HERE | |
} | |
if [[ -f $outfile.timestamp ]]; then | |
# not first run, ask if server file newer than timestamp | |
[[ "$(curl -z "$(cat $outfile.timestamp)" -H "User-Agent: $useragent" -s -L $url -o $outfile -w %\{http_code\})" == "200" ]] && process_download | |
else | |
# first run | |
[[ "$(curl -H "User-Agent: $useragent" -s -L $url -o $outfile -w %\{http_code\})" == "200" ]] && process_download | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment