⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mitab_coordsys.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        if( CSLCount(papszFields) < 5 )            nDatum = 104; /* WGS84 */        CSLDestroy( papszFields );    }        /*-----------------------------------------------------------------     * We have a "real" datum name.  Try to look it up and get the     * parameters.  If we don't find it just use WGS84.     *----------------------------------------------------------------*/    else     {        int     i;        for( i = 0; asDatumInfoList[i].nMapInfoDatumID != -1; i++ )        {            if( EQUAL(pszWKTDatum,asDatumInfoList[i].pszOGCDatumName) )            {                nDatum = asDatumInfoList[i].nMapInfoDatumID;                break;            }        }        if( nDatum == 0 )            nDatum = 104; /* WGS84 */    }    /*-----------------------------------------------------------------     * Translate the units     *----------------------------------------------------------------*/    const char  *pszMIFUnits = "m";    if( nProjection == 1 )        pszMIFUnits = NULL;    else if( pszLinearUnits == NULL )        pszMIFUnits = "m";    else if( dfLinearConv == 1000.0 )        pszMIFUnits = "km";    else if( dfLinearConv == 0.0254 || EQUAL(pszLinearUnits,"Inch")             || EQUAL(pszLinearUnits,"IINCH"))        pszMIFUnits = "in";    else if( dfLinearConv == atof(SRS_UL_FOOT_CONV)             || EQUAL(pszLinearUnits,SRS_UL_FOOT) )        pszMIFUnits = "ft";    else if( EQUAL(pszLinearUnits,"YARD") || EQUAL(pszLinearUnits,"IYARD")              || dfLinearConv == 0.9144 )        pszMIFUnits = "yd";    else if( dfLinearConv == 0.001 )        pszMIFUnits = "mm";    else if( dfLinearConv == 0.01 )        pszMIFUnits = "cm";    else if( dfLinearConv == 1.0 )        pszMIFUnits = "m";    else if( dfLinearConv == atof(SRS_UL_US_FOOT_CONV)             || EQUAL(pszLinearUnits,SRS_UL_US_FOOT) )        pszMIFUnits = "survey ft";    else if( EQUAL(pszLinearUnits,SRS_UL_NAUTICAL_MILE) )        pszMIFUnits = "nmi";    else if( EQUAL(pszLinearUnits,SRS_UL_LINK)              || EQUAL(pszLinearUnits,"GUNTERLINK") )        pszMIFUnits = "li";    else if( EQUAL(pszLinearUnits,SRS_UL_CHAIN)              || EQUAL(pszLinearUnits,"GUNTERCHAIN") )        pszMIFUnits = "ch";    else if( EQUAL(pszLinearUnits,SRS_UL_ROD) )        pszMIFUnits = "rd";    else if( EQUAL(pszLinearUnits,"Mile")              || EQUAL(pszLinearUnits,"IMILE") )        pszMIFUnits = "mi";    /* -------------------------------------------------------------------- *//*      Build coordinate system definition.                             *//* -------------------------------------------------------------------- */    char        szCoordSys[256];    if( nProjection != 0 )    {        sprintf( szCoordSys,                 "Earth Projection %d",                 nProjection );    }    else        sprintf( szCoordSys,                 "NonEarth Units" );/* -------------------------------------------------------------------- *//*      Append Datum                                                    *//* -------------------------------------------------------------------- */    if( nProjection != 0 )    {        sprintf( szCoordSys + strlen(szCoordSys),                 ", %d",                 nDatum );        if( nDatum == 999 || nDatum == 9999 )        {            sprintf( szCoordSys + strlen(szCoordSys),                     ", %d, %.15g, %.15g, %.15g",                     nEllipsoid,                     adfDatumParm[0], adfDatumParm[1], adfDatumParm[2] );        }                if( nDatum == 9999 )        {            sprintf( szCoordSys + strlen(szCoordSys),                     ", %.15g, %.15g, %.15g, %.15g, %.15g",                     adfDatumParm[3], adfDatumParm[4], adfDatumParm[5],                     adfDatumParm[6], adfDatumParm[7] );        }    }/* -------------------------------------------------------------------- *//*      Append units.                                                   *//* -------------------------------------------------------------------- */    if( nProjection != 1 && pszMIFUnits != NULL )    {        if( nProjection != 0 )            strcat( szCoordSys, "," );                sprintf( szCoordSys + strlen(szCoordSys),                 " \"%s\"",                 pszMIFUnits );    }/* -------------------------------------------------------------------- *//*      Append Projection Parms.                                        *//* -------------------------------------------------------------------- */    for( int iParm = 0; iParm < nParmCount; iParm++ )        sprintf( szCoordSys + strlen(szCoordSys),                 ", %.15g",                 parms[iParm] );/* -------------------------------------------------------------------- *//*      Report on translation                                           *//* -------------------------------------------------------------------- */    char        *pszWKT = NULL;    poSR->exportToWkt( &pszWKT );    if( pszWKT != NULL )    {        CPLDebug( "MITAB",                  "This WKT Projection:\n%s\n\ntranslates to:\n%s\n",                  pszWKT, szCoordSys );        CPLFree( pszWKT );    }    return( CPLStrdup( szCoordSys ) );}/************************************************************************//*                      MITABExtractCoordSysBounds                      *//*                                                                      *//* Return TRUE if MIF coordsys string contains a BOUNDS parameter and   *//* Set x/y min/max values.                                              *//************************************************************************/GBool MITABExtractCoordSysBounds( const char * pszCoordSys,                                  double &dXMin, double &dYMin,                                  double &dXMax, double &dYMax ){    char        **papszFields;    if( pszCoordSys == NULL )        return FALSE;        papszFields = CSLTokenizeStringComplex( pszCoordSys, " ,()", TRUE, FALSE );    int iBounds = CSLFindString( papszFields, "Bounds" );    if (iBounds >= 0 && iBounds + 4 < CSLCount(papszFields))    {        dXMin = atof(papszFields[++iBounds]);        dYMin = atof(papszFields[++iBounds]);        dXMax = atof(papszFields[++iBounds]);        dYMax = atof(papszFields[++iBounds]);        CSLDestroy( papszFields );        return TRUE;    }    CSLDestroy( papszFields );    return FALSE;}/********************************************************************** *                     MITABCoordSys2TABProjInfo() * * Convert a MIF COORDSYS string into a TABProjInfo structure. * * Note that it would have been possible to achieve the same by calling * TABFile::SetSpatialRef( MITABCoordSys2SpatialRef() ) but this would  * involve lots of manipulations for cases where only a simple conversion * is required. * * Returns 0 on success, -1 on error. **********************************************************************/int MITABCoordSys2TABProjInfo(const char * pszCoordSys, TABProjInfo *psProj){    char        **papszFields;    // Set all fields to zero, equivalent of NonEarth Units "mi"    memset(psProj, 0, sizeof(TABProjInfo));    if( pszCoordSys == NULL )        return -1;        /*-----------------------------------------------------------------     * Parse the passed string into words.     *----------------------------------------------------------------*/    while(*pszCoordSys == ' ') pszCoordSys++;  // Eat leading spaces    if( EQUALN(pszCoordSys,"CoordSys",8) )        pszCoordSys += 9;        papszFields = CSLTokenizeStringComplex( pszCoordSys, " ,", TRUE, FALSE );    /*-----------------------------------------------------------------     * Clip off Bounds information.     *----------------------------------------------------------------*/    int         iBounds = CSLFindString( papszFields, "Bounds" );    while( iBounds != -1 && papszFields[iBounds] != NULL )    {        CPLFree( papszFields[iBounds] );        papszFields[iBounds] = NULL;        iBounds++;    }    /*-----------------------------------------------------------------     * Fetch the projection.     *----------------------------------------------------------------*/    char        **papszNextField;    if( CSLCount( papszFields ) >= 3        && EQUAL(papszFields[0],"Earth")        && EQUAL(papszFields[1],"Projection") )    {        psProj->nProjId = atoi(papszFields[2]);        papszNextField = papszFields + 3;    }    else if (CSLCount( papszFields ) >= 2             && EQUAL(papszFields[0],"NonEarth") )    {        // NonEarth Units "..." Bounds (x, y) (x, y)        psProj->nProjId = 0;        papszNextField = papszFields + 2;        if( papszNextField[0] != NULL && EQUAL(papszNextField[0],"Units") )            papszNextField++;    }    else    {        // Invalid projection string ???        if (CSLCount(papszFields) > 0)            CPLError(CE_Warning, CPLE_IllegalArg,                     "Failed parsing CoordSys: '%s'", pszCoordSys);        CSLDestroy(papszFields);        return -1;    }    /*-----------------------------------------------------------------     * Fetch the datum information.     *----------------------------------------------------------------*/    int         nDatum = 0;    if( psProj->nProjId != 0 && CSLCount(papszNextField) > 0 )    {        nDatum = atoi(papszNextField[0]);        papszNextField++;    }    if( (nDatum == 999 || nDatum == 9999)        && CSLCount(papszNextField) >= 4 )    {        psProj->nEllipsoidId = atoi(papszFields[0]);        psProj->dDatumShiftX = atof(papszNextField[1]);        psProj->dDatumShiftY = atof(papszNextField[2]);        psProj->dDatumShiftZ = atof(papszNextField[3]);        papszNextField += 4;        if( nDatum == 9999            && CSLCount(papszNextField) >= 5 )        {            psProj->adDatumParams[0] = atof(papszNextField[0]);            psProj->adDatumParams[1] = atof(papszNextField[1]);            psProj->adDatumParams[2] = atof(papszNextField[2]);            psProj->adDatumParams[3] = atof(papszNextField[3]);            psProj->adDatumParams[4] = atof(papszNextField[4]);            papszNextField += 5;        }    }    else if (nDatum != 999 && nDatum != 9999)    {    /*-----------------------------------------------------------------     * Find the datum, and collect it's parameters if possible.     *----------------------------------------------------------------*/        int         iDatum;        MapInfoDatumInfo *psDatumInfo = NULL;                for(iDatum=0; asDatumInfoList[iDatum].nMapInfoDatumID != -1; iDatum++)        {            if( asDatumInfoList[iDatum].nMapInfoDatumID == nDatum )            {                psDatumInfo = asDatumInfoList + iDatum;                break;            }        }        if( asDatumInfoList[iDatum].nMapInfoDatumID == -1            && nDatum != 999 && nDatum != 9999 )        {            /* use WGS84 */            psDatumInfo = asDatumInfoList + 0;        }        if( psDatumInfo != NULL )        {            psProj->nEllipsoidId = psDatumInfo->nEllipsoid;            psProj->dDatumShiftX = psDatumInfo->dfShiftX;            psProj->dDatumShiftY = psDatumInfo->dfShiftY;            psProj->dDatumShiftZ = psDatumInfo->dfShiftZ;            psProj->adDatumParams[0] = psDatumInfo->dfDatumParm0;            psProj->adDatumParams[1] = psDatumInfo->dfDatumParm1;            psProj->adDatumParams[2] = psDatumInfo->dfDatumParm2;            psProj->adDatumParams[3] = psDatumInfo->dfDatumParm3;            psProj->adDatumParams[4] = psDatumInfo->dfDatumParm4;        }    }        /*-----------------------------------------------------------------     * Fetch the units string.     *----------------------------------------------------------------*/    if( CSLCount(papszNextField) > 0 )    {        psProj->nUnitsId = TABUnitIdFromString(papszNextField[0]);        papszNextField++;    }    /*-----------------------------------------------------------------     * Finally the projection parameters.     *----------------------------------------------------------------*/    for(int iParam=0; iParam < 6 && CSLCount(papszNextField) > 0; iParam++)    {        psProj->adProjParams[iParam] = atof(papszNextField[0]);        papszNextField++;             }    return 0;}

⌨️ 快捷键说明

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