### Makefile --- Du Page Co. Illinois addressing
## Author: Dan Jacobson https://www.jidanni.org/
## Copyright: https://www.gnu.org/licenses/gpl.html
## Created: 2023-12-12T09:00:25+0000
## Last-Updated: 2024-01-26T00:14:34+0000
##     Update #: 33
## Kane County uses same system too...
U = ../../../../utilities
export PERLLIB = $U
export PATH := $U:$(PATH)
B=~/Downloads/PLSSFirstDivision.geojsonl
D=~/IL_CadNSDI_V2.gdb.zip # Yes, we found a wonderful file full of sections
dupage_co_il.vik:
dupage_co_il.csv:dupage_co_il0.csv
	egrep IL030380N0..0E0_...100\|IL030..0N0090E0_100... $?|\
	sort -t , -k 2n -k 1n | ./pid2addr > $@ #the right place to sort.
#Patterns for the west and south edges of the county:
W=IL030380N0(09|10|11)0E0SN(31|33|35)0
S=IL030(38|39|40)0N0090E0SN(07|19|31)0
#No worry about matching the same node twice... thanks to Seq.
dupage_co_il0.csv:$B
	egrep '($W|$S)' $? |\
	perl -MPLSS_corners_4 -we 'PLSS_corners_4::parse_seq;' > $@
KO = 	-f LIBKML \
	-dsco NAME="DuPage Co. IL Address Grid" \
	-dsco DESCRIPTION="Using BLM PLSS data. See $(subst $(HOME)/,https://www.,$(PWD))"
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 $<)"'
%.kmz %.kml:%.csv; ogr2ogr $@ $? $(KO) $(CO)
%.vik:%.kmz; cd /tmp && nohup viking -e $(PWD)/$? & sleep 11
.PRECIOUS: %.kmz
$B:$D #And learned we didn't need their centers...
	ogr2ogr -f GeoJSONSeq $@ -progress -sql "SELECT FRSTDIVID FROM PLSSFirstDivision" $?
#	ogr2ogr -f GeoJSONSeq $@ -dialect SQLITE -sql $(\
#	'SELECT FRSTDIVID FROM PLSSFirstDivision WHERE FRSTDIVID REGEXP "($W|$S)"' $?
#	Too slow for too little. Too bad.
