NAME

Geo::WebService::Elevation::USGS - Elevation queries against USGS web services.

SYNOPSIS

use Geo::WebService::Elevation::USGS;

my $eq = Geo::WebService::Elevation::USGS->new();
print "The elevation of the White House is ",
  $eq->elevation( 38.898748, -77.037684 )->{Elevation},
  " feet above sea level.\n";

NOTICE

The GIS data web service this module was originally based on has gone the way of the dodo. This release uses the NED service, which is similar but simpler. When the change was made, code was installed to ease the transition by emulating the old service to the extent possible. This code was deprecated pretty much when it was released as 0.100_01 in July of 2014. With release 0.115_01 use of any of the compatibility code, including the 'compatible' attribute itself, results in a fatal error. In another six months, all the compatibility machinery will be stripped, and we will left with a reasonably-pure interface to the NED service.

DESCRIPTION

This module executes elevation queries against the United States Geological Survey's web NAD server. You provide the latitude and longitude in degrees, with south latitude and west longitude being negative. The return is typically a hash containing the data you want. Query errors are exceptions by default, though the object can be configured to signal an error by an undef response, with the error retrievable from the 'error' attribute.

For documentation on the underlying web service, see http://nationalmap.gov.

For all methods, the input latitude and longitude are documented at the above web site as being WGS84, which for practical purposes I understand to be equivalent to NAD83. The vertical reference is not documented under the above link, but correspondence with the USGS says that it is derived from the National Elevation Dataset (NED; see http://nationalmap.gov). This is referred to NAD83 (horizontal) and NAVD88 (vertical). NAVD88 is based on geodetic leveling surveys, not the WGS84/NAD83 ellipsoid, and takes as its zero datum sea level at Father Point/Rimouski, in Quebec, Canada. Alaska is an exception, and is based on NAD27 (horizontal) and NAVD29 (vertical).

Anyone interested in the gory details may find the paper Converting GPS Height into NAVD88 Elevation with the GEOID96 Geoid Height Model by Dennis G. Milbert, Ph.D. and Dru A. Smith, Ph.D helpful. This is available at http://www.ngs.noaa.gov/PUBS_LIB/gislis96.html. This paper states that the difference between ellipsoid and geoid heights ranges between -75 and +100 meters globally, and between -53 and -8 meters in "the conterminous United States."

Methods

The following public methods are provided:

$eq = Geo::WebService::Elevation::USGS->new();

This method instantiates a query object. If any arguments are given, they are passed to the set() method. The instantiated object is returned.

%values = $eq->attributes();

This method returns a list of the names and values of all attributes of the object. If called in scalar context it returns a hash reference.

$rslt = $usgs->elevation($lat, $lon, $valid);

This method queries the data base for the elevation at the given latitude and longitude, returning the results as a hash reference. This hash will contain the following keys:

{Data_Source} => A text description of the data source;

{Elevation} => The elevation in the given units;

{Units} => The units of the elevation ('Feet' or 'Meters');

{x} => The $lon argument;

{y} => The $lat argument.

For compatibility with versions of this module before 0.100, this method behaves slightly differently if the compatible attribute is true:

* The {Data_ID} key of the return will be set to the value of the {Data_Source} key;

* The {Units} key will be converted to upper case;

* If called in scalar context the return will be a reference to an array whose single element is the results hash.

Note that as of version 0.106_01, the default for this attribute is false.

You can also pass a Geo::Point, GPS::Point, or Net::GPSD::Point object in lieu of the $lat and $lon arguments. If you do this, $valid becomes the second argument, rather than the third.

If the optional $valid argument is specified and the returned data are invalid, nothing is returned. This means an empty array if compatible is true. The NAD source does not seem to produce data recognizable as invalid, so you will probably not see this.

The NAD server appears to return an elevation of 0 if the elevation is unavailable.

$value = $eq->get($attribute);

This method returns the value of the given attribute. It will croak if the attribute does not exist.

$rslt = $eq->getAllElevations($lat, $lon, $valid);

Starting with version 0.100, this method is essentially a wrapper for the elevation() method. Starting with version 0.115_01, calling this method results in a fatal error.

$rslt = $eq->getElevation($lat, $lon, $source, $elevation_only);

Starting with version 0.100, this method is essentially a wrapper for the elevation() method. Starting with version 0.115_01, calling this method results in a fatal error.

$boolean = $eq->is_valid($elevation);

This method (which can also be called as a static method or as a subroutine) returns true if the given datum represents a valid elevation, and false otherwise. A valid elevation is a number having a value greater than -1e+300. The input can be either an elevation value or a hash whose {Elevation} key supplies the elevation value.

$eq = $eq->set($attribute => $value ...);

This method sets the value of the given attribute. Multiple attribute/value pairs may be specified. The object itself is returned, to allow call chaining. An attempt to set a non-existent attribute will result in an exception being thrown.

Attributes

carp

Boolean

This Boolean attribute determines whether the data acquisition methods carp on encountering an error. If false, they silently return undef. Note, though, that the croak attribute trumps this one.

If retry is set to a number greater than 0, you will get a carp on each failed query, provided croak is false. If croak is true, no retries will be carped.

This attribute was introduced in Geo::WebService::Elevation::USGS version 0.005_01.

The default is 0 (i.e. false).

compatible

Boolean

This Boolean attribute determines whether this object attempts to make returned data consistent with the old GIS server.

As of version 0.115_01, any access of this attribute is fatal. See the NOTICE above for details.

croak

Boolean

This Boolean attribute determines whether the data acquisition methods croak on encountering an error. If false, they return undef on an error.

If retry is set to a number greater than 0, the data acquisition method will not croak until all retries are exhausted.

The default is 1 (i.e. true).

default_ns

String

This attribute is deprecated. As of version 0.115.01, any access of this attribute is fatal. See the NOTICE above for details.

error

String

This attribute records the error returned by the last query operation, or undef if no error occurred. This attribute can be set by the user, but will be reset by any query operation.

The default (before any queries have occurred) is undef.

places

Integer

If this attribute is set to a non-negative integer, elevation results will be rounded to this number of decimal places by running them through sprintf "%.${places}f".

The default is undef.

proxy

String

This attribute is deprecated. As of version 0.115_01 any access of this attribute is fatal. See the NOTICE above for details.

retry

Unsigned integer

This attribute specifies the number of retries to be done by elevation() when an error is encountered. The first try is not considered a retry, so if you set this to 1 you get a maximum of two queries (the try and the retry).

Retries are done only on actual errors, not on bad extents. They are also subject to the "throttle" setting if any.

The default is 0, i.e. no retries.

retry_hook

Code reference

This attribute specifies a piece of code to be called before retrying. The code will be called before a retry takes place, and will be passed the Geo::WebService::Elevation::USGS object, the number of the retry (from 1), the name of the method being retried ('elevation' and the arguments to that method. If the position was passed as an object, the hook gets the latitude and longitude unpacked from the object. The hook will not be called before the first try, nor after the last retry.

Examples:

# To sleep 5 seconds between retries:
$eq->set( retry_hook => sub { sleep 5 } );

# To sleep 1 second before the first retry, 2 seconds
# before the second, and so on:
$eq->set( retry_hook => sub { sleep $_[1] } );

# To do nothing between retries:
$eq->set( retry_hook => sub {} );

The default is the null subroutine, i.e. sub {}.

source

This attribute is deprecated. As of version 0.115_01 any access of this attribute is fatal. See the NOTICE above for details.

throttle

Non-negative number, or undef

Geo::WebService::Elevation::USGS->set( throttle => 5 );

This attribute, if defined and positive, specifies the minimum interval between queries, in seconds. This attribute may be set statically only, and the limit applies to all queries, not just the ones from a given object. If Time::HiRes can be loaded, then sub-second intervals are supported, otherwise not.

This functionality, and its implementation, are experimental, and may be changed or retracted without notice. Heck, I may even go back to $TARGET, though I don't think so.

timeout

Integer, or undef

This attribute specifies the timeout for the SOAP query in seconds.

The default is 30.

trace

Boolean

If true, this Boolean attribute requests that network requests and responses be dumped to standard error. This should only be used for troubleshooting, and the author makes no representation about and has no control over what output you get if you set this true.

The default is undef (i.e. false).

units

String

This attribute specifies the desired units for the resultant elevations. Valid values are 'Feet' and 'Meters'. In practice these are not case-sensitive, and any value other than case-insensitive 'Meters' will be taken as 'Feet'.

The default is 'FEET', but this will become 'Feet' when the compatibility code goes away.

use_all_limit

Integer

This attribute is deprecated. As of version 0.115_01 any access of this attribute is fatal. See the NOTICE above for details.

usgs_url

This attribute specifies the URL to query. Under normal circumstances you will not need to change this, but maybe it can get you going again if the USGS moves the service.

The default is the value of environment variable GEO_WEBSERVICE_ELEVATION_USGS_URL. If that is undefined, the default is https://nationalmap.gov/epqs/pqs.php. Note that without query parameters this URL does nothing useful. See https://nationalmap.gov/epqs/ for details.

ACKNOWLEDGMENTS

The author wishes to acknowledge the following individuals and groups.

The members of the geo-perl mailing list provided valuable suggestions and feedback, and generally helped me thrash through such issues as how the module should work and what it should actually be called.

Michael R. Davis provided prompt and helpful feedback on a testing problem in my first module to rely heavily on Test::More.

BUGS

Bugs can be reported to the author by mail, or through http://rt.cpan.org/.

SEE ALSO

AUTHOR

Thomas R. Wyant, III; wyant at cpan dot org

COPYRIGHT AND LICENSE

Copyright (C) 2008-2019 Thomas R. Wyant, III

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.