| 1 | package Geo::H3::GeoBoundary; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base qw{Geo::H3::Base}; #provides new and ffi | ||
| 5 | |||
| 6 | our $VERSION = '0.10'; | ||
| 7 | our $PACKAGE = __PACKAGE__; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Geo::H3::GeoBoundary - H3 Geospatial Hexagon Indexing System GeoBoundary Object | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | use Geo::H3::GeoBoundary; | ||
| 16 | my $GeoBoundary = Geo::H3::GeoBoundary->new(gb=>$gb); #isa Geo::H3::GeoBoundary | ||
| 17 | my $GeoBoundary = Geo::H3::GeoBoundary->new(gb=>$gb, ffi=>$ffi); #isa Geo::H3::GeoBoundary | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | H3 Geospatial Hexagon Indexing System GeoBoundary Object provides coordinates method to extract data from the FFI GeoBoundary object | ||
| 22 | |||
| 23 | =head1 CONSTRUCTORS | ||
| 24 | |||
| 25 | =head2 new | ||
| 26 | |||
| 27 | my $GeoBoundary = Geo::H3::GeoBoundary->new(gb=>$gb); | ||
| 28 | |||
| 29 | =head1 PROPERTIES | ||
| 30 | |||
| 31 | =head2 gb | ||
| 32 | |||
| 33 | Returns the H3 GeoBoundary Object from the API as a L<Geo::H3::FFI::Struct::GeoBoundary> object | ||
| 34 | |||
| 35 | my $struct = $GeoBoundary->gb; #isa Geo::H3::FFI::Struct::GeoBoundary | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | sub gb {shift->{'gb'}}; | ||
| 40 | |||
| 41 | =head1 METHODS | ||
| 42 | |||
| 43 | =head2 coordinates | ||
| 44 | |||
| 45 | Returns an OGC compatible closed polygon as an array reference of hashes i.e. [{lat=>$lat, lon=>$lon}, ...]. | ||
| 46 | |||
| 47 | This coordinates format plugs directly into the format required for many L<Geo::GoogleEarth::Pluggable> objects. | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | sub coordinates { | ||
| 52 | my $self = shift; | ||
| 53 | my @coordinates = (); | ||
| 54 | my $gb = $self->gb or die; | ||
| 55 | my $max = $gb->num_verts - 1; | ||
| 56 | foreach my $j (0 .. $max, 0) { # Open Geospatial Consortium (OGC) Simple Feature Access standard | ||
| 57 | my $vert = $gb->verts->[$j]; # for a closed ring requires the first and last coordinate points | ||
| 58 | my $lat = $self->ffi->radsToDegs($vert->lat); # in the ring sequence to be identical to create a topologically | ||
| 59 | my $lon = $self->ffi->radsToDegs($vert->lon); # closed object. | ||
| 60 | push @coordinates, {lat=>$lat, lon=>$lon}; | ||
| 61 | } | ||
| 62 | return \@coordinates; | ||
| 63 | } | ||
| 64 | |||
| 65 | =head1 SEE ALSO | ||
| 66 | |||
| 67 | L<Geo::H3>, L<Geo::H3::FFI::Struct::GeoBoundary>, L<Geo::GoogleEarth::Pluggable> | ||
| 68 | |||
| 69 | =head1 AUTHOR | ||
| 70 | |||
| 71 | Michael R. Davis | ||
| 72 | |||
| 73 | =head1 COPYRIGHT AND LICENSE | ||
| 74 | |||
| 75 | MIT License | ||
| 76 | |||
| 77 | Copyright (c) 2021 Michael R. Davis | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 1; |