diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-07-12 19:23:16 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-07-12 19:23:16 +0100 |
commit | 8490c84456f437c50f3075f5b44cfa2e726337ab (patch) | |
tree | ae7f7975f921689f77dde80999c60822368a6658 /perllib | |
parent | d2d54ea0d9844833ab8544c3df34f9043b21a6a7 (diff) |
Get OSM lookup hopefully working, does #95 except for bin scripts.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FiksGataMi.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/OSM.pm | 37 |
2 files changed, 22 insertions, 32 deletions
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm index 3ba449a33..7251f2c6a 100644 --- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm +++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm @@ -92,6 +92,23 @@ sub find_closest { return FixMyStreet::Geocode::OSM::closest_road_text( $self, $latitude, $longitude ); } +# Used by send-reports, calling find_closest, calling OSM geocoding +sub guess_road_operator { + my ( $self, $inforef ) = @_; + + my $highway = $inforef->{highway} || "unknown"; + my $refs = $inforef->{ref} || "unknown"; + + return "Statens vegvesen" + if $highway eq "trunk" || $highway eq "primary"; + + for my $ref (split(/;/, $refs)) { + return "Statens vegvesen" + if $ref =~ m/E ?\d+/ || $ref =~ m/Fv\d+/i; + } + return ''; +} + sub remove_redundant_councils { my $self = shift; my $all_councils = shift; diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm index fad5baf45..77c04503c 100644 --- a/perllib/FixMyStreet/Geocode/OSM.pm +++ b/perllib/FixMyStreet/Geocode/OSM.pm @@ -70,44 +70,17 @@ sub get_object_tags { return _osmxml_to_hash($result, $type); } -sub guess_road_operator { - my $inforef = shift; - my $highway = $inforef->{highway} || "unknown"; - my $refs = $inforef->{ref} || "unknown"; - - my $operator; - if ( mySociety::Config::get('COUNTRY') eq 'NO' ) { - if ($highway eq "trunk" - || $highway eq "primary" - ) { - $operator = "Statens vegvesen"; - } - unless (defined $operator) { - for my $ref (split(/;/, $refs)) { - if ($ref =~ m/E ?\d+/ - || $ref =~ m/Fv\d+/i - ) { - $operator = "Statens vegvesen"; - } - } - } - } - return $operator; -} - # A better alternative might be # http://www.geonames.org/maps/osm-reverse-geocoder.html#findNearbyStreetsOSM sub get_nearest_road_tags { - my ($latitude, $longitude) = @_; + my ( $cobrand, $latitude, $longitude ) = @_; my $inforef = lookup_location($latitude, $longitude, 16); if (exists $inforef->{result}->{osm_type} && 'way' eq $inforef->{result}->{osm_type}) { my $osmtags = get_object_tags('way', $inforef->{result}->{osm_id}); - if (mySociety::Config::get('OSM_GUESS_OPERATOR') - && !exists $osmtags->{operator}) { - my $guess = guess_road_operator($osmtags); - $osmtags->{operatorguess} = $guess if $guess; + unless ( exists $osmtags->{operator} ) { + $osmtags->{operatorguess} = $cobrand->guess_road_operator( $osmtags ); } return $osmtags; } @@ -115,9 +88,9 @@ sub get_nearest_road_tags { } sub closest_road_text { - my ($latitude, $longitude) = @_; + my ( $cobrand, $latitude, $longitude ) = @_; my $str = ''; - my $osmtags = get_nearest_road_tags($latitude, $longitude); + my $osmtags = get_nearest_road_tags( $cobrand, $latitude, $longitude ); if ($osmtags) { my ($name, $ref) = ('',''); $name = $osmtags->{name} if exists $osmtags->{name}; |