#!/bin/bash
# Highwood, IL, USA House addressing grids.
# # Author: Dan Jacobson https://www.jidanni.org/
# Copyright: https://www.gnu.org/licenses/gpl.html
# Created: 2023-09-04
# Last-Updated: 2023-09-07T09:13:42+0000
#     Update #: 3
set -ue -x
#Can't find any official definition. So, based on observations:
center=(-87.80835 42.19608) sw=(-87.81798 42.19614) #nw=(-87.81794 42.21064) #no easy-to-find "ne"
azimuth=$(echo ${center[@]} ${sw[@]} | gmt mapproject -AF+v -fg -o4 | gmt  convert -i+o90)
numbers_per_meter=$(gmt math -Q 800 1609.344 DIV =) #800 per mile
set -- +proj=omerc \
    +lonc=${center[0]} +lat_0=${center[1]} \
    +alpha=$azimuth +gamma=0 \
    +k_0=$numbers_per_meter
projs=$@ #proj string
rid=122065 #OSM relation id
if ! test -s $rid.kml
then
    ../fetch_boundary $rid
    ogr2ogr $rid.gmt $rid.kml
fi
for i in 0 1
do ../grat -600 200 0 1200 100 $i
done | sed 's/ 300$/ 322/' | #Highwood Avenue exception
    #700-1000 Sheridan Rd. seems to be its own system too...
    gmt mapproject -J"$projs" -I |
    gmt spatial -T$rid.gmt |
    gmt 2kml -Fl -K -Wthick,red > /tmp/x.kml
gmt 2kml -O -Fl -W5p,blue $rid.gmt >> /tmp/x.kml
viking --map 13 --zoom 15 --external /tmp/x.kml
