#!/usr/bin/perl
# PLSS Township wanted list for South Dakota.
# Author: Dan Jacobson https://www.jidanni.org/
# Copyright: https://www.gnu.org/licenses/gpl.htm
# Created: 2023-12-27T19:11:07+0000
# Last-Updated: 2023-12-29T07:51:46+0000
#     Update #: 50
#
use strict;
use warnings q(all);
use PointId2Address;

=pod

=head1 S. Dakota - Just getting townships

We will just make simple ticks, every six miles along the N and W border of SD.

An excellent oppurtunity to just get townships, no sections... and
then compute their corners.

We will just get the N and W townships of the state, (which aren't
exactly the 100 ST and AVE, but we will just label points every six
miles on them).

T&R nos. from https://dlr.sd.gov/btp/documents/land_surveying_history.pdf
See also ../../../../../borders/n_s_dakota/index.html
=cut

## And we can get intersecting strips. Hard to explain...
my %h = (
    t => [ [23], [ -12 .. 23 ] ],    #T23N and T12S to T23N
    r => [ [1],  [ 1 .. 29 ] ]       #R1E and R1E to R29E
);
my %wants
  ; #A hash, so we can remove the doubled node at the origin where the two axes meet.
for ( 0, 1 ) {
    for (
        PointId2Address::twsp_blanket(
            {
                state    => "SD",
                meridian => "07",           #Black Hills
                T        => $h{t}[$_],
                R        => $h{r}[ !$_ ],
            }
        )
    ) {
        $wants{$_}++;
    }
}
$wants{$_}++
  for PointId2Address::twsp_blanket(
    {
        state    => "SD",
        meridian => "05",
        T        => [128],
        R        => [ -79 .. -57 ],    # Don't get -80!
    }
  );
for
  ( # By hand, for Sisseton Reservation etc. See fetch_blm_sections for index map URLs.
    "SD051280N0560W0",
    ## SD051280N0550W0 doesn't touch border
    "SD051290N0550W0",    #tiny but important
    ## SD051290N0540W0 bad
    "SD051290N0530W0",
    "SD051290N0520W0",
    "SD051290N0510W0",
    "SD051290N0500W0",
    "SD051290N0490W0",
    ## SD051280N0490W0 tiny
    "SD051280N0480W0",
    "SD051280N0470WA",
  ) {    #d=doesn't touch border. t=tiny
    $wants{$_}++;
}

print STDERR "Total wanted: ", scalar keys %wants, ".\n";
for ( sort keys %wants ) {
    next unless $wants{$_} > 1;
    printf STDERR "%s requested %d times. Folding.\n", $_, $wants{$_};
}
print join "%7C", sort keys %wants;
