| 1 | package Geo::H3::Geo; | ||
| 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, ffi, and Geo::H3::FFI::Struct::GeoCoord |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | require Geo::H3::Index; | ||
| 6 | |||
| 7 | our $VERSION = '0.04'; | ||
| 8 | our $PACKAGE = __PACKAGE__; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Geo::H3::Geo - H3 Geospatial Hexagon Indexing System | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | use Geo::H3::Geo; | ||
| 17 | my $geo = Geo::H3::Geo->new(lat=>$lat, lon=>$lon); #isa Geo::H3::Geo | ||
| 18 | my $h3 = $geo->h3($resolution); #isa Geo::H3::Index | ||
| 19 | my $center = $h3->center; #isa Geo::H3::Geo | ||
| 20 | my $lat = $center->lat; #isa double WGS-84 Decimal Degrees | ||
| 21 | my $lon = $center->lon; #isa double WGS-84 Decimal Degrees | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | Perl API to the H3 Geospatial Hexagon Indexing System. | ||
| 26 | |||
| 27 | =head1 CONSTRUCTORS | ||
| 28 | |||
| 29 | =head2 new | ||
| 30 | |||
| 31 | my $geo = Geo::H3::Geo->new(lat => $lat, lon => $lon); | ||
| 32 | |||
| 33 | =head1 PROPERTIES | ||
| 34 | |||
| 35 | =head2 lat | ||
| 36 | |||
| 37 | Returns the latitude in degrees | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub lat {shift->{'lat'}}; | ||
| 42 | |||
| 43 | =head2 lon | ||
| 44 | |||
| 45 | Returns the longitude in degrees | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub lon {shift->{'lon'}}; | ||
| 50 | |||
| 51 | =head1 METHODS | ||
| 52 | |||
| 53 | =head2 struct | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub struct { | ||
| 58 | my $self = shift; | ||
| 59 | my $lat = $self->ffi->degsToRads($self->lat); | ||
| 60 | my $lon = $self->ffi->degsToRads($self->lon); | ||
| 61 | return Geo::H3::FFI::Struct::GeoCoord->new({lat=>$lat, lon=>$lon}); | ||
| 62 | } | ||
| 63 | |||
| 64 | =head2 h3 | ||
| 65 | |||
| 66 | Indexes the location at the specified resolution, returning the index object L<Geo::H3::Index> of the cell containing the location. | ||
| 67 | |||
| 68 | my $h3 = $geo->h3; #default resolution is 0 | ||
| 69 | my $h3 = $geo->h3(7); #isa Geo::H3::H3Index | ||
| 70 | |||
| 71 | Returns undef on error. | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub h3 { | ||
| 76 | my $self = shift; | ||
| 77 | my $res = shift || 0; | ||
| 78 | my $index = $self->ffi->geoToH3Wrapper(lat=>$self->lat, lon=>$self->lon, resolution=>$res, uom=>"deg") | ||
| 79 | or die("Error: API geoToH3Wrapper return index invalid"); | ||
| 80 | return Geo::H3::Index->new(index=>$index); | ||
| 81 | } | ||
| 82 | |||
| 83 | =head2 distance | ||
| 84 | |||
| 85 | Returns in meters the "great circle" or "haversine" distance between pairs of points (lat/lon pairs). | ||
| 86 | |||
| 87 | my $distance = $geoA->distance($geoB); #isa Double | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | sub distance { | ||
| 92 | my $a = shift; | ||
| 93 | my $b = shift or die("Error: package $PACKAGE method pointDistM requires a distination point"); | ||
| 94 | my $distance = $a->ffi->pointDistM($a->struct, $b->struct); | ||
| 95 | return $distance; | ||
| 96 | } | ||
| 97 | |||
| 98 | =head1 SEE ALSO | ||
| 99 | |||
| 100 | L<Geo::H3>, L<Geo::H3::FFI> | ||
| 101 | |||
| 102 | =head1 AUTHOR | ||
| 103 | |||
| 104 | Michael R. Davis | ||
| 105 | |||
| 106 | =head1 COPYRIGHT AND LICENSE | ||
| 107 | |||
| 108 | MIT License | ||
| 109 | |||
| 110 | Copyright (c) 2021 Michael R. Davis | ||
| 111 | |||
| 112 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 113 | of this software and associated documentation files (the "Software"), to deal | ||
| 114 | in the Software without restriction, including without limitation the rights | ||
| 115 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 116 | copies of the Software, and to permit persons to whom the Software is | ||
| 117 | furnished to do so, subject to the following conditions: | ||
| 118 | |||
| 119 | The above copyright notice and this permission notice shall be included in all | ||
| 120 | copies or substantial portions of the Software. | ||
| 121 | |||
| 122 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 123 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 124 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 125 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 126 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 127 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 128 | SOFTWARE. | ||
| 129 | |||
| 130 | =cut | ||
| 131 | |||
| 132 | 1; | ||