#!/usr/bin/perl # 巷 parser... # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.htm # Created: 2024-04-15T01:47:45+0000 # Last-Updated: 2024-07-12T02:44:03+0000 # Update #: 94 =encoding utf8 =head1 Input lines like: ... 路 1100 巷 6051 號 (No. 6051 Lane 1100 ... Rd) ... 路 1100 巷 6158 號 (No. 6158 Lane 1100 ... Rd) ... 路 6000 巷 1145 號 (No. 1145 Lane 6000 ... Rd) ... 路 6100 巷 1042 號 (No. 1042 Lane 6100 ... Rd) or even just 6100 巷1042號 =head1 Output lines like: "POINT (1145 5990)",1145 "POINT (1042 6110)",1042 "POINT (1092 6158)",6158 "POINT (1108 6051)",6051 which are WTK coordinates of where to put the house on the map, set back from the lane in the correct direction, followed by the correct label, which one then can post process, adding desired language words, etc. As a bonus, lines like 6000 巷 1145 號 (No. 1145 Lane 6000) are printed to STDOUT. =cut my ( $x, $h, ) = qw/巷 號/; my $usage = "Give lines with $x $h in them. Spaces optional."; my @setback = ##meters. Want to use less a percent of the 100 numbers ## of the longer EW oriented block direction ( 8, 10, ); print "WKT,Name$/"; while (<>) { chomp; next unless length; /(\d+)\s*$x\s*(\d+)\s*$h/ or die "$usage"; ## But what if users give us 2040-A, 2040A? my ( $lane, $house, ) = my @o = @{^CAPTURE}; ## Check the lane number to figure out if it is NS or EW: my $wesn = $lane >= $ENV{WeSnLimit}; # 1 means after the "mythical # big road" turns north, so its lanes are E-W. ## And here is where we will put odd numbers ## on one side of the road and even on the other: my $factor; ## Let's be real clear here (so not using "? :" format): if ($wesn) { # an E-W lane if ( $house % 2 ) { # odd number $factor = -1; # south side } else { # even number $factor = 1; # north side } } else { # a N-S lane if ( $house % 2 ) { # odd number $factor = 1; # east side } else { # even number $factor = -1; # west side } } $lane += $setback[$wesn] * $factor; my @F = ( $lane, $house, ); printf qq("POINT (%s %s)",%s$/), @F[ $wesn, !$wesn, ], $F[1]; printf STDERR "%d $x %d $h (No. %d Lane %d)$/", @o, reverse @o; }