### Makefile --- For state-wide North Dakota addressing systems
## Author: Dan Jacobson https://www.jidanni.org/
## Copyright: https://www.gnu.org/licenses/gpl.html
## Created: 2023-12-05T15:12:15+0000
## Last-Updated: 2023-12-06T12:39:57+0000
##     Update #: 30
## 
U=../../../utilities
export PATH := $U:$(PATH)
export PERLLIB = $U
KO = 	-f LIBKML \
	-dsco NAME="North Dakota Burkle grid road name axes" \
	-dsco DESCRIPTION="Via BLM PLSS data. See https://www.jidanni.org/geo/borders/n_s_dakota"
CO=	-oo HEADERS=NO \
	-oo KEEP_GEOM_COLUMNS=NO \
	-oo X_POSSIBLE_NAMES=field_1 \
	-oo Y_POSSIBLE_NAMES=field_2 \
	-sql 'SELECT field_3 AS Name FROM "$(basename $<)"'
burkle.vik:
#Let's also make a township numbering map, just for fun:
townships.csv:cor.csv #Well it shows the position of the beginning of that numbered township...
	perl -F, -anwle '@v=unpack "xxxxA3xAA3xAxxxxxxxx", $$F[2];$(\
	)if($$v[2]==78){@i=(0,1)}else{$$v[2]+=0; @i=(2,3)};$(\
	)printf "%s,%s,%s%s\n", @F[0,1], @v[@i];' $? > $@
burkle.csv:burkle cor.csv; ./$^ > $@
%.kmz %.kml:%.csv; ogr2ogr $@ $? $(KO) $(CO)
%.vik:%.kmz
	cd /tmp && nohup viking -e $(PWD)/$? &
	sleep 11
cor.csv:d.json $U/PLSS_corners.pm
	perfect_only=1 perl -MPLSS_corners -we 'PLSS_corners::process()' $< > $@.t
	grep _700100$$ $@.t > $@
	rm $@.t
d.json:; ./make_wants|fetch_blm_sections > $@.t && mv $@.t $@
.PRECIOUS: %.kmz