60 lines
1.4 KiB
Text
60 lines
1.4 KiB
Text
|
#!/usr/bin/env bash
|
||
|
set -eau -o pipefail
|
||
|
|
||
|
if [ "$#" -ne 2 ]; then
|
||
|
echo "Usage: ingest path-to-directory-containing-IPE-CSVs path-to-generated-db"
|
||
|
echo ""
|
||
|
exit 1
|
||
|
fi
|
||
|
fullIpeDirPath=$(realpath "${1}")
|
||
|
fullDbPath=$(realpath "${2}")
|
||
|
|
||
|
tmpSql=$(mktemp)
|
||
|
clean_tmp () {
|
||
|
rm "${tmpSql}"
|
||
|
}
|
||
|
trap clean_tmp EXIT
|
||
|
|
||
|
echo "[+] Ingesting IPE ata."
|
||
|
echo " The following files will be ingested."
|
||
|
echo ""
|
||
|
ipeFiles=$(find "${fullIpeDirPath}" -name '*.csv')
|
||
|
cat > "${tmpSql}" <<EOF
|
||
|
.separator ";"
|
||
|
EOF
|
||
|
|
||
|
for ipeFile in ${ipeFiles}; do
|
||
|
echo " ${ipeFile}"
|
||
|
cat >> "${tmpSql}" <<EOF
|
||
|
.import ${ipeFile} ipe
|
||
|
EOF
|
||
|
done
|
||
|
echo ""
|
||
|
|
||
|
sqlite3 "${fullDbPath}" < "${tmpSql}"
|
||
|
|
||
|
echo "[+] Ingesting spatial data."
|
||
|
|
||
|
cat > "${tmpSql}" <<EOF
|
||
|
SELECT load_extension("mod_spatialite");
|
||
|
SELECT InitSpatialMetaData();
|
||
|
|
||
|
-- Despite the SELECT, we're actually creating a new ImmeubleGeoPoint
|
||
|
-- column here. The spatialite API is a bit weird...
|
||
|
SELECT AddGeometryColumn('ipe','ImmeubleGeoPoint',4326,'POINT');
|
||
|
|
||
|
-- The geodata is expressed in RGF93 (SRID 2154). We need to project
|
||
|
-- it to WSG84 to display it on a OSM map.
|
||
|
UPDATE ipe SET ImmeubleGeoPoint =
|
||
|
Transform(
|
||
|
MakePoint(
|
||
|
CAST(CoordonneeImmeubleX as DOUBLE),
|
||
|
CAST(CoordonneeImmeubleY as DOUBLE),
|
||
|
2154)
|
||
|
,4326);
|
||
|
EOF
|
||
|
|
||
|
sqlite3 "${fullDbPath}" < "${tmpSql}"
|
||
|
|
||
|
echo "[+] SQLite database generated at ${fullDbPath}"
|