A wiki::toolkit plugin to manage co-ordinate data.
Access to and calculations using co-ordinate metadata supplied to a Wiki::Toolkit wiki when writing a node.
Note: This is read-only access. If you want to write to a node's metadata, you need to do it using the \*(C`write_node\*(C' method of Wiki::Toolkit.
We assume that the points are located on a flat, square grid with unit squares of side 1 metre.
use Wiki::Toolkit; use Wiki::Toolkit::Plugin::Locator::Grid;
my $wiki = Wiki::Toolkit->new( ... ); my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new; $wiki->register_plugin( plugin => $locator );
$wiki->write_node( "Jerusalem Tavern", "A good pub", $checksum, { x => 531674, y => 181950 } ) or die "argh";
# Just retrieve the co-ordinates. my ( $x, $y ) = $locator->coordinates( node => "Jerusalem Tavern" );
# Find the straight-line distance between two nodes, in metres. my $distance = $locator->distance( from_node => "Jerusalem Tavern", to_node => "Calthorpe Arms" );
# Find all the things within 200 metres of a given place. my @others = $locator->find_within_distance( node => "Albion", metres => 200 );
# Maybe our wiki calls the x and y co-ordinates something else. my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new( x => "os_x", y => "os_y", );
# By default we assume that x and y co-ordinates are stored in # metadata called "x" and "y". my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new; # But maybe our wiki calls the x and y co-ordinates something else. my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new( x => "os_x", y => "os_y", );
my $x_field = $locator->x_field; An accessor, returns the name of the metadata field used to store the x-coordinate.
my $y_field = $locator->y_field; An accessor, returns the name of the metadata field used to store the y-coordinate.
my ($x, $y) = $locator->coordinates( node => "Jerusalem Tavern" ); Returns the x and y co-ordinates stored as metadata last time the node was written.
# Find the straight-line distance between two nodes, in metres. my $distance = $locator->distance( from_node => "Jerusalem Tavern", to_node => "Calthorpe Arms" ); # Or in kilometres, and between a node and a point. my $distance = $locator->distance( from_x => 531467, from_y => 183246, to_node => "Duke of Cambridge", unit => "kilometres" ); Defaults to metres if \*(C`unit\*(C' is not supplied or is not recognised. Recognised units at the moment: \*(C`metres\*(C', \*(C`kilometres\*(C'. Returns \*(C`undef\*(C' if one of the endpoints does not exist, or does not have both co-ordinates defined. The \*(C`node\*(C' specification of an endpoint overrides the x/y co-ords if both specified (but don't do that). Note: Works to the nearest metre. Well, actually, calls \*(C`int\*(C' and rounds down, but if anyone cares about that they can send a patch.
# Find all the things within 200 metres of a given place. my @others = $locator->find_within_distance( node => "Albion", metres => 200 ); # Or within 200 metres of a given location. my @things = $locator->find_within_distance( x => 530774, y => 182260, metres => 200 ); Units currently understood: \*(C`metres\*(C', \*(C`kilometres\*(C'. If both \*(C`node\*(C' and \*(C`x\*(C'/\*(C`y\*(C' are supplied then \*(C`node\*(C' takes precedence. Croaks if insufficient start point data supplied.
Kake Pugh ([email protected]). The Wiki::Toolkit team (http://www.wiki-toolkit.org/)
Copyright (C) 2004 Kake L Pugh. All Rights Reserved. Copyright (C) 2006 the Wiki::Toolkit Team. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This module is based heavily on (and is the replacement for) Wiki::Toolkit::Plugin::Locator::UK. The following thanks are due to people who helped with Wiki::Toolkit::Plugin::Locator::UK: Nicholas Clark found a very silly bug in a pre-release version, oops :) Stephen White got me thinking in the right way to implement \*(C`find_within_distance\*(C'. Marcel Gruenauer helped me make \*(C`find_within_distance\*(C' work properly with postgres.