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

Mike Zulauf mazulauf at met.utah.edu
Thu Jul 15 12:49:00 EDT 2004


Hi all,

I have what I believe to be a simple question.  I've got a very simple 
bit of code C++ that converts a vector containing NAD27 long-lat to 
NAD27 State Plane coordinates.  It's written so that I can call it from 
Fortran.  It appears to be working, and giving correct results.

I need to modify it, however, so that it will also do a datum 
conversion, from WGS84 lat-lon to NAD27 State Plane coordinates.  I'm 
sure this is simple, but I'm a newbie with PROJ.  To make matters worse, 
I'm not a C++ programmer.  I generally work with Fortran.

Below is the code as it stands now.  What's the best way to modify the 
code to include the datum conversion?  It's ok to just have it 
hard-wired - I don't need it to be flexible (ie, it doesn't need to be 
able to handle NAD27 _or_ WGS84, just WGS84).  But I still need the 
output to be NAD27.

Even though it works as it is now (without datum conversion), it's 
entirely likely I have some stupid error or nonstandard code, since I'm 
not a C++ programmer.  If there's anything of that sort which might 
cause problems down the line, I wouldn't mind hearing about that either.

Thanks,
Mike



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

void conv_coords(double coord_1[], double coord_2[], int *ni,
                 int *conv_stat)
  {
    static char *parms[] = {
      "proj=lcc",
      "init=nad27:3601"
  }; 

    PJ *ref;
    projUV data;
    int i;
   
    *conv_stat = 1;

    if ( ! (ref = pj_init(sizeof(parms)/sizeof(char *), parms)) )
         {
           printf("pj_init error\n");
           *conv_stat = 0;
         }

   for (i = 0; i <= *ni-1; i++)
     {
         data.u = coord_1[i];
         data.v = coord_2[i];
         
         data.u *= DEG_TO_RAD;
         data.v *= DEG_TO_RAD;
         
         data = pj_fwd(data, ref);
         if (data.u != HUGE_VAL)
           {
             coord_1[i] = data.u;
             coord_2[i] = data.v;
           }
         else
           {
             printf("pj_fwd error\n");
             *conv_stat = 0;
           }

      }

      pj_free(ref);
      
  }
/*--------------------------------------------------------------------*/


-- 
Mike Zulauf
mazulauf at met.utah.edu




More information about the Proj mailing list