Changeset 168


Ignore:
Timestamp:
Jun 12, 2004, 9:14:45 PM (17 years ago)
Author:
kake
Message:

->find_within_distance can now take lat and long

Location:
cgi-wiki-plugin-locator-uk/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cgi-wiki-plugin-locator-uk/trunk/Changes

    r166 r168  
     10.08    12 June 2004
     2        ->find_within_distance now accepts "lat" and "long" arguments.
     3          Internally everything is still done in terms of OS X and Y.
     4
    150.07    3 September 2003
    26        Fixed bug in ->find_within_distance where nodes with identical
  • cgi-wiki-plugin-locator-uk/trunk/MANIFEST

    r166 r168  
    99t/02_locator.t
    1010t/03_same_coords_bug.t
     11t/04_lat_long.t
     12META.yml                                 Module meta-data (added by MakeMaker)
  • cgi-wiki-plugin-locator-uk/trunk/Makefile.PL

    r159 r168  
    44               VERSION_FROM => "lib/CGI/Wiki/Plugin/Locator/UK.pm",
    55               PREREQ_PM    => { 'CGI::Wiki' => 0.36, # for Plugin base class
     6                                 'Geography::NationalGrid' => 0,
     7                                 'Geography::NationalGrid::GB' => 0,
    68                                 'Test::More' => 0,
    79                                 'Carp' => 0
  • cgi-wiki-plugin-locator-uk/trunk/README

    r159 r168  
    1212    metadata, you need to do it using the "write_node" method of CGI::Wiki.
    1313
    14 SYNOPSIS
    15       use CGI::Wiki;
    16       use CGI::Wiki::Plugin::Locator::UK;
    17 
    18       my $wiki = CGI::Wiki->new( ... );
    19       my $locator = CGI::Wiki::Plugin::Locator::UK->new;
    20       $wiki->register_plugin( $locator );
    21 
    22       $wiki->write_node( "Jerusalem Tavern",
    23                          "A good pub",
    24                          $checksum,
    25                          { os_x => 531674,
    26                            os_y => 181950
    27                          }
    28                         );
    29 
    30       # Just retrieve the co-ordinates.
    31       my ( $x, $y ) = $locator->coordinates( node => "Jerusalem Tavern" );
    32 
    33       # Find the straight-line distance between two nodes, in kilometres.
    34       my $distance = $locator->distance( from_node => "Jerusalem Tavern",
    35                                          to_node   => "Calthorpe Arms" );
    36 
    37       # Find all the things within 200 metres of a given place.
    38       my @others = $locator->find_within_distance( node   => "Albion",
    39                                                    metres => 200 );
    40 
    41 METHODS
    42     new
    43           my $locator = CGI::Wiki::Plugin::Locator::UK->new;
    44 
    45     coordinates
    46           my ($x, $y) = $locator->coordinates( node => "Jerusalem Tavern" );
    47 
    48         Returns the OS x and y co-ordinates stored as metadata last time the
    49         node was written.
    50 
    51     distance
    52           # Find the straight-line distance between two nodes, in kilometres.
    53           my $distance = $locator->distance( from_node => "Jerusalem Tavern",
    54                                              to_node   => "Calthorpe Arms" );
    55 
    56           # Or in metres between a node and a point.
    57           my $distance = $locator->distance(from_os_x => 531467,
    58                                             from_os_y => 183246,
    59                                             to_node   => "Duke of Cambridge",
    60                                             unit      => "metres" );
    61 
    62         Defaults to kilometres if "unit" is not supplied or is not
    63         recognised. Recognised units at the moment: "metres", "kilometres".
    64 
    65         Returns "undef" if one of the endpoints does not exist, or does not
    66         have both co-ordinates defined. The "node" specification of an
    67         endpoint overrides the x/y co-ords if both specified (but don't do
    68         that).
    69 
    70         Note: Works to the nearest metre. Well, actually, calls "int" and
    71         rounds down, but if anyone cares about that they can send a patch.
    72 
    73     find_within_distance
    74           # Find all the things within 200 metres of a given place.
    75           my @others = $locator->find_within_distance( node   => "Albion",
    76                                                        metres => 200 );
    77 
    78           # Or within 200 metres of a given location.
    79           my @things = $locator->find_within_distance( os_x => 530774,
    80                                                        os_y => 182260,
    81                                                        metres => 200 );
    82 
    83         Units currently understood: "metres", "kilometres". If both "node"
    84         and "os_x"/"os_y" are supplied then "node" takes precedence. Croaks
    85         if insufficient start point data supplied.
    86 
    87 SEE ALSO
    88         * CGI::Wiki
    89         * Geography::NationalGrid
    90         * My test wiki that uses this plugin -
    91         <http://the.earth.li/~kake/cgi-bin/cgi-wiki/wiki.cgi>
    92 
    93 AUTHOR
    94         Kake Pugh (kake@earth.li).
    95 
    96 COPYRIGHT
    97              Copyright (C) 2003 Kake Pugh.  All Rights Reserved.
    98 
    99         This module is free software; you can redistribute it and/or modify
    100         it under the same terms as Perl itself.
    101 
    102 CREDITS
    103         Nicholas Clark found a very silly bug in a pre-release version, oops
    104         :) Stephen White got me thinking in the right way to implement
    105         "find_within_distance". Marcel Gruenauer helped me make
    106         "find_within_distance" work properly with postgres.
    107 
  • cgi-wiki-plugin-locator-uk/trunk/lib/CGI/Wiki/Plugin/Locator/UK.pm

    r166 r168  
    44
    55use vars qw( $VERSION @ISA );
    6 $VERSION = '0.07';
     6$VERSION = '0.08';
    77
    88use Carp qw( croak );
    99use CGI::Wiki::Plugin;
     10use Geography::NationalGrid;
     11use Geography::NationalGrid::GB;
    1012
    1113@ISA = qw( CGI::Wiki::Plugin );
     
    164166sub find_within_distance {
    165167    my ($self, %args) = @_;
    166 
    167168    my $store = $self->datastore;
    168169    my $dbh = eval { $store->dbh; }
     
    176177    } elsif ( $args{os_x} and $args{os_y} ) {
    177178        ($sx, $sy) = @args{ qw( os_x os_y ) };
     179    } elsif ( $args{lat} and $args{long} ) {
     180        my $point = Geography::NationalGrid::GB->new(
     181                                                      Latitude  => $args{lat},
     182                                                      Longitude => $args{long},
     183                                                    );
     184        $sx = $point->easting;
     185        $sy = $point->northing;
    178186    } else {
    179187        croak "Insufficient start location data supplied";
     
    198206        $sql =~ s/metadata_value/metadata_value::integer/gs;
    199207    }
    200 
    201208    my $sth = $dbh->prepare($sql);
    202209    $sth->execute;
Note: See TracChangeset for help on using the changeset viewer.