Skip to content

Commit

Permalink
Started openaddresses.io support
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Feb 22, 2018
1 parent c57d0ea commit 5f45b78
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ lib/Geo/Coder/Free.pm
lib/Geo/Coder/Free/bin/db2sql
lib/Geo/Coder/Free/databases/admin1.db
lib/Geo/Coder/Free/databases/admin2.db
lib/Geo/Coder/Free/databases/cities.csv
lib/Geo/Coder/Free/databases/cities.csv.gz
lib/Geo/Coder/Free/databases/cities.sql
lib/Geo/Coder/Free/DB.pm
lib/Geo/Coder/Free/DB/admin1.pm
lib/Geo/Coder/Free/DB/admin2.pm
lib/Geo/Coder/Free/DB/cities.pm
lib/Geo/Coder/Free/DB/OpenAddr.pm
LICENSE
Makefile.PL
MANIFEST This list of files
Expand Down
23 changes: 23 additions & 0 deletions lib/Geo/Coder/Free.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use warnings;
use Geo::Coder::Free::DB::admin1;
use Geo::Coder::Free::DB::admin2;
use Geo::Coder::Free::DB::cities;
use Geo::Coder::Free::DB::OpenAddr;
use Module::Info;
use Carp;
use Error::Simple;
Expand Down Expand Up @@ -52,6 +53,7 @@ Refer to the source URL for licencing information for these files
cities.csv is from https://www.maxmind.com/en/free-world-cities-database
admin1.db is from http://download.geonames.org/export/dump/admin1CodesASCII.txt
admin2.db is from http://download.geonames.org/export/dump/admin2Codes.txt
openaddress data can be downloaded from http://results.openaddresses.io/
See also http://download.geonames.org/export/dump/allCountries.zip
Expand Down Expand Up @@ -83,6 +85,12 @@ sub new {
cache => CHI->new(driver => 'Memory', datastore => { })
});

# TODO: This has not been written yet, so it isn't documented
if(my $openaddr = $param{'openaddr'}) {
die "Can't find the directory $openaddr" if((!-d $openaddr) || (!-r $openaddr));
return bless { openaddr => $openaddr}, $class;
}

return bless { }, $class;
}

Expand Down Expand Up @@ -158,6 +166,21 @@ sub geocode {
}

if($country) {
if($self->{openaddr}) {
my $openaddr_db;
my $countrydir = File::Spec->catfile($self->{openaddr}, uc($country));
if($county && (-d $countrydir)) {
my $countydir = File::Spec->catfile($countrydir, uc($county));
if(-d $countydir) {
$openaddr_db = Geo::Coder::Free::DB::OpenAddr->new(directory => $countydir);
}
} else {
$openaddr_db = Geo::Coder::Free::DB::OpenAddr->new(directory => $countrydir);
}
if($openaddr_db) {
die "TBD";
}
}
if($state && $admin1cache{$state}) {
$concatenated_codes = $admin1cache{$state};
} elsif($admin1cache{$country} && !defined($state)) {
Expand Down
12 changes: 12 additions & 0 deletions lib/Geo/Coder/Free/DB/OpenAddr.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Geo::Coder::Free::DB::OpenAddr;

use strict;
use warnings;

# The data are from http://results.openaddresses.io/

use Geo::Coder::Free::DB;

our @ISA = ('Geo::Coder::Free::DB');

1;

0 comments on commit 5f45b78

Please sign in to comment.