| 1 | package Geo::H3; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base qw{Geo::H3::Base}; #provides new and ffi | ||
| 5 | use Geo::H3::Index; | ||
| 6 | use Geo::H3::Geo; | ||
| 7 | |||
| 8 | our $VERSION = '0.10'; | ||
| 9 | our $PACKAGE = __PACKAGE__; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | Geo::H3 - H3 Geospatial Hexagon Indexing System | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | use Geo::H3; | ||
| 18 | my $gh3 = Geo::H3->new; | ||
| 19 | |||
| 20 | my $hex = $gh3->h3(uint64 => $int); #isa Geo::H3::Index | ||
| 21 | my $hex = $gh3->h3(string => $string); #isa Geo::H3::Index | ||
| 22 | |||
| 23 | my $geo = $gh3->geo(lat=>$lat, lon=>$lon); #isa Geo::H3::Geo | ||
| 24 | my $hex = $geo->h3($resolution); #isa Geo::H3::Index | ||
| 25 | |||
| 26 | my $center = $h3->center; #isa Geo::H3::GeoCoord | ||
| 27 | my $lat = $center->lat; #isa Double WGS-84 Decimal Degrees | ||
| 28 | my $lon = $center->lon; #isa Double WGS-84 Decimal Degrees | ||
| 29 | my $distance = $center->distance($geo); #isa Double meters | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | This Perl distribution provides a Perl Object Oriented interface to the H3 Core Library. It accesses the H3 C library using L<libffi|https://github.com/libffi/libffi> and L<FFI::Platypus>. | ||
| 34 | |||
| 35 | H3 is a geospatial indexing system that partitions the world into hexagonal cells. Please note that a very few number of cells are pentagons but we use the terms hex or hexagon to include pentagons. | ||
| 36 | |||
| 37 | The H3 Core Library implements the H3 grid system. It includes functions for converting from latitude and longitude coordinates to the containing H3 cell, finding the center of H3 cells, finding the boundary geometry of H3 cells, finding neighbors of H3 cells, and more. | ||
| 38 | |||
| 39 | The H3 Core Library can be installed from Uber's H3 repository on GitHub L<https://github.com/uber/h3> which is well documented at L<https://h3geo.org/docs/>. | ||
| 40 | |||
| 41 | =head2 CONVENTIONS | ||
| 42 | |||
| 43 | The Geo::H3 lib is an Object Oriented wrapper on top of the L<Geo::H3::FFI> library. Geo::H3 was written as a wrapper so that in the future we are able to re-write against different backends such as the yet to be developed Geo::H3::XS backend. | ||
| 44 | |||
| 45 | =head3 libh3 | ||
| 46 | |||
| 47 | - Latitude and longitude cordinates are in radians WGS-84 | ||
| 48 | - H3 Index values are handled as uint64 integers | ||
| 49 | - GeoCoord values are handled as C structures with lat and lon | ||
| 50 | - GeoBoundary values are handled as C structures with num_verts and verts | ||
| 51 | |||
| 52 | =head3 Geo::H3::FFI | ||
| 53 | |||
| 54 | - Latitude and Longitude cordinates are in radians WGS-84 | ||
| 55 | - H3 Index values are handled as uint64 integers | ||
| 56 | - GeoCoord values are handled as Geo::H3::FFI::Struct::GeoCoord objects | ||
| 57 | - GeoBoundary values are handled as Geo::H3::FFI::Struct::GeoBoundary objects | ||
| 58 | |||
| 59 | =head3 Geo::H3 | ||
| 60 | |||
| 61 | - Latitude and longitue cordinates are in decimal degrees WGS-84 | ||
| 62 | - H3 Index values are handled as Geo::H3::Index objects | ||
| 63 | - GeoCoord values are handled as Geo::H3::GeoCoord objects | ||
| 64 | - GeoBoundary values are handled as Geo::H3::GeoBoundary objects | ||
| 65 | |||
| 66 | =head1 CONSTRUCTORS | ||
| 67 | |||
| 68 | =head2 h3 | ||
| 69 | |||
| 70 | Returns a L<Geo::H3::Index> object | ||
| 71 | |||
| 72 | my $hex = $gh3->h3(unit64 => $int); #isa Geo::H3::Index | ||
| 73 | my $hex = $gh3->h3(string => $string); #isa Geo::H3::Index | ||
| 74 | my $hex = Geo::H3::Index->new(uint64 => $h3_uint64); #isa Geo::H3::Index | ||
| 75 | my $hex = Geo::H3::Index->new(string => $h3_string); #isa Geo::H3::Index | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | sub h3 { | ||
| 80 | my $self = shift; | ||
| 81 | my %data = @_; | ||
| 82 | $data{'ffi'} = $self->ffi unless exists $data{'ffi'}; | ||
| 83 | return Geo::H3::Index->new(%data); | ||
| 84 | } | ||
| 85 | |||
| 86 | =head2 geo | ||
| 87 | |||
| 88 | Returns a L<Geo::H3::Geo> object | ||
| 89 | |||
| 90 | my $geo = $gh3->geo(lat=>$lat_deg, lon=>$lon_deg); #isa Geo::H3::Geo | ||
| 91 | my $geo = Geo::H3::Geo->new(lat=>$lat_deg, lon=>$lon_deg); #isa Geo::H3::Geo | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | sub geo { | ||
| 96 | my $self = shift; | ||
| 97 | my %data = @_; | ||
| 98 | $data{'ffi'} = $self->ffi unless exists $data{'ffi'}; | ||
| 99 | return Geo::H3::Geo->new(%data); | ||
| 100 | }; | ||
| 101 | |||
| 102 | =head2 ffi | ||
| 103 | |||
| 104 | Returns the L<Geo::H3::FFI> object. | ||
| 105 | |||
| 106 | =head1 LIMITATIONS | ||
| 107 | |||
| 108 | This package uses the naming convention of version 3.x of the Uber H3 library. The organization that maintains the open source Uber H3 library has not maintained backward compatibility in version 4.x. This Perl distribution currently sees no reason to support the 4.x version of the Uber H3 library as the 3.7.2 release is stable and full featured. | ||
| 109 | |||
| 110 | =head1 SEE ALSO | ||
| 111 | |||
| 112 | L<https://h3geo.org/docs/3.x/>, L<https://github.com/uber/h3/tree/stable-3.x>, L<Geo::H3::FFI> | ||
| 113 | |||
| 114 | =head1 AUTHOR | ||
| 115 | |||
| 116 | Michael R. Davis | ||
| 117 | |||
| 118 | =head1 COPYRIGHT AND LICENSE | ||
| 119 | |||
| 120 | MIT License | ||
| 121 | |||
| 122 | Copyright (c) 2021 Michael R. Davis | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | 1; |