ogr_fromepsg.cpp

来自「用于读取TAB、MIF、SHP文件的类」· C++ 代码 · 共 1,725 行 · 第 1/5 页

CPP
1,725
字号
    }/* -------------------------------------------------------------------- *//*      Get the GeogCS (Datum with PM) code, if requested.              *//* -------------------------------------------------------------------- */    if( pnGeogCS != NULL )    {        const char      *pszValue;        pszValue =            CSLGetField( papszRecord,                         CSVGetFileFieldId(pszFilename,"SOURCE_GEOGCRS_CODE"));        if( atoi(pszValue) > 0 )            *pnGeogCS = atoi(pszValue);        else            *pnGeogCS = 0;    }/* -------------------------------------------------------------------- *//*      Get the GeogCS (Datum with PM) code, if requested.              *//* -------------------------------------------------------------------- */    if( pnTRFCode != NULL )    {        const char      *pszValue;        pszValue =            CSLGetField( papszRecord,                         CSVGetFileFieldId(pszFilename,"COORD_OP_CODE"));                                         if( atoi(pszValue) > 0 )            *pnTRFCode = atoi(pszValue);        else            *pnTRFCode = 0;    }    return TRUE;}/************************************************************************//*                           SetEPSGGeogCS()                            *//*                                                                      *//*      FLAWS:                                                          *//*       o Units are all hardcoded.                                     *//*       o Axis hardcoded.                                              *//************************************************************************/static OGRErr SetEPSGGeogCS( OGRSpatialReference * poSRS, int nGeogCS ){    int  nDatumCode, nPMCode, nUOMAngle, nEllipsoidCode;    char *pszGeogCSName = NULL, *pszDatumName = NULL, *pszEllipsoidName = NULL;    char *pszPMName = NULL, *pszAngleName = NULL;    double dfPMOffset, dfSemiMajor, dfInvFlattening, adfBursaTransform[7];    double dfAngleInDegrees, dfAngleInRadians;    if( !EPSGGetGCSInfo( nGeogCS, &pszGeogCSName,                         &nDatumCode, &pszDatumName,                          &nPMCode, &nEllipsoidCode, &nUOMAngle ) )        return OGRERR_UNSUPPORTED_SRS;    if( !EPSGGetPMInfo( nPMCode, &pszPMName, &dfPMOffset ) )        return OGRERR_UNSUPPORTED_SRS;    OGREPSGDatumNameMassage( &pszDatumName );    if( !EPSGGetEllipsoidInfo( nEllipsoidCode, &pszEllipsoidName,                                &dfSemiMajor, &dfInvFlattening ) )        return OGRERR_UNSUPPORTED_SRS;    if( !EPSGGetUOMAngleInfo( nUOMAngle, &pszAngleName, &dfAngleInDegrees ) )    {        pszAngleName = CPLStrdup("degree");        dfAngleInDegrees = 1.0;        nUOMAngle = -1;    }    if( dfAngleInDegrees == 1.0 )        dfAngleInRadians = atof(SRS_UA_DEGREE_CONV);    else        dfAngleInRadians = atof(SRS_UA_DEGREE_CONV) * dfAngleInDegrees;    poSRS->SetGeogCS( pszGeogCSName, pszDatumName,                       pszEllipsoidName, dfSemiMajor, dfInvFlattening,                      pszPMName, dfPMOffset,                      pszAngleName, dfAngleInRadians );    if( EPSGGetWGS84Transform( nGeogCS, adfBursaTransform ) )    {        OGR_SRSNode     *poWGS84;        char            szValue[48];        poWGS84 = new OGR_SRSNode( "TOWGS84" );        for( int iCoeff = 0; iCoeff < 7; iCoeff++ )        {            sprintf( szValue, "%g", adfBursaTransform[iCoeff] );            poWGS84->AddChild( new OGR_SRSNode( szValue ) );        }        poSRS->GetAttrNode( "DATUM" )->AddChild( poWGS84 );    }    poSRS->SetAuthority( "GEOGCS", "EPSG", nGeogCS );    poSRS->SetAuthority( "DATUM", "EPSG", nDatumCode );    poSRS->SetAuthority( "SPHEROID", "EPSG", nEllipsoidCode );    poSRS->SetAuthority( "PRIMEM", "EPSG", nPMCode );    if( nUOMAngle > 0 )        poSRS->SetAuthority( "GEOGCS|UNIT", "EPSG", nUOMAngle );    CPLFree( pszAngleName );    CPLFree( pszDatumName );    CPLFree( pszEllipsoidName );    CPLFree( pszGeogCSName );    CPLFree( pszPMName );    return OGRERR_NONE;}/************************************************************************//*                           OGR_FetchParm()                            *//*                                                                      *//*      Fetch a parameter from the parm list, based on it's EPSG        *//*      parameter code.                                                 *//************************************************************************/static double OGR_FetchParm( double *padfProjParms, int *panParmIds,                              int nTargetId, double dfFromGreenwich ){    int i;    double dfResult;/* -------------------------------------------------------------------- *//*      Set default in meters/degrees.                                  *//* -------------------------------------------------------------------- */    switch( nTargetId )    {      case NatOriginScaleFactor:      case InitialLineScaleFactor:      case PseudoStdParallelScaleFactor:        dfResult = 1.0;        break;              case AngleRectifiedToSkewedGrid:        dfResult = 90.0;        break;      default:        dfResult = 0.0;    }/* -------------------------------------------------------------------- *//*      Try to find actual value in parameter list.                     *//* -------------------------------------------------------------------- */    for( i = 0; i < 7; i++ )    {        if( panParmIds[i] == nTargetId )        {            dfResult = padfProjParms[i];            break;        }    }/* -------------------------------------------------------------------- *//*      EPSG longitudes are relative to greenwich.  The follow code     *//*      could be used to make them relative to the prime meridian of    *//*      the associated GCS if that was appropriate.  However, the       *//*      SetNormProjParm() method expects longitudes relative to         *//*      greenwich, so there is nothing for us to do.                    *//* -------------------------------------------------------------------- */#ifdef notdef    switch( nTargetId )    {      case NatOriginLong:      case ProjCenterLong:      case FalseOriginLong:      case SphericalOriginLong:      case InitialLongitude:        // Note that the EPSG values are already relative to greenwich.        // This shift is really making it relative to the provided prime        // meridian, so that when SetTM() and company the correction back        // ends up back relative to greenwich.        dfResult = dfResult + dfFromGreenwich;        break;      default:        ;    }#endif    return dfResult;}#define OGR_FP(x) OGR_FetchParm( adfProjParms, anParmIds, (x), \                                 dfFromGreenwich )/************************************************************************//*                           SetEPSGProjCS()                            *//************************************************************************/static OGRErr SetEPSGProjCS( OGRSpatialReference * poSRS, int nPCSCode ){    int         nGCSCode, nUOMAngleCode, nUOMLength, nTRFCode, nProjMethod;    int         anParmIds[7];    char        *pszPCSName = NULL, *pszUOMLengthName = NULL;    double      adfProjParms[7], dfInMeters, dfFromGreenwich;    OGRErr      nErr;    OGR_SRSNode *poNode;    if( !EPSGGetPCSInfo( nPCSCode, &pszPCSName, &nUOMLength, &nUOMAngleCode,                         &nGCSCode, &nTRFCode ) )        return OGRERR_UNSUPPORTED_SRS;    poSRS->SetNode( "PROJCS", pszPCSName );    /* -------------------------------------------------------------------- *//*      Set GEOGCS.                                                     *//* -------------------------------------------------------------------- */    nErr = SetEPSGGeogCS( poSRS, nGCSCode );    if( nErr != OGRERR_NONE )        return nErr;    dfFromGreenwich = poSRS->GetPrimeMeridian();/* -------------------------------------------------------------------- *//*      Set linear units.                                               *//* -------------------------------------------------------------------- */    if( !EPSGGetUOMLengthInfo( nUOMLength, &pszUOMLengthName, &dfInMeters ) )        return OGRERR_UNSUPPORTED_SRS;    poSRS->SetLinearUnits( pszUOMLengthName, dfInMeters );    poSRS->SetAuthority( "PROJCS|UNIT", "EPSG", nUOMLength );    CPLFree( pszUOMLengthName );    CPLFree( pszPCSName );/* -------------------------------------------------------------------- *//*      Set projection and parameters.                                  *//* -------------------------------------------------------------------- */    if( !EPSGGetProjTRFInfo( nPCSCode, &nProjMethod, anParmIds, adfProjParms ))        return OGRERR_UNSUPPORTED_SRS;    switch( nProjMethod )    {      case 9801:      case 9817: /* really LCC near conformal */        poSRS->SetLCC1SP( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                          OGR_FP( NatOriginScaleFactor ),                           OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9802:        poSRS->SetLCC( OGR_FP( StdParallel1Lat ), OGR_FP( StdParallel2Lat ),                       OGR_FP( FalseOriginLat ), OGR_FP( FalseOriginLong ),                       OGR_FP( FalseOriginEasting ),                        OGR_FP( FalseOriginNorthing ));        break;      case 9803:        poSRS->SetLCCB( OGR_FP( StdParallel1Lat ), OGR_FP( StdParallel2Lat ),                        OGR_FP( FalseOriginLat ), OGR_FP( FalseOriginLong ),                        OGR_FP( FalseOriginEasting ),                         OGR_FP( FalseOriginNorthing ));        break;      case 9804:      case 9805: /* NOTE: treats 1SP and 2SP cases the same */        poSRS->SetMercator( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                            OGR_FP( NatOriginScaleFactor ),                             OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9806:        poSRS->SetCS( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                            OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9807:        poSRS->SetTM( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                      OGR_FP( NatOriginScaleFactor ),                       OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;              case 9808:        poSRS->SetTMSO( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                        OGR_FP( NatOriginScaleFactor ),                         OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;              case 9809:        poSRS->SetOS( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                      OGR_FP( NatOriginScaleFactor ),                       OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9810:        poSRS->SetPS( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                      OGR_FP( NatOriginScaleFactor ),                       OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9811:        poSRS->SetNZMG( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ),                        OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9812:      case 9813:        poSRS->SetHOM( OGR_FP( ProjCenterLat ), OGR_FP( ProjCenterLong ),                       OGR_FP( Azimuth ),                        OGR_FP( AngleRectifiedToSkewedGrid ),                       OGR_FP( InitialLineScaleFactor ),                       OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        poNode = poSRS->GetAttrNode( "PROJECTION" )->GetChild( 0 );        if( nProjMethod == 9813 )            poNode->SetValue( SRS_PT_LABORDE_OBLIQUE_MERCATOR );        break;      case 9814:        /* NOTE: This is no longer used!  Swiss Oblique Mercator gets        ** implemented using 9815 instead.          */        poSRS->SetSOC( OGR_FP( ProjCenterLat ), OGR_FP( ProjCenterLong ),                       OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );        break;      case 9815:        poSRS->SetHOM( OGR_FP( ProjCenterLat ), OGR_FP( ProjCenterLong ),                       OGR_FP( Azimuth ),                        OGR_FP( AngleRectifiedToSkewedGrid ),                       OGR_FP( InitialLineScaleFactor ),                       OGR_FP( ProjCenterEasting ),                        OGR_FP( ProjCenterNorthing ) );        break;      case 9816:        poSRS->SetTMG( OGR_FP( FalseOriginLat ), OGR_FP( FalseOriginLong ),                       OGR_FP( FalseOriginEasting ),                        OGR_FP( FalseOriginNorthing ) );        break;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?