ogr_fromepsg.cpp

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

CPP
1,725
字号
    if( pnPM != NULL )        *pnPM = nPM;/* -------------------------------------------------------------------- *//*      Get the Ellipsoid.                                              *//* -------------------------------------------------------------------- */    nEllipsoid = atoi(CSVGetField( pszFilename, "COORD_REF_SYS_CODE",                                    szSearchKey, CC_Integer,                                   "ELLIPSOID_CODE" ) );    if( nEllipsoid < 1 )        return FALSE;    if( pnEllipsoid != NULL )        *pnEllipsoid = nEllipsoid;/* -------------------------------------------------------------------- *//*      Get the angular units.                                          *//* -------------------------------------------------------------------- */    nUOMAngle = atoi(CSVGetField( pszFilename, "COORD_REF_SYS_CODE",                                   szSearchKey, CC_Integer,                                  "UOM_CODE" ) );    if( nUOMAngle < 1 )        return FALSE;    if( pnUOMAngle != NULL )        *pnUOMAngle = nUOMAngle;/* -------------------------------------------------------------------- *//*      Get the name, if requested.                                     *//* -------------------------------------------------------------------- */    if( ppszName != NULL )        *ppszName =            CPLStrdup(CSVGetField( pszFilename, "COORD_REF_SYS_CODE",                                    szSearchKey, CC_Integer,                                   "COORD_REF_SYS_NAME" ));    /* -------------------------------------------------------------------- *//*      Get the datum name, if requested.                               *//* -------------------------------------------------------------------- */    if( ppszDatumName != NULL )        *ppszDatumName =            CPLStrdup(CSVGetField( pszFilename, "COORD_REF_SYS_CODE",                                    szSearchKey, CC_Integer,                                   "DATUM_NAME" ));        return( TRUE );}/************************************************************************//*                        EPSGGetEllipsoidInfo()                        *//*                                                                      *//*      Fetch info about an ellipsoid.  Axes are always returned in     *//*      meters.  SemiMajor computed based on inverse flattening         *//*      where that is provided.                                         *//************************************************************************/static int EPSGGetEllipsoidInfo( int nCode, char ** ppszName,                      double * pdfSemiMajor, double * pdfInvFlattening ){    char        szSearchKey[24];    double      dfSemiMajor, dfToMeters = 1.0;    int         nUOMLength;    /* -------------------------------------------------------------------- *//*      Get the semi major axis.                                        *//* -------------------------------------------------------------------- */    sprintf( szSearchKey, "%d", nCode );    dfSemiMajor =        atof(CSVGetField( CSVFilename("ellipsoid.csv" ),                          "ELLIPSOID_CODE", szSearchKey, CC_Integer,                          "SEMI_MAJOR_AXIS" ) );    if( dfSemiMajor == 0.0 )        return FALSE;/* -------------------------------------------------------------------- *//*      Get the translation factor into meters.                         *//* -------------------------------------------------------------------- */    nUOMLength = atoi(CSVGetField( CSVFilename("ellipsoid.csv" ),                                   "ELLIPSOID_CODE", szSearchKey, CC_Integer,                                   "UOM_CODE" ));    EPSGGetUOMLengthInfo( nUOMLength, NULL, &dfToMeters );    dfSemiMajor *= dfToMeters;        if( pdfSemiMajor != NULL )        *pdfSemiMajor = dfSemiMajor;    /* -------------------------------------------------------------------- *//*      Get the semi-minor if requested.  If the Semi-minor axis        *//*      isn't available, compute it based on the inverse flattening.    *//* -------------------------------------------------------------------- */    if( pdfInvFlattening != NULL )    {        *pdfInvFlattening =             atof(CSVGetField( CSVFilename("ellipsoid.csv" ),                              "ELLIPSOID_CODE", szSearchKey, CC_Integer,                              "INV_FLATTENING" ));        if( *pdfInvFlattening == 0.0 )        {            double dfSemiMinor;            dfSemiMinor =                atof(CSVGetField( CSVFilename("ellipsoid.csv" ),                                  "ELLIPSOID_CODE", szSearchKey, CC_Integer,                                  "SEMI_MINOR_AXIS" )) * dfToMeters;            if( dfSemiMajor != 0.0 && dfSemiMajor != dfSemiMinor )                *pdfInvFlattening =                     -1.0 / (dfSemiMinor/dfSemiMajor - 1.0);            else                *pdfInvFlattening = 0.0;        }    }/* -------------------------------------------------------------------- *//*      Get the name, if requested.                                     *//* -------------------------------------------------------------------- */    if( ppszName != NULL )        *ppszName =            CPLStrdup(CSVGetField( CSVFilename("ellipsoid.csv" ),                                   "ELLIPSOID_CODE", szSearchKey, CC_Integer,                                   "ELLIPSOID_NAME" ));        return( TRUE );}#define NatOriginLat         8801#define NatOriginLong        8802#define NatOriginScaleFactor 8805#define FalseEasting         8806#define FalseNorthing        8807#define ProjCenterLat        8811#define ProjCenterLong       8812#define Azimuth              8813#define AngleRectifiedToSkewedGrid 8814#define InitialLineScaleFactor 8815#define ProjCenterEasting    8816#define ProjCenterNorthing   8817#define PseudoStdParallelLat 8818#define PseudoStdParallelScaleFactor 8819#define FalseOriginLat       8821#define FalseOriginLong      8822#define StdParallel1Lat      8823#define StdParallel2Lat      8824#define FalseOriginEasting   8826#define FalseOriginNorthing  8827#define SphericalOriginLat   8828#define SphericalOriginLong  8829#define InitialLongitude     8830#define ZoneWidth            8831#define PolarLatStdParallel  8832#define PolarLongOrigin      8833/************************************************************************//*                         EPSGGetProjTRFInfo()                         *//*                                                                      *//*      Transform a PROJECTION_TRF_CODE into a projection method,       *//*      and a set of parameters.  The parameters identify will          *//*      depend on the returned method, but they will all have been      *//*      normalized into degrees and meters.                             *//************************************************************************/static intEPSGGetProjTRFInfo( int nPCS, int * pnProjMethod,                    int *panParmIds, double * padfProjParms ){    int         nProjMethod, i;    double      adfProjParms[7];    char        szTRFCode[16];    char       *pszFilename = CPLStrdup(CSVFilename( "pcs.csv" ));/* -------------------------------------------------------------------- *//*      Get the proj method.  If this fails to return a meaningful      *//*      number, then the whole function fails.                          *//* -------------------------------------------------------------------- */    sprintf( szTRFCode, "%d", nPCS );    nProjMethod =        atoi( CSVGetField( pszFilename,                           "COORD_REF_SYS_CODE", szTRFCode, CC_Integer,                           "COORD_OP_METHOD_CODE" ) );    if( nProjMethod == 0 )    {        CPLFree( pszFilename );        return FALSE;    }/* -------------------------------------------------------------------- *//*      Get the parameters for this projection.                         *//* -------------------------------------------------------------------- */    for( i = 0; i < 7; i++ )    {        char    szParamUOMID[32], szParamValueID[32], szParamCodeID[32];        char    *pszValue;        int     nUOM;                sprintf( szParamCodeID, "PARAMETER_CODE_%d", i+1 );        sprintf( szParamUOMID, "PARAMETER_UOM_%d", i+1 );        sprintf( szParamValueID, "PARAMETER_VALUE_%d", i+1 );        if( panParmIds != NULL )            panParmIds[i] =                 atoi(CSVGetField( pszFilename, "COORD_REF_SYS_CODE", szTRFCode,                                  CC_Integer, szParamCodeID ));        nUOM = atoi(CSVGetField( pszFilename, "COORD_REF_SYS_CODE", szTRFCode,                                 CC_Integer, szParamUOMID ));        pszValue = CPLStrdup(            CSVGetField( pszFilename, "COORD_REF_SYS_CODE", szTRFCode,                         CC_Integer, szParamValueID ));        // there is a bug in the EPSG 6.2.2 database for PCS 2935 and 2936        // such that they have foot units for the scale factor.  Avoid this.        if( (panParmIds[i] == NatOriginScaleFactor              || panParmIds[i] == InitialLineScaleFactor             || panParmIds[i] == PseudoStdParallelScaleFactor)             && nUOM < 9200 )            nUOM = 9201;        if( nUOM >= 9100 && nUOM < 9200 )            adfProjParms[i] = EPSGAngleStringToDD( pszValue, nUOM );        else if( nUOM > 9000 && nUOM < 9100 )        {            double dfInMeters;            if( !EPSGGetUOMLengthInfo( nUOM, NULL, &dfInMeters ) )                dfInMeters = 1.0;            adfProjParms[i] = atof(pszValue) * dfInMeters;        }        else if( EQUAL(pszValue,"") ) /* null field */        {            adfProjParms[i] = 0.0;        }        else /* really we should consider looking up other scaling factors */        {            if( nUOM != 9201 )                CPLDebug( "OGR", "Non-unity scale factor units!" );            adfProjParms[i] = atof(pszValue);        }        CPLFree( pszValue );    }/* -------------------------------------------------------------------- *//*      Transfer requested data into passed variables.                  *//* -------------------------------------------------------------------- */    if( pnProjMethod != NULL )        *pnProjMethod = nProjMethod;    if( padfProjParms != NULL )    {        for( i = 0; i < 7; i++ )            padfProjParms[i] = adfProjParms[i];    }    CPLFree( pszFilename );    return TRUE;}/************************************************************************//*                           EPSGGetPCSInfo()                           *//************************************************************************/static int EPSGGetPCSInfo( int nPCSCode, char **ppszEPSGName,                int *pnUOMLengthCode, int *pnUOMAngleCode,                int *pnGeogCS, int *pnTRFCode ){    char        **papszRecord;    char        szSearchKey[24];    const char  *pszFilename = CSVFilename( "pcs.csv" );    /* -------------------------------------------------------------------- *//*      Search the units database for this unit.  If we don't find      *//*      it return failure.                                              *//* -------------------------------------------------------------------- */    sprintf( szSearchKey, "%d", nPCSCode );    papszRecord = CSVScanFileByName( pszFilename, "COORD_REF_SYS_CODE",                                     szSearchKey, CC_Integer );    if( papszRecord == NULL )        return FALSE;/* -------------------------------------------------------------------- *//*      Get the name, if requested.                                     *//* -------------------------------------------------------------------- */    if( ppszEPSGName != NULL )    {        CPLString osPCSName =             CSLGetField( papszRecord,                         CSVGetFileFieldId(pszFilename,                                           "COORD_REF_SYS_NAME"));                    const char *pszDeprecated =             CSLGetField( papszRecord,                         CSVGetFileFieldId(pszFilename,                                           "DEPRECATED") );        if( pszDeprecated != NULL && *pszDeprecated == '1' )            osPCSName += " (deprecated)";        *ppszEPSGName = CPLStrdup(osPCSName);    }/* -------------------------------------------------------------------- *//*      Get the UOM Length code, if requested.                          *//* -------------------------------------------------------------------- */    if( pnUOMLengthCode != NULL )    {        const char      *pszValue;        pszValue =            CSLGetField( papszRecord,                         CSVGetFileFieldId(pszFilename,"UOM_CODE"));        if( atoi(pszValue) > 0 )            *pnUOMLengthCode = atoi(pszValue);        else            *pnUOMLengthCode = 0;    }/* -------------------------------------------------------------------- *//*      Get the UOM Angle code, if requested.                           *//* -------------------------------------------------------------------- */    if( pnUOMAngleCode != NULL )    {        const char      *pszValue;                pszValue =            CSLGetField( papszRecord,                         CSVGetFileFieldId(pszFilename,"UOM_ANGLE_CODE") );                if( atoi(pszValue) > 0 )            *pnUOMAngleCode = atoi(pszValue);        else            *pnUOMAngleCode = 0;

⌨️ 快捷键说明

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