NAME

Geo::GNS::Parser - parse a GNS data file

SYNOPSIS

use Geo::GNS::Parser 'parse_file';
my $in_file = 'ja.txt';
my %lines;
my $n_entries;
my $n_places;
parse_file (file => $in_file, callback => \& callback);
print "$n_entries / $n_places\n";
exit;

sub callback
{
    my (undef, $line) = @_;
    $n_entries++;
    my @parts = split /\t/, $_;
    my $ufi = $line->{UFI};
    if (my $e = $lines{$ufi}) {
        print "Duplicate $ufi for $line->{FULL_NAME_RO} $e->{FULL_NAME_RO}\n";
    }
    else {
        $lines{$ufi} = $line;
        $n_places++;
    }
}

(This example is included as synopsis.pl in the distribution.)

VERSION

This documents Geo::GNS::Parser version 0.02 corresponding to git commit dd93949b220dd7e8072228a93cebac75b6b536d3 released on Thu Jul 13 08:37:47 2017 +0900.

DESCRIPTION

Parse the GeoNET Names Server data

FUNCTIONS

parse_file

parse_file (file => 'ja.txt', data => \@array);

Parse the data in the file specified by file and put the lines into the array specified by the data parameter. Each line is added to the array as a hash reference with the keys given under "FIELDS", and the values taken from the read line.

parse_file (file => 'af.txt', callback => \& myroutine);

Parse the data in the file specified by file. As each line of data is parsed, call back the code routine specified by callback. The callback is called in the form

&{callback} (undef, \%line);

Possible options are

file

The file name. This must be supplied or the module dies.

data

An array reference.

callback

A code reference to call back. If parse_file is called as

parse_file (%inputs);

then the callback is called in the form

&{$inputs{callback}} ($inputs{callback_data}, \%line);

where %line is a hash containing the parts of the line as specified under "FIELDS".

callback_data

User-specified data to pass to the callback routine. See "callback" above.

FIELDS

The fields in the data are as follows. The meanings of each field are explained at http://geonames.nga.mil/gns/html/gis_countryfiles.html.

RC
UFI
UNI
LAT
LONG
DMS_LAT
DMS_LONG
MGRS
JOG
FC
DSG
PC
CC1
ADM1
POP
ELEV
CC2
NT
LC
SHORT_FORM
GENERIC
SORT_NAME_RO
FULL_NAME_RO
FULL_NAME_ND_RO
SORT_NAME_RG
FULL_NAME_RG
FULL_NAME_ND_RG
NOTE
MODIFY_DATE

SEE ALSO

GeoNet Names Server

http://geonames.nga.mil/gns/html/

geolocator

Geolocator is a Python project using this data.

On CPAN

As of 0.02, I am not aware of any other CPAN module which parses the GeoNET data. The following modules are related to geography.

Geo::Distance
Geo::Calc
Geo::Point
Geo::GML

HISTORY

PrePAN

I proposed this module in 2012 on PrePAN: http://prepan.org/module/429En4oFbE.

CPAN

I released this module to CPAN in July 2017.

AUTHOR

Ben Bullock, <bkb@cpan.org>

COPYRIGHT & LICENCE

This package and associated files are copyright (C) 2012-2017 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.