| 1 | #!/usr/local/bin/perl | ||
| 2 | use v5.10; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Geo::H3 0.04; | ||
| 6 | require #hide from rpmbuild | ||
| 7 | Geo::GoogleEarth::Pluggable; | ||
| 8 | require #hide from rpmbuild | ||
| 9 | Geo::GoogleEarth::Pluggable::Plugin::Styles; | ||
| 10 | require #hide from rpmbuild | ||
| 11 | Path::Class; | ||
| 12 | use Getopt::Long qw{GetOptions}; | ||
| 13 | |||
| 14 | my $lat = 38.889480654699476; | ||
| 15 | my $lon = -77.03523875953579; | ||
| 16 | my $resoultion = 8; | ||
| 17 | GetOptions( | ||
| 18 | 'lat=s' => \$lat, | ||
| 19 | 'lon=s' => \$lon, | ||
| 20 | 'resolution|res|r=s' => \$resoultion, | ||
| 21 | ); | ||
| 22 | |||
| 23 | my $gh3 = Geo::H3->new; | ||
| 24 | my $geo = $gh3->geo(lat=>$lat, lon=>$lon); | ||
| 25 | my $h3 = $geo->h3($resoultion); | ||
| 26 | my $center = $h3->geo; | ||
| 27 | |||
| 28 | my $document = Geo::GoogleEarth::Pluggable->new(name=>"Geo::H3"); | ||
| 29 | my $style_index = $document->Style(PolyStyle=>$document->AreaStyleBlue(alpha=>"20%") , LineStyle=>$document->LineStyleBlue(width=>4)); | ||
| 30 | my $style_child = $document->Style(PolyStyle=>$document->AreaStyleBlack(alpha=>"20%"), LineStyle=>$document->LineStyleBlack(width=>2)); | ||
| 31 | my $style_parent = $document->Style(PolyStyle=>$document->AreaStyleWhite(alpha=>"20%"), LineStyle=>$document->LineStyleWhite(width=>2)); | ||
| 32 | my $style_hex_ring = $document->Style(PolyStyle=>$document->AreaStyleGreen(alpha=>"20%"), LineStyle=>$document->LineStyleGreen(width=>2)); | ||
| 33 | $document->Point(name=>"Input" , lat=>$lat, lon=>$lon); | ||
| 34 | $document->Point(name=>"Center", lat=>$center->lat, lon=>$center->lon); | ||
| 35 | |||
| 36 | if ($h3->resolution > 0) { | ||
| 37 | my $folder = $document->Folder(name=>"Parent"); | ||
| 38 | my $parent = $h3->parent; | ||
| 39 | $folder->LinearRing(name=>$parent->string, coordinates=>$parent->geoBoundary->coordinates, style=>$style_parent); | ||
| 40 | } | ||
| 41 | |||
| 42 | { | ||
| 43 | my $folder = $document->Folder(name=>"Hex Ring"); | ||
| 44 | foreach my $hex (@{$h3->hexRing}) { | ||
| 45 | $folder->LinearRing(name=>$hex->string, coordinates=>$hex->geoBoundary->coordinates, style=>$style_hex_ring); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | { | ||
| 50 | my $folder = $document->Folder(name=>"Children"); | ||
| 51 | foreach my $child (@{$h3->children}) { | ||
| 52 | $folder->LinearRing(name=>$child->string, coordinates=>$child->geoBoundary->coordinates, style=>$style_child); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | $document->LinearRing(name=>$h3->string, coordinates=>$h3->geoBoundary->coordinates, style=>$style_index); | ||
| 57 | |||
| 58 | my $outfile = Path::Class::file("output.kmz"); | ||
| 59 | $outfile->spew($document->archive); | ||
| 60 | |||
| 61 | __END__ |