Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: approximating geological problems with highway data

by AnomalousMonk (Archbishop)
on Jan 26, 2023 at 09:51 UTC ( #11149891=note: print w/replies, xml ) Need Help??


in reply to Re^2: approximating geological problems with highway data
in thread approximating geological problems with highway data

In sub init_event { ... }
{ "name" => "snowville", "date" => $date_str, "time" => $time_str, "location" => { lon => -112.7105234, lat => 41.9655701 }, 42.152429, -112.9842191 },

Is the 42.152429, -112.9842191 key/value pair from the posted code perhaps a tyop? It's syntactically correct, but looks semantically fishy. Looks like it escaped from the following event record anonymous hash. (Update: OTOH, it looks quite harmless since you're unlikely to ever encounter a "42.152429" key in your code. :)

Also, if init_event() isn't just stub code for the SSCCE, a more succinct way to write it would be

c:\@Work\Perl\monks>perl use strict; use warnings; use Data::Dump qw(dd); sub init_event { # define unique event records as anonymous hash refs. my $ar_events = [ { "name" => "Boise", "location" => { lon => -116.2, lat => 43.61 }, }, { "name" => "near sublett", "location" => { lon => -113.2104084, lat => 42.3278114 }, }, { "name" => "snowville", "location" => { lon => -112.7105234, lat => 41.9655701 }, }, { "name" => "juniper", "location" => { lon => -112.9842191, lat => 42.152429 }, }, # and so on... ]; # add standard date/time to each event record. my $date_str = "2021-10-14"; my $time_str = "03:22:31"; @{$_}{ qw(date time) } = ($date_str, $time_str) for @$ar_events; return $ar_events; } my $ar_ev = init_event(); dd $ar_ev; ^Z [ { date => "2021-10-14", location => { lat => "43.61", lon => "-116.2" }, name => "Boise", "time" => "03:22:31", }, { date => "2021-10-14", location => { lat => "42.3278114", lon => "-113.2104084" }, name => "near sublett", "time" => "03:22:31", }, { date => "2021-10-14", location => { lat => "41.9655701", lon => "-112.7105234" }, name => "snowville", "time" => "03:22:31", }, { date => "2021-10-14", location => { lat => "42.152429", lon => "-112.9842191" }, name => "juniper", "time" => "03:22:31", }, ]


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: approximating geological problems with highway data
by Aldebaran (Curate) on Jan 29, 2023 at 06:19 UTC

    Thanks all for helpful source comments. I can now compare numbers from different sources. This link should contain the newest source: 4.am.pl

    Output:

    $ ./4.am.pl Subroutine get_logger redefined at ./4.am.pl line 146. INFO: ./4.am.pl INFO: pi is 3.14159265358979 INFO: Bonneville max altitude in feet: 5200 INFO: Boise 43.61 -116.2 INFO: return from the google is 821 meters INFO: Altitude in feet is 2693.56964 INFO: Difference from max Bonneville elevation is 2506.43036 ft INFO: USGS elevation is 2697.37 ft INFO: Percent difference is 0.140990634426756 INFO: distance is 7794.07491881811 miles INFO: distance is 4656.32531168763 miles INFO: Percent difference is 50.4039958401085 INFO: ============== INFO: near sublett 42.3278114 -113.2104084 INFO: return from the google is 1455 meters INFO: Altitude in feet is 4773.6222 INFO: Difference from max Bonneville elevation is 426.3778 ft INFO: USGS elevation is 4780.72 ft INFO: Percent difference is 0.148577470880213 INFO: distance is 175.16979925839 miles INFO: distance is 175.486511142723 miles INFO: Percent difference is 0.180639489402675 INFO: ============== INFO: snowville 41.9655701 -112.7105234 INFO: return from the google is 1384 meters INFO: Altitude in feet is 4540.68256 INFO: Difference from max Bonneville elevation is 659.31744 ft INFO: USGS elevation is 4545.24 ft INFO: Percent difference is 0.100318706656456 INFO: distance is 35.8058824322112 miles INFO: distance is 35.837188345951 miles INFO: Percent difference is 0.0873941147406608 INFO: ============== INFO: juniper 42.152429 -112.9842191 INFO: return from the google is 1577 meters INFO: Altitude in feet is 5173.88468 INFO: Difference from max Bonneville elevation is 26.1153199999999 ft INFO: USGS elevation is 5169.2 ft INFO: Percent difference is 0.0905857419703596 INFO: distance is 19.0729839145012 miles INFO: distance is 19.0916186594743 miles INFO: Percent difference is 0.097654599897474 INFO: ============== $

    The first distance is kludged with garbage values, so not too surprised to see 50% error there, but look at how close the values tended to be! I think I might have 3 sig figs. The modified script is approximately:

    ### Elevation with USGS use Geo::WebService::Elevation::USGS; my $eq = Geo::WebService::Elevation::USGS->new(); my $alt = $eq->elevation( $event->{location}->{lat}, $event->{location}->{lo +n} ) ->{Elevation}; $logger->info("USGS elevation is $alt ft"); ### compare values my $percent = percent_error( $feet, $alt ); $logger->info("Percent difference is $percent"); ### home cooked distance my $d = distance( $prev_lat, $prev_long, $event->{location}->{lat}, $event->{location}->{lon}, "M" ); $logger->info("distance is $d miles"); ### distance with GPS::Point use GPS::Point; my $gps = GPS::Point->new( lat => $prev_lat, lon => $prev_long ); my $dist = $gps->distance( $event->{location}->{lat}, $event->{location}->{lo +n} ); my $feet2 = 3.28084 * $dist; my $miles = $feet2 / 5280; #$logger->info("distance is $feet2 feet"); $logger->info("distance is $miles miles"); ### compare values my $percent2 = percent_error( $d, $miles ); $logger->info("Percent difference is $percent2");

    Really happy to work up a different source for elevations, and look, I ran into Tom Wyant's software again:

    Running Build test for WYANT/Geo-WebService-Elevation-USGS-0.120.tar.g +z t/basic.t .. ok t/elev.t ... # Accessing https://nationalmap.gov/epqs/pqs.php

    Cheers,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2023-09-22 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?