#!/usr/bin/perl # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.html # Created: 2023-11-17T13:45:38+0000 # Last-Updated: 2023-12-28T21:56:33+0000 # Update #: 409 =head1 NAME OnePLSSSec - Print one US PLSS section's ring of nodes details, for debugging =head1 USAGE From the shell, use an environment variable: $ filter=ND051290N0970W0SN340 OnePLSSSec BLM.json BLM input is the same format as used in PLSS_corners.pm . =head2 Output $ filter=IL030430N0100E0SN360 OnePLSSSec d.json -88.0046011276936,42.1679122426371,0: 0 -88.004472002058,42.1535938668403,1: 1 -88.0045498859932,42.1536063277028,2: 1 -88.0236153882235,42.1537167591673,3: 2 -88.0240035772072,42.1537190114552,4: 2 -88.0242066925812,42.1537201795548,5: 2 -88.0239623975363,42.1680598247816,6: 3 -88.0143147261034,42.1608017620379,IL030430N0100E0SN360 Here we see X,Y,{node number: our bucket}, or id of centroid. We disposed of the final loop back node, as it is the same as the first. Also works great on townships, not just sections: $ filter=SD051280N0760W0 OnePLSSSec d.json -100.089948218423,45.9309625552075,0: 3 -100.089949284724,45.93460674562,1: 3... =cut use strict; use warnings q(all); use JSON::PP; use Math::Trig qw(great_circle_distance great_circle_direction deg2rad rad2deg); sub NESW { deg2rad( $_[0] ), deg2rad( 90 - $_[1] ) } use PLSS_corners; die "use a ENV variable, e.g., filter=ND051290N0970W0SN340" unless $ENV{filter}; my $ph; { local $/; $ph = decode_json <>; } my @center_deg; my @d; for ( 0 .. $#{ $ph->{coordinates} } ) { next unless $ENV{filter} eq $ph->{coordinates}[$_]{plssid}; @center_deg = ( $ph->{coordinates}[$_]{lon}, $ph->{coordinates}[$_]{lat} ); my @center_rad = NESW @center_deg; my @r = @{ $ph->{features}[$_]->{geometry}->{rings}[0] }; for ( 0 .. $#r - 1 ) { #last one just closes the loop and is always a repeat, so skip. my %k; @{ $k{rad} } = NESW( @{ $r[$_] } ); my $t = great_circle_direction( @center_rad, @{ $k{rad} } ); $k{bucket} = PLSS_corners::buck($t); push @d, \%k; printf "%s,%s,%s: %d\n", @{ $r[$_] }, $_, $k{bucket}; } } printf "%s,%s,%s\n", @center_deg, $ENV{filter};