Database-BI
view release on metacpan or search on metacpan
lib/Database/BI/Model/Boundary.pm view on Meta::CPAN
}
=head2 level_name
my $word = Database::BI::Model::Boundary->level_name('state'); # 'state'
=head3 API SPECIFICATION
=head4 INPUT
level : string, one of levels()
=head4 OUTPUT
What the level's areas are called where no country says otherwise, as
L</name_for> gives it: the word to use before a point's country is known.
Undef for a level that is not one.
=cut
sub level_name {
my (undef, $level) = @_;
return unless defined($level) && !ref($level) && $LEVELS{$level};
return $LEVELS{$level}{name};
}
=head2 levels
my @levels = Database::BI::Model::Boundary->levels;
# ('country', 'state', 'county', 'city', 'town', 'neighbourhood')
=head3 API SPECIFICATION
=head4 INPUT
None.
=head4 OUTPUT
The names of the levels new() takes, the largest area first.
=cut
sub levels {
return @LEVEL_ORDER;
}
=head2 point_key
my $key = Database::BI::Model::Boundary->point_key(39.0901, -77.6402); # '39.090,-77.640'
=head3 API SPECIFICATION
=head4 INPUT
lat : number -90 .. 90
lon : number -180 .. 180
Domains: each is a plain decimal, an optional minus and ASCII digits with an
optional fraction (1, -1.5, 12.345678). A plus sign, a bare point (.5, 5.),
an exponent, spaces, a newline, a comma, NaN, Inf and non-ASCII digits are
not numbers here. The edges -90, 90, -180 and 180 are in; anything past
them, however slightly (90.0001), is out, even if it would round to an edge.
=head4 OUTPUT
The point rounded to three decimal places, as C<"lat,lon">: what the cache is
keyed by and all of the point that is sent. Undef for a point out of range.
=cut
sub point_key {
my (undef, $lat, $lon) = @_;
return unless defined($lat) && defined($lon)
&& $lat =~ /\A-?[0-9]+(?:\.[0-9]+)?\z/ && $lon =~ /\A-?[0-9]+(?:\.[0-9]+)?\z/
&& abs($lat) <= 90 && abs($lon) <= 180;
my @parts = map {
my $text = sprintf("%.${DECIMALS}f", $_);
$text =~ s/\A-(?=0\.0+\z)//; # no "-0.000", so a point has one key
$text;
} ($lat, $lon);
return join(',', @parts);
}
=head2 outlines
my $result = $boundary->outlines(\@points, lookup => 1);
=head3 API SPECIFICATION
=head4 INPUT
points : arrayref of [lat, lon]
lookup : boolean, default 1. 0 asks Nominatim nothing: the points not
known yet come back in pending, for the caller to look up one at
a time (lookup_point)
=head4 OUTPUT
{
features => [ GeoJSON Feature, ... ] one per outline, in the order
their first point came; properties { name, osm, called }
(called: what the division is called there, as name_for)
pending => [ point_key, ... ] points not known, not asked
inside => { point_key => osm, ... } the outline each point drawn is in,
by the osm of its Feature (to total what is in each)
counts => { points, drawn, attempted, nowhere }
offline => 0|1 points were left because Nominatim may not be asked
failed => 0|1 Nominatim did not answer; the rest were left
}
A point out of range is ignored. A Feature's name is the place's name as
OpenStreetMap has it: text, not HTML.
=cut
sub outlines {
my ($self, $points, @rest) = @_;
croak 'outlines() needs an arrayref of [lat, lon]' unless ref($points) eq 'ARRAY';
( run in 1.051 second using v1.01-cache-2.11-cpan-60884a8df76 )