summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/convert_all.sh62
-rwxr-xr-xscripts/convert_maps.sh4
-rwxr-xr-xscripts/geojson/get_rendered_meta.sh2
-rwxr-xr-xscripts/geojson/maps/fetch_bodiesofwater.sh62
-rwxr-xr-xscripts/geojson/maps/fetch_trainlines.sh66
-rwxr-xr-xscripts/geojson/maps/update_all.sh15
6 files changed, 205 insertions, 6 deletions
diff --git a/scripts/convert_all.sh b/scripts/convert_all.sh
new file mode 100755
index 0000000..cf566ad
--- /dev/null
+++ b/scripts/convert_all.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+
+OUTDIR=`pwd`/tiles
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
+
+mode="$1"
+
+if [ "$mode" == "legacy" ]; then
+ MAPSERVER='http://old-maps.li-fo.de/'
+ FILES=`curl "$MAPSERVER" | sed -n 's/.*<a href="\([^\.]\+\.png\).*/\1/p'`
+else
+ MAPSERVER='https://lifomaps.de'
+ FILES=`curl "$MAPSERVER" | sed -n 's/.*>\(world-[0-9\-]\+\.png\).*/\1/p'`
+fi
+
+if [[ "$FILES" == "" ]]; then
+ echo "ERROR: Could not detect latest map file."
+ exit
+fi
+
+for FILE in $FILES; do
+ REMOTE_URL="$MAPSERVER/$FILE"
+ LOCAL_FILE="`echo $FILE | sed 's#.*/##'`"
+ LOCAL_URL="$OUTDIR/$LOCAL_FILE"
+ MAPNAME=`echo $LOCAL_URL | sed 's/.*\/\([^\.]\+\).*/\1/g'`
+
+ echo "# Downloading and converting $MAPNAME."
+
+ mkdir -p $OUTDIR
+ cd $OUTDIR
+
+ if [ ! -d "$OUTDIR/$MAPNAME" ]; then
+ echo "Downloading latest map file..."
+ curl -C - "$REMOTE_URL" -o "$LOCAL_URL"
+
+ if [ "$mode" == "legacy" ]; then
+ echo "Patching map (for map exports prior to 2019-07-09)..."
+ OSIZE=`file $LOCAL_URL | sed -n 's/.*PNG image data, \([0-9]\+\).*/\1/p'`
+ NSIZE=$(($OSIZE+1008))
+ RESIZED_URL="$LOCAL_URL-temp.png"
+ convert $LOCAL_URL -gravity SouthEast -extent ${NSIZE}x${NSIZE} $RESIZED_URL
+ rm $LOCAL_URL
+ mv $RESIZED_URL $LOCAL_URL
+ fi
+
+ echo "Resizing map..."
+ OSIZE=`file $LOCAL_URL | sed -n 's/.*PNG image data, \([0-9]\+\).*/\1/p'`
+ NSIZE=$((2**6 * 256))
+ RESIZED_URL="$LOCAL_URL-resized.png"
+ convert $LOCAL_URL -extent ${NSIZE}x${NSIZE} -gravity NorthWest $RESIZED_URL
+
+ echo "Converting map..."
+ $SCRIPT_DIR/convert_maps.sh $MAPNAME $RESIZED_URL
+
+ echo "Cleaning up..."
+ rm $RESIZED_URL
+ rm $LOCAL_URL
+ else
+ echo "Skipping $MAPNAME."
+ fi
+done
diff --git a/scripts/convert_maps.sh b/scripts/convert_maps.sh
index faeea22..16bfe9f 100755
--- a/scripts/convert_maps.sh
+++ b/scripts/convert_maps.sh
@@ -11,8 +11,8 @@
# `convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $MAPFILE.scaled.png`
TILESIZE=256
-MAPNAME="world-2020-04-09"
-MAPFILE="../$MAPNAME.png"
+MAPNAME="$1"
+MAPFILE="$2"
width=`file "$MAPFILE" | sed -n "s/.* \([0-9]\+\) x \([0-9]\+\).*/\1/p"`
crop=$TILESIZE
diff --git a/scripts/geojson/get_rendered_meta.sh b/scripts/geojson/get_rendered_meta.sh
index 120645c..9debc53 100755
--- a/scripts/geojson/get_rendered_meta.sh
+++ b/scripts/geojson/get_rendered_meta.sh
@@ -9,7 +9,7 @@ categories=""
data=`curl -s "$1"`
-temp=`echo "$data" | sed -n 's/<p>\(.\+\).*/\1/p' | head -n1`
+temp=`echo "$data" | sed -n 's/<p>\(.\+\).*/\1/p' | grep -v -e '^<br />$' | sed 's#^</p>##' | head -n1`
if [ "$temp" != "" ]; then
temp=`echo "$temp" | sed "s#href=\"#href=\"$BASE#g" | sed 's/"/\\\\"/g' | sed 's/\t//g'`
description="$temp"
diff --git a/scripts/geojson/maps/fetch_bodiesofwater.sh b/scripts/geojson/maps/fetch_bodiesofwater.sh
new file mode 100755
index 0000000..8cd4a29
--- /dev/null
+++ b/scripts/geojson/maps/fetch_bodiesofwater.sh
@@ -0,0 +1,62 @@
+ #!/bin/bash
+
+json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:BodiesOfWater'`
+data=`echo "$json" | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"`
+
+section=""
+echo "["
+export IFS="}"
+for entry in $data; do
+ this_section=`echo $entry | sed -n 's/.*== \([^=]\+\) ==.*/\1/p'`
+ if [[ "$this_section" != "" ]]; then
+ section=$this_section
+ fi
+
+ if [[ "$section" != "$1" ]]; then
+ continue
+ fi
+
+ case "$section" in
+ "Rivers")
+ name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'`
+ type=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'`
+ coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'`
+ if [[ "$name" != "" && "$coord" != "" ]]; then
+ echo "{ \"type\": \"Feature\",
+ \"geometry\": {
+ \"type\": \"LineString\",
+ \"coordinates\": [
+ $coord
+ ]
+ },
+ \"properties\": {
+ \"name\": \"$name\",
+ \"type\": \"$type\"
+ }
+ },"
+ fi
+ ;;
+ "Oceans, Seas, and Lakes")
+ name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'`
+ type=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'`
+ coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'`
+ if [[ "$name" != "" && "$coord" != "" ]]; then
+ echo "{ \"type\": \"Feature\",
+ \"geometry\": {
+ \"type\": \"Polygon\",
+ \"coordinates\": [[
+ $coord
+ ]]
+ },
+ \"properties\": {
+ \"name\": \"$name\",
+ \"type\": \"$type\"
+ }
+ },"
+ fi
+ ;;
+ esac
+done
+export IFS=" "
+echo "{}"
+echo "]"
diff --git a/scripts/geojson/maps/fetch_trainlines.sh b/scripts/geojson/maps/fetch_trainlines.sh
new file mode 100755
index 0000000..f0c4d25
--- /dev/null
+++ b/scripts/geojson/maps/fetch_trainlines.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:Trainlines'`
+data=`echo "$json" | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"`
+
+section=""
+echo "["
+export IFS="}"
+for entry in $data; do
+ this_section=`echo $entry | sed -n 's/.*== \([^=]\+\) ==.*/\1/p'`
+ if [[ "$this_section" != "" ]]; then
+ section=$this_section
+ fi
+
+ if [[ "$section" != "$1" ]]; then
+ continue
+ fi
+
+ case "$section" in
+ "Train Lines")
+ name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'`
+ start=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'`
+ end=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\([^|]\+\)||\s*\([^|]\+\).*/\3/p' | sed 's/ $//'`
+ coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'`
+ if [[ "$name" != "" && "$coord" != "" ]]; then
+ echo "{ \"type\": \"Feature\",
+ \"geometry\": {
+ \"type\": \"LineString\",
+ \"coordinates\": [
+ $coord
+ ]
+ },
+ \"properties\": {
+ \"name\": \"$name\",
+ \"start\": \"$start\",
+ \"end\": \"$end\"
+ }
+},"
+ fi
+ ;;
+ "Access Paths")
+ name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'`
+ lines=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'`
+ coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'`
+ if [[ "$type" == "district" ]]; then
+ continue;
+ fi
+ if [[ "$name" != "" && "$coord" != "" ]]; then
+ echo "{ \"type\": \"Feature\",
+ \"geometry\": {
+ \"type\": \"LineString\",
+ \"coordinates\": [
+ $coord
+ ]
+ },
+ \"properties\": {
+ \"name\": \"$lines:$name\"
+ }
+},"
+ fi
+ ;;
+ esac
+done
+export IFS=" "
+echo "{}"
+echo "]"
diff --git a/scripts/geojson/maps/update_all.sh b/scripts/geojson/maps/update_all.sh
index 22b9eee..e25d843 100755
--- a/scripts/geojson/maps/update_all.sh
+++ b/scripts/geojson/maps/update_all.sh
@@ -1,10 +1,19 @@
#!/bin/bash
function fetch() {
- "./fetch_$1.sh" | json_reformat -m > "$1.json.tmp"
- rm -f "$1.json"
- mv "$1.json.tmp" "$1.json"
+ if [[ "$3" != "" ]]; then
+ fn="$3"
+ else
+ fn="$1"
+ fi
+ "./fetch_$1.sh" "$2" | json_reformat -m > "$fn.json.tmp"
+ rm -f "$fn.json"
+ mv "$fn.json.tmp" "$fn.json"
}
fetch streets
fetch city_outlines
+fetch trainlines "Train Lines"
+fetch trainlines "Access Paths" trainlines_access
+fetch bodiesofwater "Rivers" rivers
+fetch bodiesofwater "Oceans, Seas, and Lakes" oceans