📄 geotiff_proj4.c
字号:
/* -------------------------------------------------------------------- *//* Miller Cylindrical *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_MillerCylindrical ) { sprintf( szProjection+strlen(szProjection), "+proj=mill +lat_0=%.9f +lon_0=%.9f +x_0=%.3f +y_0=%.3f +R_A ", psDefn->ProjParm[0], psDefn->ProjParm[1], dfFalseEasting, dfFalseNorthing ); }/* -------------------------------------------------------------------- *//* Polyconic *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_Polyconic ) { sprintf( szProjection+strlen(szProjection), "+proj=poly +lat_0=%.9f +lon_0=%.9f +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[0], psDefn->ProjParm[1], dfFalseEasting, dfFalseNorthing ); }/* -------------------------------------------------------------------- *//* AlbersEqualArea *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_AlbersEqualArea ) { sprintf( szProjection+strlen(szProjection), "+proj=aea +lat_1=%.9f +lat_2=%.9f +lat_0=%.9f +lon_0=%.9f" " +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[0], psDefn->ProjParm[1], psDefn->ProjParm[2], psDefn->ProjParm[3], dfFalseEasting, dfFalseNorthing ); } /* -------------------------------------------------------------------- *//* EquidistantConic *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_EquidistantConic ) { sprintf( szProjection+strlen(szProjection), "+proj=eqdc +lat_1=%.9f +lat_2=%.9f +lat_0=%.9f +lon_0=%.9f" " +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[0], psDefn->ProjParm[1], psDefn->ProjParm[2], psDefn->ProjParm[3], dfFalseEasting, dfFalseNorthing ); } /* -------------------------------------------------------------------- *//* Robinson *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_Robinson ) { sprintf( szProjection+strlen(szProjection), "+proj=robin +lon_0=%.9f +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[1], dfFalseEasting, dfFalseNorthing ); } /* -------------------------------------------------------------------- *//* VanDerGrinten *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_VanDerGrinten ) { sprintf( szProjection+strlen(szProjection), "+proj=vandg +lon_0=%.9f +x_0=%.3f +y_0=%.3f +R_A ", psDefn->ProjParm[1], dfFalseEasting, dfFalseNorthing ); } /* -------------------------------------------------------------------- *//* Sinusoidal *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_Sinusoidal ) { sprintf( szProjection+strlen(szProjection), "+proj=sinu +lon_0=%.9f +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[1], dfFalseEasting, dfFalseNorthing ); } /* -------------------------------------------------------------------- *//* LambertConfConic_2SP *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_LambertConfConic_2SP ) { sprintf( szProjection+strlen(szProjection), "+proj=lcc +lat_0=%.9f +lon_0=%.9f +lat_1=%.9f +lat_2=%.9f " " +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[0], psDefn->ProjParm[1], psDefn->ProjParm[2], psDefn->ProjParm[3], dfFalseEasting, dfFalseNorthing ); } /* -------------------------------------------------------------------- *//* LambertConfConic_1SP *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_LambertConfConic_1SP ) { sprintf( szProjection+strlen(szProjection), "+proj=lcc +lat_0=%.9f +lat_1=%.9f +lon_0=%.9f" " +k_0=%.9f +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[0], psDefn->ProjParm[0], psDefn->ProjParm[1], psDefn->ProjParm[4], psDefn->ProjParm[5], psDefn->ProjParm[6] ); } /* -------------------------------------------------------------------- *//* NewZealandMapGrid *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_NewZealandMapGrid ) { /* this appears to be an unsupported formulation with PROJ.4 */ } /* -------------------------------------------------------------------- *//* Transverse Mercator - south oriented. *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_TransvMercator_SouthOriented ) { /* this appears to be an unsupported formulation with PROJ.4 */ } /* -------------------------------------------------------------------- *//* ObliqueMercator (Hotine) *//* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_ObliqueMercator ) { /* not clear how ProjParm[3] - angle from rectified to skewed grid - should be applied ... see the +not_rot flag for PROJ.4. Just ignoring for now. */ sprintf( szProjection+strlen(szProjection), "+proj=omerc +lat_0=%.9f +lonc=%.9f +alpha=%.9f" " +k=%.9f +x_0=%.3f +y_0=%.3f ", psDefn->ProjParm[0], psDefn->ProjParm[1], psDefn->ProjParm[2], psDefn->ProjParm[4], psDefn->ProjParm[5], psDefn->ProjParm[6] ); }/* ==================================================================== *//* Handle ellipsoid information. *//* ==================================================================== */ if( psDefn->Ellipsoid == Ellipse_WGS_84 ) strcat( szProjection, "+ellps=WGS84 " ); else if( psDefn->Ellipsoid == Ellipse_Clarke_1866 ) strcat( szProjection, "+ellps=clrk66 " ); else if( psDefn->Ellipsoid == Ellipse_Clarke_1880 ) strcat( szProjection, "+ellps=clrk80 " ); else if( psDefn->Ellipsoid == Ellipse_GRS_1980 ) strcat( szProjection, "+ellps=GRS80 " ); else { if( psDefn->SemiMajor != 0.0 && psDefn->SemiMinor != 0.0 ) { sprintf( szProjection+strlen(szProjection), "+a=%.3f +b=%.3f ", psDefn->SemiMajor, psDefn->SemiMinor ); } } strcat( szProjection, szUnits ); return( strdup( szProjection ) );}#if !defined(HAVE_LIBPROJ) || !defined(HAVE_PROJECTS_H)int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints, double *padfX, double *padfY ){ (void) psDefn; (void) nPoints; (void) padfX; (void) padfY;#ifdef DEBUG fprintf( stderr, "GTIFProj4ToLatLong() - PROJ.4 support not compiled in.\n" );#endif return FALSE;}int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints, double *padfX, double *padfY ){ (void) psDefn; (void) nPoints; (void) padfX; (void) padfY;#ifdef DEBUG fprintf( stderr, "GTIFProj4FromLatLong() - PROJ.4 support not compiled in.\n" );#endif return FALSE;}#else#include "projects.h"#ifdef USE_PROJUV# define UV projUV#endif/************************************************************************//* GTIFProj4FromLatLong() *//* *//* Convert lat/long values to projected coordinate for a *//* particular definition. *//************************************************************************/int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints, double *padfX, double *padfY ){ char *pszProjection, **papszArgs; PJ *psPJ; int i; /* -------------------------------------------------------------------- *//* Get a projection definition. *//* -------------------------------------------------------------------- */ pszProjection = GTIFGetProj4Defn( psDefn ); if( pszProjection == NULL ) return FALSE;/* -------------------------------------------------------------------- *//* Parse into tokens for pj_init(), and initialize the projection. *//* -------------------------------------------------------------------- */ papszArgs = CSLTokenizeStringComplex( pszProjection, " +", TRUE, FALSE ); free( pszProjection ); psPJ = pj_init( CSLCount(papszArgs), papszArgs ); CSLDestroy( papszArgs ); if( psPJ == NULL ) { return FALSE; }/* -------------------------------------------------------------------- *//* Process each of the points. *//* -------------------------------------------------------------------- */ for( i = 0; i < nPoints; i++ ) { UV sUV; sUV.u = padfX[i] * DEG_TO_RAD; sUV.v = padfY[i] * DEG_TO_RAD; sUV = pj_fwd( sUV, psPJ ); padfX[i] = sUV.u; padfY[i] = sUV.v; } pj_free( psPJ ); return TRUE;}/************************************************************************//* GTIFProj4ToLatLong() *//* *//* Convert projection coordinates to lat/long for a particular *//* definition. *//************************************************************************/int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints, double *padfX, double *padfY ){ char *pszProjection, **papszArgs; PJ *psPJ; int i; /* -------------------------------------------------------------------- *//* Get a projection definition. *//* -------------------------------------------------------------------- */ pszProjection = GTIFGetProj4Defn( psDefn ); if( pszProjection == NULL ) return FALSE;/* -------------------------------------------------------------------- *//* Parse into tokens for pj_init(), and initialize the projection. *//* -------------------------------------------------------------------- */ papszArgs = CSLTokenizeStringComplex( pszProjection, " +", TRUE, FALSE ); free( pszProjection ); psPJ = pj_init( CSLCount(papszArgs), papszArgs ); CSLDestroy( papszArgs ); if( psPJ == NULL ) { return FALSE; }/* -------------------------------------------------------------------- *//* Process each of the points. *//* -------------------------------------------------------------------- */ for( i = 0; i < nPoints; i++ ) { UV sUV; sUV.u = padfX[i]; sUV.v = padfY[i]; sUV = pj_inv( sUV, psPJ ); padfX[i] = sUV.u * RAD_TO_DEG; padfY[i] = sUV.v * RAD_TO_DEG; } pj_free( psPJ ); return TRUE;}#endif /* has projects.h and -lproj */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -