Skip to content

Commit

Permalink
Fix 'Westmorland, New Brunswick, Canada
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Mar 6, 2018
1 parent ff7ea82 commit 630ceca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 4 additions & 5 deletions createdatabase.PL
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ if(my $oa = $ENV{'OPENADDR_HOME'}) {
if($file =~ /^(.+)_county.csv$/) {
$county = $1;
}
if((!defined($county)) && ($row->{'REGION'})) {
$county = $row->{'REGION'};
if((!defined($county)) && ($row->{'DISTRICT'}) && ($row->{'DISTRICT'} ne $state)) {
$county = $row->{'DISTRICT'};
}
if($county) {
$county =~ s/\s+County$//i;
Expand Down Expand Up @@ -375,8 +375,8 @@ if(my $oa = $ENV{'OPENADDR_HOME'}) {
if($file =~ /^(.+)_county.csv$/) {
$county = $1;
}
if((!defined($county)) && ($row->{'REGION'})) {
$county = $row->{'REGION'};
if((!defined($county)) && ($row->{'DISTRICT'}) && ($row->{'DISTRICT'} ne $state)) {
$county = $row->{'DISTRICT'};
}
if($county) {
$county =~ s/\s+County$//i;
Expand Down Expand Up @@ -415,7 +415,6 @@ if(my $oa = $ENV{'OPENADDR_HOME'}) {
$query =~ s/,$//;
$query .= ')';
if($query) {
# print "$query\n";
$dbh->prepare($query)->execute();
}
}
Expand Down
14 changes: 6 additions & 8 deletions lib/Geo/Coder/Free/OpenAddresses.pm
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ sub geocode {
my $location = $param{location}
or Carp::croak("Usage: geocode(location => \$location)");

::diag($location);
# ::diag($location);

if($location =~ /^(.+),\s*Washington\s*DC,(.+)$/) {
$location = "$1, Washington, DC, $2";
Expand Down Expand Up @@ -335,7 +335,6 @@ sub geocode {
$state = $twoletterstate;
}
}
::diag(">>>>>>> province: $state");
if($city !~ /,/) {
# Simple case looking up a city in a state in Canada
my $rc = $openaddr_db->fetchrow_hashref(city => uc($city), state => $state, country => 'CA');
Expand Down Expand Up @@ -444,7 +443,7 @@ sub geocode {
}

# Not been able to find in the SQLite file, look in the CSV files.
::diag("FALL THROUGH $location");
# ::diag("FALL THROUGH $location");

# TODO: this is horrible. Is there an easier way? Now that MaxMind is handled elsewhere, I hope so
if($location =~ /^([\w\s\-]+)?,([\w\s]+),([\w\s]+)?$/) {
Expand Down Expand Up @@ -564,8 +563,7 @@ sub geocode {
}
my $statedir = File::Spec->catfile($countrydir, $state);
if(-d $statedir) {
::diag('1111111111');
# if($countrycode eq 'us') {
if($countrycode eq 'us') {
# $openaddr_db = $self->{openaddr_db} ||
# Geo::Coder::Free::DB::openaddresses->new(
# directory => $self->{openaddr},
Expand All @@ -574,7 +572,9 @@ sub geocode {
# $self->{openaddr_db} = $openaddr_db;
# } else {
$openaddr_db = $self->{$statedir} || Geo::Coder::Free::DB::OpenAddr->new(directory => $statedir, table => 'statewide');
# }
} elsif($countrycode eq 'ca') {
$openaddr_db = $self->{$statedir} || Geo::Coder::Free::DB::OpenAddr->new(directory => $statedir, table => 'province');
}
if($location) {
$self->{$statedir} = $openaddr_db;
my %args = (city => uc($location));
Expand Down Expand Up @@ -611,7 +611,6 @@ sub geocode {
die $statedir;
}
} elsif($county && (-d $countrydir)) {
::diag('22222222222');
my $is_state;
my $table;
if($country =~ /^(United States|USA|US)$/) {
Expand Down Expand Up @@ -687,7 +686,6 @@ sub geocode {
}
}
} else {
::diag('333333333333');
$openaddr_db = Geo::Coder::Free::DB::OpenAddr->new(directory => $countrydir);
die $param{location};
}
Expand Down

0 comments on commit 630ceca

Please sign in to comment.