Created
August 14, 2020 21:48
-
-
Save kensanata/5df54660bf6ac5e2420863e82f8731bc to your computer and use it in GitHub Desktop.
Geocoding: use Open Street Map for the location of a picture (e.g. from phones)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Image::ExifTool; | |
use Geo::Coder::OSM; | |
use JSON; | |
use Data::Dumper; | |
binmode(STDOUT, ':utf8'); # force UTF-8 output | |
my $geocoder = Geo::Coder::OSM->new; | |
my $exifTool = Image::ExifTool->new; | |
$exifTool->Options(CoordFormat => q{%+.6f}, | |
DateFormat => "%Y-%m-%d %H:%M:%S"); | |
for my $file (@ARGV) { | |
die "Cannot read $file" unless -f "$file"; | |
say "$file"; | |
$exifTool->ExtractInfo("$file"); | |
# Date | |
my $date = $exifTool->GetValue('CreateDate', ''); | |
say $date if $date; | |
# City | |
my $lat = $exifTool->GetValue('GPSLatitude', ''); | |
my $long = $exifTool->GetValue('GPSLongitude', ''); | |
my $location = $geocoder->reverse_geocode(lat => $lat, lon => $long); | |
die "No location data found\n" unless $geocoder->response; | |
my $json = decode_json($geocoder->response->content); | |
die $json->{error} . " $lat/$long\n" if $json->{error}; | |
say $location->{display_name} if $location; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment