| 1 | package Geo::H3::GeoBoundary; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use base qw{Geo::H3::Base}; #provides new and ffi |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | our $VERSION = '0.04'; | ||
| 7 | our $PACKAGE = __PACKAGE__; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Geo::H3::GeoBoundary - H3 Geospatial Hexagon Indexing System | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | use Geo::H3::GeoBoundary; | ||
| 16 | my $gb = Geo::H3::GeoBoundary->new(gb=>$gb); #isa Geo::H3::GeoBoundary | ||
| 17 | my $gb = Geo::H3::GeoBoundary->new(gb=>$gb, ffi=>$ffi); #isa Geo::H3::GeoBoundary | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | Perl API to the H3 Geospatial Hexagon Indexing System. | ||
| 22 | |||
| 23 | =head1 CONSTRUCTORS | ||
| 24 | |||
| 25 | =head2 new | ||
| 26 | |||
| 27 | my $geo = Geo::H3::GeoBoundary->new(gb=>$gb); | ||
| 28 | |||
| 29 | =head1 PROPERTIES | ||
| 30 | |||
| 31 | =head2 gb | ||
| 32 | |||
| 33 | Returns the H3 GeoBoundray Object as returned from the API | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub gb {shift->{'gb'}}; | ||
| 38 | |||
| 39 | =head1 METHODS | ||
| 40 | |||
| 41 | =head2 coordinates | ||
| 42 | |||
| 43 | Returns an OGC compatible closed polygon as an array reference of hashes i.e. [{lat=>$lat, lon=>$lon}, ...]. | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub coordinates { | ||
| 48 | my $self = shift; | ||
| 49 | my @coordinates = (); | ||
| 50 | my $gb = $self->gb or die; | ||
| 51 | my $max = $gb->num_verts - 1; | ||
| 52 | foreach my $index (0 .. $max, 0) { | ||
| 53 | my $vert = $gb->verts->[$index]; | ||
| 54 | my $lat = $self->ffi->radsToDegs($vert->lat); | ||
| 55 | my $lon = $self->ffi->radsToDegs($vert->lon); | ||
| 56 | push @coordinates, {lat=>$lat, lon=>$lon}; | ||
| 57 | } | ||
| 58 | return \@coordinates; | ||
| 59 | } | ||
| 60 | |||
| 61 | =head1 SEE ALSO | ||
| 62 | |||
| 63 | L<Geo::H3>, L<Geo::H3::FFI> | ||
| 64 | |||
| 65 | =head1 AUTHOR | ||
| 66 | |||
| 67 | Michael R. Davis | ||
| 68 | |||
| 69 | =head1 COPYRIGHT AND LICENSE | ||
| 70 | |||
| 71 | MIT License | ||
| 72 | |||
| 73 | Copyright (c) 2021 Michael R. Davis | ||
| 74 | |||
| 75 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 76 | of this software and associated documentation files (the "Software"), to deal | ||
| 77 | in the Software without restriction, including without limitation the rights | ||
| 78 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 79 | copies of the Software, and to permit persons to whom the Software is | ||
| 80 | furnished to do so, subject to the following conditions: | ||
| 81 | |||
| 82 | The above copyright notice and this permission notice shall be included in all | ||
| 83 | copies or substantial portions of the Software. | ||
| 84 | |||
| 85 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 86 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 87 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 88 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 89 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 90 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 91 | SOFTWARE. | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | 1; | ||