/
p5-get-orig-geo-data.pl
executable file
·160 lines (123 loc) · 3.74 KB
/
p5-get-orig-geo-data.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env perl
# this is a Perl 5 program
use strict;
use warnings;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
#http://www.ngs.noaa.gov/cgi-bin/Inv_Fwd/forward2.prl
#http://www.ngs.noaa.gov/cgi-bin/Inv_Fwd/inverse2.prl
my $uf = 'http://www.ngs.noaa.gov/cgi-bin/Inv_Fwd/forward2.prl';
my $ui = 'http://www.ngs.noaa.gov/cgi-bin/Inv_Fwd/inverse2.prl';
my $ua = LWP::UserAgent->new();
get_forward();
get_inverse();
sub get_forward {
# forward
my $req = POST $uf, [
ELLIPSOID => 'GRS80/WGS84',
FROM_NAME => 'from',
FIRST_LAT => 'N01.0',
FIRST_LON => 'e00.0',
AZIMUTH => '120.0',
DIST => '10000.0',
TO_NAME => 'to',
];
my $res = $ua->request($req)->as_string;
parse($res);
#print $res;
=pod
# example raw output (unneeded stripped away)
<h2>Output from FORWARD</h2><pre>
Ellipsoid : GRS80 / WGS84 (NAD83)
Equatorial axis, a = 6378137.0000
Polar axis, b = 6356752.3141
Inverse flattening, 1/f = 298.25722210088
First Station : from
----------------
LAT = 1 0 0.00000 North
LON = 0 0 0.00000 East
Second Station : to
----------------
LAT = 0 57 17.21068 North
LON = 0 4 40.10559 East
Forward azimuth FAZ = 120 0 0.0000 From North
Back azimuth BAZ = 300 0 4.7780 From North
Ellipsoidal distance S = 10000.0000 m
=cut
}
sub get_inverse {
my $req = POST $ui, [
ELLIPSOID => 'GRS80/WGS84',
FROM_NAME => 'from',
FIRST_LAT => 'N01.0',
FIRST_LON => 'e00.0',
TO_NAME => 'to',
SECOND_LAT => 'S01.0',
SECOND_LON => 'w00.0',
];
my $res = $ua->request($req)->as_string;
print $res;
=pod
# example raw output (unneeded stripped away)
<h2>Output from INVERSE </h2><pre>
Ellipsoid : GRS80 / WGS84 (NAD83)
Equatorial axis, a = 6378137.0000
Polar axis, b = 6356752.3141
Inverse flattening, 1/f = 298.25722210088
First Station : from
----------------
LAT = 1 0 0.00000 North
LON = 0 0 0.00000 East
Second Station : to
----------------
LAT = 1 0 0.00000 South
LON = 0 0 0.00000 East
Forward azimuth FAZ = 180 0 0.0000 From North
Back azimuth BAZ = 0 0 0.0000 From North
Ellipsoidal distance S = 221148.7771 m
=cut
}
sub parse {
my $s = shift @_;
# split on newline
my @lines = split /^/, $s;
foreach my $line (@lines) {
chomp $line;
if ($line =~ m{ Output \s+ from \s+ (INVERSE|FORWARD)}xms) {
my $dir = $1;
print "DEBUG: $line\n";
print " ($dir)\n";
}
elsif ($line =~ m{\A \s* Ellipsoid \s \: \s* ([\S\s]+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1)\n";
}
elsif ($line =~ m{\A \s* Equatorial \s axis, \s+ a \s+ = \s+ (\S+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1)\n";
}
elsif ($line =~ m{\A \s* Polar \s axis, \s+ b \s+ = \s+ (\S+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1)\n";
}
elsif ($line =~ m{\A \s* Inverse \s flattening, \s+ 1/f \s+ = \s+ (\S+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1)\n";
}
elsif ($line =~ m{\A \s* (LAT|LON) \s+ = \s+ (\S+) \s+ (\S+) \s+ (\S+) \s+ (\S+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1) ($2) ($3) ($4) ($5)\n";
}
elsif ($line =~ m{\A \s* (Forward|Back) \s azimuth \s+ (FAZ|BAZ) \s = \s+ (\S+) \s+ (\S+) \s+ (S+) \s+ (\S+) \s+ (\S+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1) ($2) ($3) ($4) ($5) ($6) ($7)\n";
}
elsif ($line =~ m{\A \s* Ellipsoidal \s distance \s+ S \s+ = \s+(\S+) \s+ (\S+) \s* \z}xms) {
print "DEBUG: $line\n";
print " ($1) ($2)\n";
}
#chomp $line;
#print " $line\n";
}
die "DEBUG exit";
}