[OSRS-PROJ] Uk Grid projection

Frank Warmerdam warmerdam at pobox.com
Tue Feb 17 07:47:11 PST 2004


Tim Sutton wrote:
> Hi 
> 
> I have two questions:
> 
> 1) I would like to convert  coordinates from UK National Grid to lat/long. 
>>From the proj manual and ordinance survey information, I calculate the input 
> projection definition to be:
> 
> +proj=tmerc +lat_0=49n +lon_0=2w +k=0.9996012717 +ellps=airy +a=677563.396 
> +b=6356256.910
> 
> How would I specify that I want the output coordinates to be in lat/long using 
> proj on the command line.?

Tim,

The proj command always converts between the projected coordinate system you
specify, and lat/long coordinates on the same ellipsoid.   So, no need to
specify anything special.

Note, I tried your formulation which duplicates the ellipsoid information
between the +ellps and the +a/+b and got:

warmerda at gdal2200[40]% proj +proj=tmerc +lat_0=49n +lon_0=2w +k=0.9996012717 +ellps=airy +a=677563.396 +b=6356256.910
Rel. 4.4.7, 31 March 2003
<proj>:
projection initialization failure
cause: squared eccentricity < 0
program abnormally terminated

With just the following things seem to work fine:
warmerda at gdal2200[41]% proj +proj=tmerc +lat_0=49n +lon_0=2w +k=0.9996012717 +ellps=airy

By default proj converts from lat/long values to projected coordinates.  To go
from projected coordinates to lat/long supply the -I (inverse) parameter.

I would add that your coordinate system definition is lacking the false easting
and north required for the British National Grid.  If we use EPSG code 27700
(OSGB 1936 / British National Grid) we get:

warmerda at gdal2200[44]% proj -v +init=epsg:27700
#Transverse Mercator
#       Cyl, Sph&Ell
# +init=epsg:27700 +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000
# +y_0=-100000 +ellps=airy +units=m +no_defs

> 2) Is there a simple 'hello world' c++ example that demonstrates the libproj 
> programmatic interface, as I need to do the above process programmatically.
> 
> I am woking on suse linux 9.0

The proj_init() man page includes the following simple "old style API"
example for going from lat/long to projected coordinates.

        #include <proj_api.h>

        main(int argc, char **argv) {
             char *args[] = { "proj=merc", "ellps=clrk66", "lat_ts=33" };
             projUV p;
             projPJ pj;

             if (!(pj = pj_init(3, args)))
                exit(1);
             while (scanf("%lf %lf", &p.v, &p.u) == 2) {
                p.u *= DEG_TO_RAD;
                p.v *= DEG_TO_RAD;
                p = pj_fwd(p, pj);
                printf("%.2f\t%.2f\n", p.u, p.v);
             }
             exit(0);
        }

To go the other way, use pj_inv() instead of pj_fwd() and apply the RAD_TO_DEG
translation to the result after pj_inv() instead of the reverse before.  The
angles accepted and produced by the API entry points are always in radians.

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

----------------------------------------
PROJ.4 Discussion List
See http://www.remotesensing.org/proj for subscription, unsubscription
and other information.



More information about the Proj mailing list