Script for adding a boat ramp tag to the last node of a slipway polyline
Jump to navigation
Jump to search
- See leisure=slipway and List of LINZ layers and notes
- This assumes that the last thing written before the polyline describing the actual ramp is the last node of the ramp. While this is true for Rob's LINZ data extract web app, there is no guarantee or checks that this will be true for other data sources!
- Mac or Linux users can use this directly from a Terminal prompt. MS Windows users will need it install MSys or Cygwin to gain access to the UNIX power tools.
- (Does MacOSX ship with tac?)
#!/bin/sh
#
# Little shell script to extract the last node from a way
# and tag it with leisure=slipway.
#
# by H.Bowman 1 May 2010; released to the Public Domain.
#
# Input: .osm file exported from PostGIS database
# Output: .osm file ready for OSM editor app
# if no output file is given output is input name with
# "_with_slipway" added.
#
if [ $# -lt 1 ] ; then
echo
echo "Usage: `basename $0` input.osm [output.osm]"
echo
exit 1
fi
INPUT="$1"
if [ ! -r "$INPUT" ] ; then
echo "ERROR: Input file is not readable or does not exist."
exit 1
fi
if [ -n "$2" ] ; then
OUTPUT="$2"
else
OUTPUT="`basename "$INPUT" .osm`_with_slipway.osm"
fi
if [ -e "$OUTPUT" ] ; then
echo "ERROR: Output file <$OUTPUT> already exists"
exit 1
fi
#echo "Input: <$INPUT>"
#echo "Output: <$OUTPUT>"
# add newline at eof if needed
if [ `tac "$INPUT" | head -n 1 | tr ' ' '\n' | grep -c '</'` -eq 2 ] ; then
echo >> "$INPUT"
echo "WARNING: modified input file, added newline after last line."
fi
tac "$INPUT" | awk '{
if (/<way id=/) {
print
NEW_WAY=1
} else {
if ( NEW_WAY == 1 ) {
print " </node>"
print " <tag k=\"leisure\" v=\"slipway\" />"
sub(/ \/>$/, ">")
print
NEW_WAY=0
} else {
print
}
}
}' | tac > "$OUTPUT"
# done!