| Geo-Coordinates-Parser documentation | Contained in the Geo-Coordinates-Parser distribution. |
Geo::Coordinates::Parser - A coordinate parser class.
use Geo::Coordinates::Parser;
my $coordinateparser = Geo::Coordinates::Parser->new('.');
my $decimaldegree = $coordinateparser->parse(q{E25°42'60"});
$decimaldegree = $coordinateparser->parse(q{E25.12346"});
This module provides a method for parsing a coordinate string.
This module provides the following methods:
Returns a new Geo::Coordinates::Parser object. The decimal delimiter can be given as an argument. If no argument is given then period "." character is used as decimal delimiter.
Usage:
my $coordinateparser = Geo::Coordinates::Parser->new(); # or
my $coordinateparser = Geo::Coordinates::Parser->new('.'); # same as above, or
my $coordinateparser = Geo::Coordinates::Parser->new(','); # , is the decimal delimiter
Parses the coordinate string and returns it's decimal value. It uses Geo::Coordinates::DecimalDegrees to turn degrees, minutes and seconds into the equivalent decimal degree. The argument can be either a longitude or a latitude. It doesn't test the sanity of the data. The method simply removes all unnecessary characters and then converts the degrees, minutes and seconds to a decimal degree.
Usage:
my $decimal = $coordinateparser->parse('E25'42'60');
Returns the decimal delimiter. If an argument is given then it's sets the delimiter to the given value.
Usage:
$coordinateparser->decimal_delimiter; # Returns the delimiter
$coordinateparser->decimal_delimiter(','); # Sets and returns , as the delimiter
$coordinateparser->decimal_delimiter; # Returns now , as the delimiter
Carl Räihä, <carl.raiha at gmail.com>
Copyright 2005 by Carl Räihä / Frantic Media
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Geo-Coordinates-Parser documentation | Contained in the Geo-Coordinates-Parser distribution. |
package Geo::Coordinates::Parser; our $VERSION = '0.01'; use strict; use warnings; use Geo::Coordinates::DecimalDegrees qw(dms2decimal dm2decimal);
sub new { my $class = shift; my $decimal_delimiter = shift || '.'; my $self = {'decimal_delimiter' => $decimal_delimiter}; bless($self, $class); return $self; }
sub parse { my $self = shift; my $coordinatestring = shift; unless ($coordinatestring) { return undef; } # Remove all extra my $decimal_delimiter = $self->decimal_delimiter; $coordinatestring =~ s/[^0-9$decimal_delimiter]/ /g; $coordinatestring =~ s/^\s+//; $coordinatestring =~ s/\s+$//; # Split into degrees, minutes and seconds my ($degrees, $minutes, $seconds) = split(/\s+/, $coordinatestring); # Return in decimal format with the right delimiter if ($minutes and $seconds) { return dms2decimal($degrees, $minutes, $seconds); } elsif ($minutes and not $seconds) { return dm2decimal($degrees, $minutes); } else { return $degrees; } }
sub decimal_delimiter { my $self = shift; my $decimal_delimiter = shift; if ($decimal_delimiter) { $self->{'decimal_delimiter'} = $decimal_delimiter; } return $self->{'decimal_delimiter'}; } 1;