lifomapserver/scripts/geojson/maps/fetch_bodiesofwater.sh

65 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
source common.sh
json=`curl ${CURLOPTS[@]} '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 "]"