Point GCTPTester::doInverse(const Point& projP) { Point retP; //lon / lat coord double inCoord[2] = {0}; double outCoord[2] = {0}; inCoord[0] = projP.x; inCoord[1] = projP.y; long outSys = 0; //GEO long outZone = 0; //doesn't matter long outUnit = 4; //degrees of arc long outDatum = getToProjInfo().projDatum; //no datum shifting, in and out datum the same. long inDatum = outDatum; long inSys = getToProjInfo().projNumber; long inZone = getToProjInfo().projZone; long inUnit = getToProjInfo().projUnits; gctp(inCoord, &inSys, &inZone, getFromProjInfo().projParams, &inUnit, &inDatum, NULL, NULL, NULL, NULL, outCoord, &outSys, &outZone, getToProjInfo().projParams, &outUnit, &outDatum, NULL, NULL, NULL); retP.x = outCoord[1]; retP.y = outCoord[0]; return(retP); }
/**************************************************************************** Name: call_gctp Purpose: Helper routine to perform a transformation by calling the old gctp interface. Note that this routine should be eliminated when all of the projections have been converted to the new interface. Returns: GCTP_SUCCESS, GCTP_ERROR or GCTP_IN_BREAK ****************************************************************************/ static int call_gctp ( const GCTP_TRANSFORMATION *trans, /* I: transformation to use */ const double *in_coor, /* I: array of (lon, lat) or (x, y) */ double *out_coor /* O: array of (x, y) or (lon, lat) */ ) { /* Set up local variables for calling the old gctp routine */ const GCTP_PROJECTION *in_proj = &trans->inverse.proj; const GCTP_PROJECTION *out_proj = &trans->forward.proj; long insys = in_proj->proj_code; long inzone = in_proj->zone; long inunit = in_proj->units; long inspheroid = in_proj->spheroid; long outsys = out_proj->proj_code; long outzone = out_proj->zone; long outunit = out_proj->units; long outspheroid = out_proj->spheroid; long iflg = 0; /* Call the original gctp routine */ gctp(in_coor, &insys, &inzone, in_proj->parameters, &inunit, &inspheroid, out_coor, &outsys, &outzone, out_proj->parameters, &outunit, &outspheroid, &iflg); /* Convert the error flag */ if (iflg == OK) return GCTP_SUCCESS; else if (iflg == IN_BREAK) return GCTP_IN_BREAK; else return GCTP_ERROR; }
Point GCTPTester::doForward(const Point& geoP) { Point retP; // x / y coord double inCoord[2] = {0}; double outCoord[2] = {0}; inCoord[0] = geoP.y; inCoord[1] = geoP.x; long inSys = getFromProjInfo().projNumber; //Equirectangular long inZone = getFromProjInfo().projZone; //doesn't matter long inUnit = getFromProjInfo().projUnits; //meters long inDatum = getFromProjInfo().projDatum; //no datum shifting, in and out datum the same. long outDatum = inDatum; long outSys = getToProjInfo().projNumber; long outZone = getToProjInfo().projZone; long outUnit = getToProjInfo().projUnits; gctp(inCoord, &inSys, &inZone, getFromProjInfo().projParams, &inUnit, &inDatum, NULL, NULL, NULL, NULL, outCoord, &outSys, &outZone, getToProjInfo().projParams, &outUnit, &outDatum, NULL, NULL, NULL); retP.x = outCoord[0]; retP.y = outCoord[1]; return(retP); }
int geo2eqr(long numLines, long numSamps, const char * infilename, int projnum) { FILE *file; double pixsiz; // Pixel Size in output image double pixX, pixY; double pxmin; // Projection minimum in X double pxmax; // Projection maximum in X double pymin; // Projection minimum in Y double pymax; // Projection maximum in Y long status; long i; long outProj = projnum; long outUnit = 2; long outZone = 62; long outDatum = 0; double outParms[15]; long inProj = 0; long inUnit = 4; long inZone = 62; long inDatum = 0; long zero = 0; double R = 6370997.0; double inParms[15]; double inCoords[2]; double outCoords[2]; for(i = 0; i < 15; inParms[i++] = 0.0); for(i = 0; i < 15; outParms[i++] = 0.0); pxmin = 1000000000.0; pymin = 1000000000.0; pxmax = -1000000000.0; pymax = -1000000000.0; FILE *paramfile = fopen( logFile, "wa"); // Parse Parameters // ---------------- outParms[0] = R; // Calc projection coordinates for the four corners. OK, OK, for an Equirectangular // space & square pixels this really isn't necessary 'cuz it's easy to figure out with 2PiR // etc., but it's here for a check. It should check EXACTLY... // --------------------------------------------------------------------------------------- inCoords[0] = -180.0; inCoords[1] = 90.0; // gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &zero, "", &zero, "", // outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &errorMode,logFile,¶mMode,logFile, paramfile, outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); if(outCoords[0] < pxmin) { pxmin = outCoords[0]; } if(outCoords[0] > pxmax) { pxmax = outCoords[0]; } if(outCoords[1] < pymin) { pymin = outCoords[1]; } if(outCoords[1] > pymax) { pymax = pymax = outCoords[1]; } inCoords[0] = 180.0; inCoords[1] = -90.0; // gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &zero, "", &zero, "", // outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &errorMode,logFile,¶mMode,logFile, paramfile,outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); if(outCoords[0] < pxmin) { pxmin = outCoords[0]; } if(outCoords[0] > pxmax) { pxmax = outCoords[0]; } if(outCoords[1] < pymin) { pymin = outCoords[1]; } if(outCoords[1] > pymax) { pymax = pymax = outCoords[1]; } inCoords[0] = -180.0; inCoords[1] = -90.0; // gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &zero, "", &zero, "", // outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &errorMode,logFile,¶mMode,logFile, paramfile,outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); if(outCoords[0] < pxmin) { pxmin = outCoords[0]; } if(outCoords[0] > pxmax) { pxmax = outCoords[0]; } if(outCoords[1] < pymin) { pymin = outCoords[1]; } if(outCoords[1] > pymax) { pymax = pymax = outCoords[1]; } inCoords[0] = 180.0; inCoords[1] = 90.0; // gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &zero, "", &zero, "", // outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); gctp(inCoords, &inProj, &inZone, inParms, &inUnit, &inDatum, &errorMode,logFile,¶mMode,logFile, paramfile,outCoords, &outProj, &outZone, outParms, &outUnit, &outDatum, "", "", &status); if(outCoords[0] < pxmin) { pxmin = outCoords[0]; } if(outCoords[0] > pxmax) { pxmax = outCoords[0]; } if(outCoords[1] < pymin) { pymin = outCoords[1]; } if(outCoords[1] > pymax) { pymax = pymax = outCoords[1]; } // Calc output imagee pixel size // ----------------------------- pixsiz = (2.0 * 3.141593653589793238 * R) / (double)numSamps; pixX = pxmin + (pixsiz / 2); pixY = pymax + (pixsiz / 2); // Output Results to File // ---------------------- file = fopen(infilename, "w"); if(!file) { fclose(file); remove(infilename); /*** * Geographic to Eqirectangular projection (or variant) * * "An internal error occurred while trying to open the designated output file" * "MapIMG will not execute." * * The Output file could not be opened for storing the parameter file. * Check for a write protected .info associated with the input .img ***/ QMessageBox::critical( 0, "MapIMG", QString("An internal error occurred while trying to open the designated output file\n\nMapIMG will not execute.")); return 0; } fprintf(file, "%d %d\n", numLines, numSamps); fprintf(file, "%d\n", outProj); fprintf(file, "%d\n", outZone); fprintf(file, "%d\n", outUnit); fprintf(file, "%d\n", outDatum); fprintf(file, "%lf\n", pixsiz); fprintf(file, "%lf %lf\n", pixX, pixY); for(i = 0; i < 15; i++) fprintf(file, "%lf ", outParms[i]); fclose(file); fclose( paramfile ); return 1; }