mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[tools] Add generate_subways.sh script
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
ef6ffa299d
commit
01aecbfac4
1
.gitignore
vendored
1
.gitignore
vendored
@@ -178,6 +178,7 @@ tools/python/*/venv/
|
|||||||
# Configs
|
# Configs
|
||||||
tools/python/maps_generator/var/etc/map_generator.ini
|
tools/python/maps_generator/var/etc/map_generator.ini
|
||||||
tools/python/routing/etc/*.ini
|
tools/python/routing/etc/*.ini
|
||||||
|
tools/unix/maps/settings.sh
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
/node_modules/
|
/node_modules/
|
||||||
|
|||||||
1
tools/python/transit/requirements.txt
Normal file
1
tools/python/transit/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
numpy
|
||||||
16
tools/unix/helper_python.sh
Normal file
16
tools/unix/helper_python.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
PYTHON="${PYTHON:-python3}"
|
||||||
|
|
||||||
|
function activate_venv_at_path() {
|
||||||
|
path=$1
|
||||||
|
|
||||||
|
if [ ! -d "$path/".venv ]; then
|
||||||
|
"$PYTHON" -m venv "$path"/.venv
|
||||||
|
fi
|
||||||
|
|
||||||
|
source "$path"/.venv/bin/activate
|
||||||
|
|
||||||
|
if [ -f "$path"/requirements.txt ]; then
|
||||||
|
pip install --upgrade pip
|
||||||
|
pip install -r "$path"/requirements.txt
|
||||||
|
fi
|
||||||
|
}
|
||||||
47
tools/unix/maps/generate_subways.sh
Executable file
47
tools/unix/maps/generate_subways.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e -u -o pipefail
|
||||||
|
|
||||||
|
# Generate subways.transit.json file consumed by the maps generator.
|
||||||
|
# Inputs:
|
||||||
|
# - OSM planet in pbf format
|
||||||
|
# - csv table of subway networks
|
||||||
|
# (auto-downloaded from https://docs.google.com/spreadsheets/d/1SEW1-NiNOnA2qDwievcxYV1FOaQl1mb1fdeyqAxHu3k)
|
||||||
|
# Output:
|
||||||
|
# - subways.transit.json
|
||||||
|
|
||||||
|
source "$(dirname "$0")/helper_settings.sh"
|
||||||
|
source "$REPO_PATH/tools/unix/helper_python.sh"
|
||||||
|
|
||||||
|
# Parameters for the process_subways.sh script:
|
||||||
|
export PLANET="$PLANET_PBF"
|
||||||
|
export SKIP_PLANET_UPDATE="1"
|
||||||
|
# http(s) or "file://" URL to a CSV file with a list of subway networks.
|
||||||
|
# Auto-downloaded from https://docs.google.com/spreadsheets/d/1SEW1-NiNOnA2qDwievcxYV1FOaQl1mb1fdeyqAxHu3k
|
||||||
|
# If unavailable then replace with a local file.
|
||||||
|
# TODO: keep the downloaded csv file from the latest run.
|
||||||
|
#export CITIES_INFO_URL=""
|
||||||
|
export TMPDIR="$BUILD_PATH/subways"
|
||||||
|
# The output file, which needs post-processing by transit_graph_generator.py
|
||||||
|
export MAPSME="$SUBWAYS_PATH/subways.json"
|
||||||
|
|
||||||
|
# Produce additional files needed for https://cdn.organicmaps.app/subway/
|
||||||
|
export HTML_DIR="$SUBWAYS_VALIDATOR_PATH"
|
||||||
|
export DUMP="$SUBWAYS_VALIDATOR_PATH"
|
||||||
|
export GEOJSON="$SUBWAYS_VALIDATOR_PATH"
|
||||||
|
export DUMP_CITY_LIST="$SUBWAYS_VALIDATOR_PATH/cities.txt"
|
||||||
|
|
||||||
|
"$SUBWAYS_REPO_PATH/scripts/process_subways.sh" 2>&1 | tee "$SUBWAYS_LOG"
|
||||||
|
|
||||||
|
# Make render.html available for map visualization on the web
|
||||||
|
cp -r "$SUBWAYS_REPO_PATH"/render/* "$SUBWAYS_VALIDATOR_PATH/"
|
||||||
|
|
||||||
|
TRANSIT_TOOL_PATH="$REPO_PATH/tools/python/transit"
|
||||||
|
SUBWAYS_GRAPH_FILE="$SUBWAYS_PATH/subways.transit.json"
|
||||||
|
|
||||||
|
activate_venv_at_path "$TRANSIT_TOOL_PATH"
|
||||||
|
"$PYTHON" "$TRANSIT_TOOL_PATH/transit_graph_generator.py" "$MAPSME" "$SUBWAYS_GRAPH_FILE" 2>&1 | tee -a "$SUBWAYS_LOG"
|
||||||
|
deactivate
|
||||||
|
|
||||||
|
echo "Generated subways transit graph file:"
|
||||||
|
echo "$SUBWAYS_GRAPH_FILE"
|
||||||
|
echo "Finished"
|
||||||
25
tools/unix/maps/helper_settings.sh
Normal file
25
tools/unix/maps/helper_settings.sh
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
SETTINGS_FILE="${SETTINGS_FILE:-$(cd "$(dirname "$0")"; pwd -P)/settings.sh}"
|
||||||
|
if [ -f "$SETTINGS_FILE" ]; then
|
||||||
|
echo "Using settings from $SETTINGS_FILE"
|
||||||
|
source "$SETTINGS_FILE"
|
||||||
|
else
|
||||||
|
echo "Creating a template settings file $SETTINGS_FILE"
|
||||||
|
cat << EOF > "$SETTINGS_FILE"
|
||||||
|
# Customize the default settings here.
|
||||||
|
# (check the defaults in settings_default.sh)
|
||||||
|
|
||||||
|
# The default maps workspace base is ../maps relative to the repo.
|
||||||
|
# All source and output and intermediate files will be organized there in corresponding subdirs.
|
||||||
|
# E.g. set it to the user's home directory:
|
||||||
|
# BASE_PATH="$HOME"
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
source "$(dirname "$0")/settings_default.sh"
|
||||||
|
|
||||||
|
mkdir -p "$BASE_PATH"
|
||||||
|
mkdir -p "$BUILD_PATH"
|
||||||
|
mkdir -p "$DATA_PATH"
|
||||||
|
|
||||||
|
mkdir -p "$PLANET_PATH"
|
||||||
|
mkdir -p "$SUBWAYS_PATH"
|
||||||
25
tools/unix/maps/settings_default.sh
Normal file
25
tools/unix/maps/settings_default.sh
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# NOTE: edit the settings.sh file to customize/override the defaults.
|
||||||
|
|
||||||
|
# Absolutize & normalize paths.
|
||||||
|
REPO_PATH="${REPO_PATH:-$(cd "$(dirname "$0")/../../.."; pwd -P)}"
|
||||||
|
|
||||||
|
BASE_PATH="${BASE_PATH:-$REPO_PATH/../maps}"
|
||||||
|
# Temporary files
|
||||||
|
BUILD_PATH="${BUILD_PATH:-$BASE_PATH/build}"
|
||||||
|
# Other code repositories, e.g. subways, wikiparser..
|
||||||
|
CODE_PATH="${CODE_PATH:-$REPO_PATH/..}"
|
||||||
|
# Source map data and processed outputs e.g. wiki articles
|
||||||
|
DATA_PATH="${DATA_PATH:-$BASE_PATH/data}"
|
||||||
|
|
||||||
|
# OSM planet source files
|
||||||
|
|
||||||
|
PLANET_PATH="${PLANET_PATH:-$DATA_PATH/planet}"
|
||||||
|
PLANET_PBF="${PLANET_PBF:-$PLANET_PATH/planet-latest.osm.pbf}"
|
||||||
|
PLANET_O5M="${PLANET_O5M:-$PLANET_PATH/planet-latest.o5m}"
|
||||||
|
|
||||||
|
# Subways
|
||||||
|
|
||||||
|
SUBWAYS_REPO_PATH="${SUBWAYS_REPO_PATH:-$CODE_PATH/subways}"
|
||||||
|
SUBWAYS_PATH="${SUBWAYS_PATH:-$DATA_PATH/subways}"
|
||||||
|
SUBWAYS_LOG="${SUBWAYS_LOG:-$SUBWAYS_PATH/subways.log}"
|
||||||
|
SUBWAYS_VALIDATOR_PATH="${SUBWAYS_VALIDATOR_PATH:-$SUBWAYS_PATH/validator}"
|
||||||
Reference in New Issue
Block a user