Skip to content
Snippets Groups Projects
Commit 7cb1dc76 authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

added poly2json script

parent ac229d51
No related branches found
No related tags found
No related merge requests found
*.json
\ No newline at end of file
#! /bin/sh
#######################################################################################################
# #
# This convertes a .poly file (http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format) #
# to a json file (which then can easily be loaded by leaflet's L.Polygon constructor) #
# #
#######################################################################################################
# Variable definition:
######################
POLY_FILE="$1"
OUTPUT_FILE="${POLY_FILE%%.json}"
# Startup checks:
#################
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ] || ! [ -f "$1" ]; then
echo "Usage: $0 POLYGON_IN_FILE [JSON_OUT_FILE]" >&2
exit 1
fi
if [ "$#" -eq 2 ]; then
OUTPUT_FILE="$2"
fi
if [ -f $OUTPUT_FILE ]; then
echo "Output file exists... not doing anything!"
exit 1
fi
# Main logic (copy from poly to json):
######################################
# Create output file
touch $OUTPUT_FILE
# Set the field seperator to a newline
IFS="
"
printf "[\n" >> $OUTPUT_FILE
# Loop through the .poly file
LC_NUMERIC="en_US.UTF-8"
IS_FIRST_ENTRY=true
for LINE in $(cat $POLY_FILE); do
if [[ $LINE != *\.* ]]; then
# Strip lines that do not contain numbers (Header, End-Markers, ...)
continue
fi
if $IS_FIRST_ENTRY; then
IS_FIRST_ENTRY=false
else
printf ",\n" >> $OUTPUT_FILE
fi
LINE=$(echo "$LINE" | sed -e 's/^ *//' -e 's/ *$//' -e 's/ */ /g')
IFS=" "
LINE_ARR=($LINE)
printf "[%0f, %0f]" "${LINE_ARR[0]}" "${LINE_ARR[1]}" >> $OUTPUT_FILE
done
printf "\n]\n" >> $OUTPUT_FILE
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment