use Geo::Proj4; my $proj = Geo::Proj4->new(proj => "merc", ellps => "clrk66", lon_0 => -96) or die "parameter error: ".Geo::Proj4->error. "\n"; my $proj = Geo::Proj4->new("+proj=merc +ellps=clrk66 +lon_0=-96") or die "parameter error: ".Geo::Proj4->error. "\n"; my ($x, $y) = $proj->forward($lat, $lon); if($proj->hasInverse) { my ($lat, $lon) = $proj->inverse($x, $y); ... } my $proj = Geo::Proj4->new(init => "epsg:26985") or die; my ($lat, $lon) = $proj->inverse(401717.80, 130013.88); my $point = [ 123.12, -5.4 ]; my $projected_point = $from->transform($to, $point); my $projected_multi = $from->transform($to, \@points);
The Open Source PROJ.4 library converts between geographic coordinate systems. It is able to convert between geodetic latitude and longitude (LL, most commonly the WGS84 projection), into an enormous variety of other cartographic projections (XY, usually UTM).
WARNING: It is not always clear what the source projection is when forward() or inverse() are used, i.e. in what projection system the source data is expected to be in. Therefore, you can better be specific on both source and destination projection and use transform().
Geo::Proj4 uses XS to wrap the PROJ.4 cartographic projections library. You will need to have the PROJ.4 library installed in order to build and use this module. You can get source code and binaries for the PROJ.4 library from its home page at http://www.remotesensing.org/proj/.
Covering all the possible projections and their arguments in PROJ.4
is well beyond the scope of this document. However, the cs2cs(1)
utility that ships with PROJ.4 will list the projections it knows about
by running cs2cs -lp, the ellipsoid models it knows with the -le
parameter, the units it knows about with -lu, and the geodetic datums
it knows with -ld. Read manual cs2cs(1) for more details.
Alternately, you can read the PROJ.4 documentation, which can be found on the project's homepage. There are links to PDFs, text documentation, a FAQ, and more.
One common source of errors is that latitude and longitude are swapped: some projection systems use lat-long, other use x-y which is a swapped order. Especially the forward() and inverse() cause this problem, always flipping the coordinate order. The transform() method is much easier: input and output in x-y/long-lat order.
Also be warned that the values must have the right sign. Make sure you give negative values for south latitude and west longitude. For calculating projections, this is more important than on maps.