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

📄 cpl_conv.cpp

📁 读写ArcInfo Binary Grid的c代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        {            nRLBufferSize = nRLBufferSize*2 + 128;            pszRLBuffer = (char *) VSIRealloc(pszRLBuffer, nRLBufferSize);            if( pszRLBuffer == NULL )            {                nRLBufferSize = 0;                return NULL;            }        }/* -------------------------------------------------------------------- *//*      Do the actual read.                                             *//* -------------------------------------------------------------------- */        if( VSIFGets( pszRLBuffer+nReadSoFar, nRLBufferSize-nReadSoFar, fp )            == NULL )        {            CPLFree( pszRLBuffer );            pszRLBuffer = NULL;            nRLBufferSize = 0;            return NULL;        }        nReadSoFar = strlen(pszRLBuffer);    } while( nReadSoFar == nRLBufferSize - 1             && pszRLBuffer[nRLBufferSize-2] != 13             && pszRLBuffer[nRLBufferSize-2] != 10 );/* -------------------------------------------------------------------- *//*      Clear CR and LF off the end.                                    *//* -------------------------------------------------------------------- */    nLength = strlen(pszRLBuffer);    if( nLength > 0        && (pszRLBuffer[nLength-1] == 10 || pszRLBuffer[nLength-1] == 13) )    {        pszRLBuffer[--nLength] = '\0';        nStripped++;    }        if( nLength > 0        && (pszRLBuffer[nLength-1] == 10 || pszRLBuffer[nLength-1] == 13) )    {        pszRLBuffer[--nLength] = '\0';        nStripped++;    }/* -------------------------------------------------------------------- *//*      Check that there aren't any extra CR or LF characters           *//*      embedded in what is left.  I have encountered files with        *//*      embedded CR (13) characters that should have acted as line      *//*      terminators but got sucked up by VSIFGetc().                    *//* -------------------------------------------------------------------- */    for( i = 0; i < nLength; i++ )    {        if( pszRLBuffer[i] == 10 || pszRLBuffer[i] == 13 )        {            /* we need to chop off the buffer here, and seek the input back               to after the character that should have been the line               terminator. */            VSIFSeek( fp, (i+1) - (nLength+nStripped), SEEK_CUR );            pszRLBuffer[i] = '\0';        }    }    return( pszRLBuffer );}/************************************************************************//*                       CPLVerifyConfiguration()                       *//************************************************************************/void CPLVerifyConfiguration(){/* -------------------------------------------------------------------- *//*      Verify data types.                                              *//* -------------------------------------------------------------------- */    CPLAssert( sizeof(GInt32) == 4 );    CPLAssert( sizeof(GInt16) == 2 );    CPLAssert( sizeof(GByte) == 1 );    if( sizeof(GInt32) != 4 )        CPLError( CE_Fatal, CPLE_AppDefined,                   "sizeof(GInt32) == %d ... yow!\n",                   sizeof(GInt32) );/* -------------------------------------------------------------------- *//*      Verify byte order                                               *//* -------------------------------------------------------------------- */    GInt32   nTest;    nTest = 1;#ifdef CPL_LSB    if( ((GByte *) &nTest)[0] != 1 )#endif#ifdef CPL_MSB    if( ((GByte *) &nTest)[3] != 1 )#endif            CPLError( CE_Fatal, CPLE_AppDefined,                   "CPLVerifyConfiguration(): byte order set wrong.\n" );}/************************************************************************//*                         CPLGetConfigOption()                         *//************************************************************************/const char *CPLGetConfigOption( const char *pszKey, const char *pszDefault ){    const char *pszResult = CSLFetchNameValue( papszConfigOptions, pszKey );    if( pszResult == NULL )        pszResult = getenv( pszKey );    if( pszResult == NULL )        return pszDefault;    else        return pszResult;}/************************************************************************//*                         CPLSetConfigOption()                         *//************************************************************************/void CPLSetConfigOption( const char *pszKey, const char *pszValue ){    papszConfigOptions =         CSLSetNameValue( papszConfigOptions, pszKey, pszValue );}/************************************************************************//*                              CPLStat()                               *//*                                                                      *//*      Same as VSIStat() except it works on "C:" as if it were         *//*      "C:\".                                                          *//************************************************************************/int CPLStat( const char *pszPath, VSIStatBuf *psStatBuf ){    if( strlen(pszPath) == 2 && pszPath[1] == ':' )    {        char    szAltPath[10];                strcpy( szAltPath, pszPath );        strcat( szAltPath, "\\" );        return VSIStat( szAltPath, psStatBuf );    }    else        return VSIStat( pszPath, psStatBuf );}/************************************************************************//*                            proj_strtod()                             *//************************************************************************/static doubleproj_strtod(char *nptr, char **endptr) {    char c, *cp = nptr;    double result;    /*     * Scan for characters which cause problems with VC++ strtod()     */    while ((c = *cp) != '\0') {        if (c == 'd' || c == 'D') {            /*             * Found one, so NUL it out, call strtod(),             * then restore it and return             */            *cp = '\0';            result = strtod(nptr, endptr);            *cp = c;            return result;        }        ++cp;    }    /* no offending characters, just handle normally */    return strtod(nptr, endptr);}/************************************************************************//*                            CPLDMSToDec()                             *//************************************************************************/static const char*sym = "NnEeSsWw";static const double vm[] = { 1.0, 0.0166666666667, 0.00027777778 };double CPLDMSToDec( const char *is ){    int sign, n, nl;    char *p, *s, work[64];    double v, tv;    /* copy sting into work space */    while (isspace(sign = *is)) ++is;    for (n = sizeof(work), s = work, p = (char *)is; isgraph(*p) && --n ; )        *s++ = *p++;    *s = '\0';    /* it is possible that a really odd input (like lots of leading       zeros) could be truncated in copying into work.  But ... */    sign = *(s = work);    if (sign == '+' || sign == '-') s++;    else sign = '+';    for (v = 0., nl = 0 ; nl < 3 ; nl = n + 1 ) {        if (!(isdigit(*s) || *s == '.')) break;        if ((tv = proj_strtod(s, &s)) == HUGE_VAL)            return tv;        switch (*s) {          case 'D': case 'd':            n = 0; break;          case '\'':            n = 1; break;          case '"':            n = 2; break;          case 'r': case 'R':            if (nl) {                return 0.0;            }            ++s;            v = tv;            goto skip;          default:            v += tv * vm[nl];          skip: n = 4;            continue;        }        if (n < nl) {            return 0.0;        }        v += tv * vm[n];        ++s;    }    /* postfix sign */    if (*s && (p = (char *) strchr(sym, *s))) {        sign = (p - sym) >= 4 ? '-' : '+';        ++s;    }    if (sign == '-')        v = -v;    return v;}/************************************************************************//*                            CPLDecToDMS()                             *//*                                                                      *//*      Translate a decimal degrees value to a DMS string with          *//*      hemisphere.                                                     *//************************************************************************/const char *CPLDecToDMS( double dfAngle, const char * pszAxis,                          int nPrecision ){    int         nDegrees, nMinutes;    double      dfSeconds, dfABSAngle, dfEpsilon;    char        szFormat[30];    static char szBuffer[50];    const char  *pszHemisphere;        dfEpsilon = (0.5/3600.0) * pow(0.1,nPrecision);    dfABSAngle = ABS(dfAngle) + dfEpsilon;    nDegrees = (int) dfABSAngle;    nMinutes = (int) ((dfABSAngle - nDegrees) * 60);    dfSeconds = dfABSAngle * 3600 - nDegrees*3600 - nMinutes*60;    if( dfSeconds > dfEpsilon * 3600.0 )        dfSeconds -= dfEpsilon * 3600.0;    if( EQUAL(pszAxis,"Long") && dfAngle < 0.0 )        pszHemisphere = "W";    else if( EQUAL(pszAxis,"Long") )        pszHemisphere = "E";    else if( dfAngle < 0.0 )        pszHemisphere = "S";    else        pszHemisphere = "N";    sprintf( szFormat, "%%3dd%%2d\'%%.%df\"%s", nPrecision, pszHemisphere );    sprintf( szBuffer, szFormat, nDegrees, nMinutes, dfSeconds );    return( szBuffer );}/************************************************************************//*                         CPLStringToComplex()                         *//************************************************************************/void  CPLStringToComplex( const char *pszString,                                  double *pdfReal, double *pdfImag ){    int  i;    int  iPlus = -1, iImagEnd = -1;    while( *pszString == ' ' )        pszString++;    *pdfReal = atof(pszString);    *pdfImag = 0.0;    for( i = 0; pszString[i] != '\0' && pszString[i] != ' ' && i < 100; i++ )    {        if( pszString[i] == '+' && i > 0 )            iPlus = i;        if( pszString[i] == '-' && i > 0 )            iPlus = i;        if( pszString[i] == 'i' )            iImagEnd = i;    }    if( iPlus > -1 && iImagEnd > -1 && iPlus < iImagEnd )    {        *pdfImag = atof(pszString + iPlus);    }    return;}

⌨️ 快捷键说明

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