[Proj] please help C++ idiot with datum conversion

Mike Zulauf mazulauf at met.utah.edu
Thu Jul 15 18:26:38 EDT 2004


Frank already answered this, but I thought I'd add my points.

I suppose it might depend on your platform (?), but on the two 
unix-like OSs I built the libraries on (Mac OS X and Linux), I only had 
to extract the contents of proj-nad27-1.1.tar into the proj/nad 
directory, and then reconfigure and rebuild the library.

Before that point, the code would run, but without the datum shift.  
Afterwards, the datum shift occurs as it should.

And if anybody is interested, at the bottom of this message is the 
final version of the code snippet that I'm using now.  I had to correct 
a couple minor issues of Frank's code (after all, he didn't have the 
rest of my code to test with).

Thanks again to all!

Mike

On Jul 15, 2004, at 2:59 PM, bsupnik wrote:

> Hi Frank,
>
> Stupid question about your code snippet: does it require that the 
> datum files are installed in the right places and converted from ASCII 
> to binary format in order to work?
>
> *Cheers*
> ben
>


/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <proj_api.h>

void ll2xy_(double coord_1[], double coord_2[], int *ni,
             int *conv_stat)
{
     static const char *src_crs = "+proj=latlong +datum=WGS84";
     static const char *dst_crs = "+init=nad27:3601 +datum=NAD27";

     projPJ src_PJ, dst_PJ;
     int i;

     src_PJ = pj_init_plus( src_crs );
     dst_PJ = pj_init_plus( dst_crs );

     *conv_stat = 1;

     if ( src_PJ == NULL || dst_PJ == NULL )
     {
         printf("pj_init_plus error\n");
         *conv_stat = 0;
     }

     for (i = 0; i <= *ni-1; i++)
     {
         double dummyz = 0.0;

         coord_1[i] *= DEG_TO_RAD;
         coord_2[i] *= DEG_TO_RAD;

         if( pj_transform( src_PJ, dst_PJ,  1, 0,
                           &coord_1[i], &coord_2[i], &dummyz ) != 0 )
         {
             printf("pj_transform error\n");
             *conv_stat = 0;
         }

         if (coord_1[i] == HUGE_VAL)
         {
             printf("pj_transform returned HUGE_VAL\n");
             *conv_stat = 0;
         }
     }

     pj_free(src_PJ);
     pj_free(dst_PJ);
}
/*--------------------------------------------------------------------*/


-- 
Mike Zulauf
mazulauf at met.utah.edu




More information about the Proj mailing list