### Makefile
N=South St. Paul MN Address Grid
DESC1=Using PLSS data.
## Author: Dan Jacobson https://www.jidanni.org/
## Copyright: https://www.gnu.org/licenses/gpl.html
## Created: 2024-02-07T03:46:04+0000
## Last-Updated: 2024-02-11T01:44:17+0000
##     Update #: 124
##
U = ../../../../utilities
export PERLLIB = $U
export PATH := $U:$(PATH)
include $U/m1.makefile
T=s_st_paul_mn
G=~/Downloads/plan_mngeo_trs.gpkg #F=~/Downloads/gpkg_plan_mngeo_trs.zip
Q=SELECT * FROM trs WHERE TOWN = 28 AND RANG = 22 AND SECT GLOB "2[278]" AND COUN_UC = "DAKOTA"
$T.vik:
$T.csv:corners.csv targets.csv $U/PLSS_projection.pm
	perl -MPLSS_projection -we 'PLSS_projection::pid2lonlat;' corners.csv targets.csv > $@.t
	mv $@.t $@
targets.csv:adr.csv Makefile $U pid2addr
	./pid2addr -I $< > $@.t
	mv $@.t $@
trs.geojsonl:$G
#	ogrinfo -al -so $< trs
#	ogrinfo -ro -al -features -dialect SQLITE -sql '$Q' $<
#	ogr2ogr -f LIBKML $@ -dialect SQLITE -sql '$Q' $<
	ogr2ogr -f GeoJSONSeq $@ -sql '$Q' $<
corners.csv:trs.geojsonl $U/PLSS_corners_4.pm
	perl -MPLSS_corners_4 -we 'PLSS_corners_4::parse_seq_MN46;' $< > $@.t
	mv $@.t $@

# d.json: #But all there were were townships outlines...
#	bash -c 'echo MN460280N0220W0SN2{2,7,8}O'|
#	echo MN460280N0220W0SN0|fetch_blm_sections #> $@.t && mv $@.t $@
#	perl -pwle 's/ /%7C/g'|

# So looked further,
# https://gisdata.mn.gov/dataset/plan-mndnr-public-land-survey has it but 500 MB
# https://mnatlas.org/resources/public-land-survey-sections/
# https://gisdata.mn.gov/dataset/plan-mndnr-public-land-survey
# https://gisdata.mn.gov/dataset/loc-pls-api-service
# https://www.mngeo.state.mn.us/chouse/pls/pls_api.html
# Never mind, I'll make it by hand. wait... finally found it:
# https://gisdata.mn.gov/dataset/plan-mngeo-trs

#Example file of points and labels where we want to put custom addresses:
adr.csv:pid2addr; ./$< --make-samples  > $@
clean:; rm *.csv *.geojsonl *.t #not kmz
