# Makefile ---
N=Winetka Illinois address grid
DESC1=Using PLSS data.
# Author: Dan Jacobson https://www.jidanni.org/
# Copyright: https://www.gnu.org/licenses/gpl.html
# Created: 2024-02-13T13:10:21+0000
# Last-Updated: 2024-04-25T01:15:40+0000
#     Update #: 317
U = ../../../../utilities
export PERLLIB = $U
export PATH := $U:$(PATH)
include $U/m1.makefile
B=~/Downloads/PLSSFirstDivision.geojsonl
G=egrep
T=winnetka_il
C= > $@.t && test -s $@.t && mv $@.t $@
$T.vik:
targets.csv:pid2addr
	./$< --make-targets $C
#o=-order 1 -tps -rpc -geoloc #No effect. one day learn what these do.
K.csv:targets.csv Makefile corners_addr.csv
	gdaltransform $o -output_xy $(GCP) < $< | paste -d " " - $< $C
$T.csv:K.csv; perl -anwle 'print join ",", @F[0,1,-1];' $< $C
GCP=$$(perl -F, -anwle 'printf " -gcp %s %s %s %s", @F[2,3,0,1]' corners_addr.csv)
corners_addr.csv:pid2addr corners.csv #Makefile
	./$< corners.csv $C
# Should really also have gotten the acre size of the section, and checked if it was close to
# 640, to warn about lakeside deformed sections, which didn't trigger any alarms...
P=IL030420N0130E0SN(19|2[089]|30)
#P=IL030420N0130E0SN(1[69]|2[0189]|30)
corners.csv: $B $U/PLSS_corners_4.pm Makefile
	$G '$P' $< |\
	perl -MPLSS_corners_4 -we PLSS_corners_4::parse_seq > /tmp/$@
	test -s /tmp/$@
	sort -u -o $@.t /tmp/$@
	perl -F, -anwle '$$h{$$F[2]}++; END{for(keys %h){$(\
	)die "double values for $$_" unless $$h{$$_}==1;}}' $@.t
	mv $@.t $@
D=~/IL_CadNSDI_V2.gdb.zip # Yes, we found a wonderful file full of sections
mm:$D
#	ogrinfo -ro -so $< ; false
#	ogrinfo -ro -so $< PLSSFirstDivision PLSSPoint
#	ogrinfo -ro -so $< PLSSPoint
#	ogrinfo -ro -sql 'SELECT * FROM PLSSPoint LIMIT 3' $<
	ogrinfo -ro -sql "SELECT POINTID FROM PLSSPoint WHERE POINTID NOT LIKE '%' LIMIT 3" $<
$B:$D #And learned we didn't need their centers...
	ogr2ogr -f GeoJSONSeq $@ -progress -sql "SELECT FRSTDIVID FROM PLSSFirstDivision" $?
# Actually if centers were always available we wouldn't need to compute which corners are which...
clean:; rm *.csv *.t  *.gpkg #not *.kmz
observations:pid2addr; ./$< --$@

eee:
	for i in /tmp/ee/*; do ogrinfo -ro -al $$i; done
iii:
	set -ux -- $$(ogrinfo --formats|grep vector.*rw|perl -awlne 'print $$F[0]');\
	cd /tmp; \
	for i do ogr2ogr -gcp 0 1 0 1 -gcp 1 0 1 0 -gcp 1 1 1 1 -of $$i ee/$$i a.csv; done