=head1 NAME Geo::Proj4 - PROJ.4 cartographic projections library =head1 INHERITANCE Geo::Proj4 is a DynaLoader =head1 SYNOPSIS 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 $proj = Geo::Proj4->new(init => "epsg:28992"); 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); =head1 DESCRIPTION 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 L or L 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 L. =head1 METHODS =head2 Instantiation =over 4 =item Geo::Proj4-EB(STRING|OPTIONS) The object defines the target projection, but that's easier said than done: projections have different parameter needs. The parameters which can (or need to) be used are listed with C. The manual page of C explains how the configuration works. Two ways are provided to define the projection. Either, use a list of OPTIONS, which are pairs of parameters, or pass one string which contains all parameters at once. You must supply a C parameter. In case of an OPTION list: WARNING: Specify boolean parameters (e.g. the south parameter to the UTM projection) with a matching value of undef. example: my $proj = Geo::Proj4->new(proj => "merc", ellps => "clrk66", lon_0 => -96 ) or die Geo::Proj4->error; my $proj = Geo::Proj4->new("+proj=merc +ellps=clrk66 +lon_0=096") or die Geo::Proj4->error; my $proj = Geo::Proj4->new(init => "epsg:$epsg"); =back =head2 Accessors =over 4 =item $obj-EB() Tries to return a datum name for this projection. =item $obj-EB() Write the definition in extended form to stdout. This output cannot be caught, because it is done on stdio level, below the reach of PerlIO. =item Geo::Proj4-EB() Returns a dualvar (see Scalar::Util) containing the error number and error string of the last reported error. example: my $proj = Geo::Proj4->new(...); unless(defined $proj) { my $error = Geo::Proj4->error; warn "error-code: ".$error+0; warn "error-string: $error\n"; } =item $obj-EB() Returns whether the reverse function for the projection exists. Some projections are one-way. =item $obj-EB() Returns true when the source projection is using a geocentric coordinate system; i.e. uses x-y coordinates. =item $obj-EB() Returns true when the source projection is using a geodetic coordinate system; i.e. uses lat long coordinates. Same as L =item $obj-EB() Returns true when the source projection is using a geodetic coordinate system; i.e. uses lat long coordinates. Same as L. =item $obj-EB() Returns a string which is produced by the library based on the data extracted from the initiation parameters. This string may be more explicit than the passed values, and could be used for debugging. =item $obj-EB() Returns the projection type. =back =head2 Converters =over 4 =item $obj-EB(LATITUDE, LONGITUDE) Perform a forward projection from LATITUDE and LONGITUDE (LL) to the cartographic projection (XY) represented by the Geo::Proj4 instance. WARNING: for historic reasons, latitude and longitude are assumed to be in (floating point) degrees, although the library expects rads. See L. A latitude south of the Equator and longitude west of the Prime Meridian given with negative values. Returned are two values, usually X and Y in meters, or whatever units are relevant to the given projection. When the destination projection also than the order of parameters will be returned as LONG,LAT (not lat,long!) On error, C will return undef for both values. example: my ($x, $y) = $proj->forward($lat, $lon); my ($long2, $lat2) = $proj->forward($lat, $lon); =item $obj-EB(LATITUDE, LONGITUDE) Perform a forward projection from LATITUDE and LONGITUDE (LL) to the cartographic projection (XY) represented by the Geo::Proj4 instance. This function reflects to library function C, expecting radians, not degrees. =item $obj-EB((X,Y) | (LAT|LONG)) Perform an inverse projection from the (cartographic) projection represented by this Geo::Proj4 object, back into latitude and longitude values. WARNING: for historic reasons, latitude and longitude are assumed to be in (floating point) degrees, although the library expects rads. See L. On error, C will return undef for both values. example: if($proj->hasInverse) { my ($lat, $lon) = $proj->inverse($x, $y); ... } =item $obj-EB((X,Y) | (LAT|LONG)) Perform an inverse projection from the (cartographic) projection represented by this Geo::Proj4 object, back into latitude and longitude values. Latitude and longitude are assumed to be in radians. See L. =item $obj-EB(TO, POINT|ARRAY-OF-POINTS) Translate the POINTS into the projecten of TO. Each point is specified as two or three values in an ARRAY. In case of latlong source or destination projections, coordinates are translated into radians and/or back. Both input and output values are always in X-Y/LongLat order. See L example: my $from = Geo::Proj4->new("+proj=latlong +datum=NAD83"); my $to = Geo::Proj4->new("+proj=utm +zone=10 +datum=WGS84"); my $point = [ 1.12, 3.25 ]; # See Geo::Point my $pr_point = $from->transform($to, $point); my $pr = $from->transform($to, [ $point1, $point2 ]); my $pr_point1 = $pr->[0]; my $pr_point2 = $pr->[1]; =item $obj-EB(TO, POINT|ARRAY-OF-POINTS) Translate the POINTS into the projecten of TO. Each point is specified as two or three values in an ARRAY. In case of latlong source or destination projections, coordinates are expected to be in radians. Both input and output values are always in X-Y/LongLat order. See L =back =head2 Library introspection =over 4 =item Geo::Proj4-EB(LABEL) Returns a hash with information about the specified datum. With L, all defined LABELS can be found. =item Geo::Proj4-EB(LABEL) Returns a hash with information about the specified ellipsis. With L, all defined LABELS can be found. =item $obj-EB() =item Geo::Proj4-EB() Returns the version of the proj4 library =item Geo::Proj4-EB() Returns a list with all defined datum labels. example: foreach my $id (Geo::Proj4->listDatums) { my $def = Geo::Proj4->datum($id); print "$id = $def->{ellips_id}\n"; } =item Geo::Proj4-EB() Returns a list with all defined ellips labels. example: foreach my $id (Geo::Proj4->listEllipsoids) { my $def = Geo::Proj4->ellipsoid($id); print "$id = $def->{name}\n"; } =item Geo::Proj4-EB() Returns a list with all defined projection types. example: foreach my $id (Geo::Proj4->listTypes) { my $def = Geo::Proj4->type($id); print "$id = $def->{description}\n"; } =item Geo::Proj4-EB() Returns a list with all defined unit labels. example: foreach my $id (Geo::Proj4->listUnits) { my $def = Geo::Proj4->unit($id); print "$id = $def->{name}\n"; } =item Geo::Proj4-EB(LABEL) Returns a hash with information about the specified projection type. With L, all defined LABELS can be found. =item Geo::Proj4-EB(LABEL) Returns a hash with information about the specified unit. With L, all defined LABELS can be found. =back =head1 DETAILS =head2 Install 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 L. =head2 Projections Covering all the possible projections and their arguments in PROJ.4 is well beyond the scope of this document. However, the C utility that ships with PROJ.4 will list the projections it knows about by running B, the ellipsoid models it knows with the B<-le> parameter, the units it knows about with B<-lu>, and the geodetic datums it knows with B<-ld>. Read L 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. =head2 Bugs 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 L and L cause this problem, always flipping the coordinate order. The L 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. =head1 DIAGNOSTICS =over 4 =item Error: transform() expects array of points =item Error: transformRad() expects array of points =back =head1 REFERENCES See the Geo::Point website at L for an html version of this and related modules; L, L, L and L Effusive thanks to Frank Warmerdam (maintainer of PROJ.4) and Gerald Evenden (main contributor of PROJ.4). Their PROJ.4 library home page: L proj(1), cs2cs(1), pj_init(3). =head1 COPYRIGHTS Developed and maintained by Mark Overmeer Egeo@overmeer.netE. Copyright (c) 2004-2007 by the authors. All rights reserved. Originally Written by Schuyler Erle Eschuyler@nocat.netE and Rich Gibson Erich@nocat.netE. Their site: Mapping Hacks home page: L =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.