The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Geo::Formatter - Encode / decode latitude & longitude in degree to / from other format

SYNOPSIS

use Geo::Formatter;
# Export 3 functions, latlng2format, format2latlng, and alias_format.

# Encode:

# Degree format with 6 digits under the decimal point.
my ($lat,$lng) = latlng2format("degree",35,135); 
# 35.000000, 135.000000

# Signed degree format with 4 digits under the decimal point.
my ($lat,$lng) = latlng2format("degree",35,135,{sign => 1,under_decimal => 4}); 
# +35.0000, +135.0000

# Dms format with 3 digits under the decimal point in second part.
my ($lat,$lng) = latlng2format("dms",35,135); 
# 35.0.0.000, 135.0.0.000

# Dms format with zerofill and 0 digits under the decimal point in second part.
my ($lat,$lng) = latlng2format("dms",35,135,{zerofill => 1,under_decimal => 0}); 
# 35.00.00, 135.00.00

# Signed dms format with "/" as devider.
my ($lat,$lng) = latlng2format("dms",35,135,{devider => "/",sign => 1}); 
# +35/0/0.000, +135/0/0.000

# Decode:

# Dms format.
my ($lat,$lng) = format2latlng("dms","35.0.0.000","135.0.0.000"); 
# 35, 135

# Dms format with "/" as devider.
my ($lat,$lng) = format2latlng("dms","+35/00/00.000","+135/00/00.000",{devider => "/"}); 
# 35, 135

# Alias:
# You can alias any format to other name with default option

alias_format("degree8","degree",{encode =>{under_decimal => 8}});
my ($lat,$lng) = latlng2format("degree8",35,135); 
# 35.00000000, 135.00000000

alias_format("dms2","dms",{encode =>{devider=>"/",zerofill=>1},decode =>{devider=>"/"}});
my ($lat,$lng) = latlng2format("dms2",35,135); 
# 35/00/00.000, 135/00/00.000
my ($lat,$lng) = format2latlng("dms2","35/00/00.000","135/00/00.000"); 
# 35, 135

DESCRIPTION

This module provides framework of encoding/decoding latlong in degree to/from other format. Default module provide only degree and dms formats, but you can extend other formats with Geo::Formatter::Format::XXX type modules.

EXPORT

3 functions are exported.

  • latlng2format( [FORMAT],[LATITUDE],[LONGITUDE],[OPTION] )

    Return values are different by FORMAT type. If FORMAT type is single string value, function returns scalar. If FORMAT type is latitude/longitude type, function returns array (in wantarray case) or array reference. LATITUDE and LONGITUDE are latitude/longitude value in degree. OPTION is optional, and it must be hash reference. Effective OPTIONs are different by each FORMATs.

  • format2latlng( [FORMAT],[FORMAT_STR],[OPTION] )

  • format2latlng( [FORMAT],[FORMAT_LAT],[FORMAT_LNG],[OPTION] )

    Arguments are different by FORMAT type. If FORMAT type is single string value, arguments need formatted string, [FORMAT_STR]. If FORMAT type is latitude/longitude type, arguments need formatted latitude/longitude, [FORMAT_LAT] and [FORMAT_LNG]. OPTION is optional, and it must be hash reference. Effective OPTIONs are different by each FORMATs.

    Return values are latitude/longitude in degree, at array (in wantarray case) or array reference.

  • alias_format( [ALIAS],[FORMAT],[OPTION] )

    Arguments are different by FORMAT type. If FORMAT type is single string value, arguments need formatted string, [FORMAT_STR]. If FORMAT type is latitude/longitude type, arguments need formatted latitude/longitude, [FORMAT_LAT] and [FORMAT_LNG]. OPTION is optional, and it must be hash reference. Effective OPTIONs are different by each FORMATs.

    Return values are latitude/longitude in degree, at array (in wantarray case) or array reference.

CLASS METHOD

  • add_format( [FORMAT_CLASS_NAME1](,[FORMAT_CLASS_NAME2],...) )

    Add new format class to handle new format. If you want to set Geo::Formatter::Format::XXX, you should set XXX as [FORMAT_CLASS_NAME].

DEPENDENCIES

Exporter Class::Inspector UNIVERSAL::require

AUTHOR

OHTSUKA Ko-hei <nene@kokogiko.net>

LICENCE AND COPYRIGHT

Copyright (c) 2008, OHTSUKA Ko-hei <nene@kokogiko.net>.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.