Yen-Ming Lee (李彥明) > Geography-NationalGrid-TW > Geography::NationalGrid::TW



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.08   Source  


Geography::NationalGrid::TW - Module to convert Taiwan Datum (TWD67/TM2, TWD97/TM2) to/from Latitude and Longitude


You should _create_ the object using the Geography::NationalGrid factory class, but you still need to know the object interface, given below.

        use Geography::NationalGrid;
        use Geography::NationalGrid::TW;
        # default TWD97
        my $point97 = new Geography::NationalGrid::TW(
                'Easting' => 302721.36,
                'Northing' => 2768851.3995,
        printf("Point 97 is %f X and %f Y\n", $point97->easting, $point97->northing);
        printf("Point 97 is %f N and %f E\n", $point97->latitude, $point97->longitude);
        # transform to TWD67
        my $point67 = $point97->transform('TWD67');


Once created, the object allows you to retrieve information about the point that the object represents. For example you can create an object using easting / northing and the retrieve the latitude / longitude.


These are the options accepted in the constructor. You MUST provide either Latitude and Longitude, or Easting and Northing.


Default is 'TWD97', the "TAIWAN DATUM 97". Another projection recognized is 'TWD67', but only 'TWD97' is tested.


There is no grid reference in Taiwan datum. Grid related functions are disabled.


The latitude of the point. Actually should be the latitude using the spheroid related to the grid projection but for most purposes the difference is not too great. Specify the amount in any of these ways: as a decimal number of degrees, a reference to an array of three values (i.e. [ $degrees, $minutes, $seconds ]), or as a string of the form '52d 13m 12s'. North is positive degrees, south is negative degrees.


As for latitude, except that east is positive degrees, west is negative degrees.


The number of metres east of the grid origin, using grid east.


The number of metres north of the grid origin, using grid north.


The value of this option is a hash-reference, which you can fill with whatever you want - typical usage might be to specify Userdata = { Name => 'Dublin Observatory' }> but add whatever you want. Access using the data() method.


Most of these methods take no arguments. Some are inherited from Geography::NationalGrid


Returns the latitude of the point in a floating point number of degrees, north being positive.


As latitude, but east is positive degrees.


How many metres east of the origin the point is. The precision of this value depends on how it was derived, but is truncated to an integer number of metres.


How many metres north of the origin the point is. The precision of this value depends on how it was derived, but is truncated to an integer number of metres.

deg2string( DEGREES )

Given a floating point number of degrees, returns a string of the form '51d 38m 34.34s'. Intended for formatting, like: $self->deg2string( $self->latitude );


Returns the item from the Userdata hash whose key is the PARAMETER_NAME.

transform( PROJECTION )

Transform the point to the new projection, i.e. TWD67 to TWD97 or reverse. Return the point after transformation and keep original point intact. Uses the formula proposed by John Hsieh which is supposed to provide 2 meter accuracy conversions.


The routines used in this code may not give you completely accurate results for various mathematical and theoretical reasons. In tests the results appeared to be correct, but it may be that under certain conditions the output could be highly inaccurate. It is likely that output accuracy decreases further from the datum, and behaviour is probably divergent outside the intended area of the grid.

This module has been coded in good faith but it may still get things wrong. Hence, it is recommended that this module is used for preliminary calculations only, and that it is NOT used under any circumstance where its lack of accuracy could cause any harm, loss or other problems of any kind. Beware!


John Hsieh -


Copyright (c) 2006 Yen-Ming Lee <>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: