Created
June 28, 2023 13:02
-
-
Save ThomasG77/27c547d6a9cff0e412dc58b4bd25be41 to your computer and use it in GitHub Desktop.
Load GTFS as GPKG with GDAL 3.7
This file contains 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
#!/usr/bin/env bash | |
# You need GDAL 3.7 to get GTFS driver supported and also -json option for ogrinfo (since 3.6 for this particular feature) | |
# To override, do something like | |
# gpkg_output_name=tutu.gpkg gtfs_path_or_url=mygtfs.zip bash gtfs-to-gpkg.sh | |
gtfs_path_or_url="${gtfs_path_or_url:-/vsicurl/https://eu.ftp.opendatasoft.com/stif/GTFS/IDFM-gtfs.zip}" | |
gpkg_output_name="${gpkg_output_name:-idfm-gtfs.gpkg}" | |
cmd=gdalinfo | |
if [ -x "$(command -v "$cmd")" ]; then | |
echo "Notice: $cmd is in \$PATH" | |
else | |
echo "Error: $cmd is not in \$PATH" | |
echo "Be sure to have GDAL installed" | |
exit | |
fi | |
gdal_version=$(gdalinfo --version | cut -d ',' -f1 | cut -d ' ' -f2) | |
gdal_version_as_number=$(echo $gdal_version | cut -d '.' -f1,2) | |
min_version=3.7 | |
if (( $(echo "$gdal_version_as_number < $min_version" | bc -l) )); then | |
echo "Error: You need GDAL version 3.7 or higher" | |
exit | |
else | |
echo "Notice: GDAL version is $gdal_version" | |
fi | |
layers=$(ogrinfo -json -nocount -noextent -nogeomtype "$gtfs_path_or_url" | jq -r .layers[].name) | |
INDEX=0 | |
for layer in $layers; do | |
echo $layer | |
if [ "${INDEX}" == 0 ] | |
then | |
gdal_update=""; | |
else | |
gdal_update="-update" | |
fi | |
ogr2ogr -f "GPKG" $gpkg_output_name $gdal_update "$gtfs_path_or_url" $layer | |
let INDEX=${INDEX}+1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment