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

📄 ogrutils.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************/const char * OGRWktReadPoints( const char * pszInput,                               OGRRawPoint ** ppaoPoints, double **ppadfZ,                               int * pnMaxPoints,                               int * pnPointsRead ){    const char *pszOrigInput = pszInput;    *pnPointsRead = 0;    if( pszInput == NULL )        return NULL;    /* -------------------------------------------------------------------- *//*      Eat any leading white space.                                    *//* -------------------------------------------------------------------- */    while( *pszInput == ' ' || *pszInput == '\t' )        pszInput++;/* -------------------------------------------------------------------- *//*      If this isn't an opening bracket then we have a problem!        *//* -------------------------------------------------------------------- */    if( *pszInput != '(' )    {        CPLDebug( "OGR",                  "Expected '(', but got %s in OGRWktReadPoints().\n",                  pszInput );                          return pszInput;    }    pszInput++;/* ==================================================================== *//*      This loop reads a single point.  It will continue till we       *//*      run out of well formed points, or a closing bracket is          *//*      encountered.                                                    *//* ==================================================================== */    char        szDelim[OGR_WKT_TOKEN_MAX];        do {/* -------------------------------------------------------------------- *//*      Read the X and Y values, verify they are numeric.               *//* -------------------------------------------------------------------- */        char    szTokenX[OGR_WKT_TOKEN_MAX];        char    szTokenY[OGR_WKT_TOKEN_MAX];        pszInput = OGRWktReadToken( pszInput, szTokenX );        pszInput = OGRWktReadToken( pszInput, szTokenY );        if( (!isdigit(szTokenX[0]) && szTokenX[0] != '-' && szTokenX[0] != '.' )            || (!isdigit(szTokenY[0]) && szTokenY[0] != '-' && szTokenY[0] != '.') )            return NULL;/* -------------------------------------------------------------------- *//*      Do we need to grow the point list to hold this point?           *//* -------------------------------------------------------------------- */        if( *pnPointsRead == *pnMaxPoints )        {            *pnMaxPoints = *pnMaxPoints * 2 + 10;            *ppaoPoints = (OGRRawPoint *)                CPLRealloc(*ppaoPoints, sizeof(OGRRawPoint) * *pnMaxPoints);            if( *ppadfZ != NULL )            {                *ppadfZ = (double *)                    CPLRealloc(*ppadfZ, sizeof(double) * *pnMaxPoints);            }        }/* -------------------------------------------------------------------- *//*      Add point to list.                                              *//* -------------------------------------------------------------------- */        (*ppaoPoints)[*pnPointsRead].x = atof(szTokenX);        (*ppaoPoints)[*pnPointsRead].y = atof(szTokenY);/* -------------------------------------------------------------------- *//*      Do we have a Z coordinate?                                      *//* -------------------------------------------------------------------- */        pszInput = OGRWktReadToken( pszInput, szDelim );        if( isdigit(szDelim[0]) || szDelim[0] == '-' || szDelim[0] == '.' )        {            if( *ppadfZ == NULL )            {                *ppadfZ = (double *) CPLCalloc(sizeof(double),*pnMaxPoints);            }            (*ppadfZ)[*pnPointsRead] = atof(szDelim);                        pszInput = OGRWktReadToken( pszInput, szDelim );        }                (*pnPointsRead)++;/* -------------------------------------------------------------------- *//*      Read next delimeter ... it should be a comma if there are       *//*      more points.                                                    *//* -------------------------------------------------------------------- */        if( szDelim[0] != ')' && szDelim[0] != ',' )        {            CPLDebug( "OGR",                      "Corrupt input in OGRWktReadPoints()\n"                      "Got `%s' when expecting `,' or `)', near `%s' in %s.\n",                      szDelim, pszInput, pszOrigInput );            return NULL;        }            } while( szDelim[0] == ',' );    return pszInput;}/************************************************************************//*                             OGRMalloc()                              *//*                                                                      *//*      Cover for CPLMalloc()                                           *//************************************************************************/void *OGRMalloc( size_t size ){    return CPLMalloc( size );}/************************************************************************//*                             OGRCalloc()                              *//*                                                                      *//*      Cover for CPLCalloc()                                           *//************************************************************************/void * OGRCalloc( size_t count, size_t size ){    return CPLCalloc( count, size );}/************************************************************************//*                             OGRRealloc()                             *//*                                                                      *//*      Cover for CPLRealloc()                                          *//************************************************************************/void *OGRRealloc( void * pOld, size_t size ){    return CPLRealloc( pOld, size );}/************************************************************************//*                              OGRFree()                               *//*                                                                      *//*      Cover for CPLFree().                                            *//************************************************************************/void OGRFree( void * pMemory ){    CPLFree( pMemory );}/** * General utility option processing. * * This function is intended to provide a variety of generic commandline  * options for all OGR commandline utilities.  It takes care of the following * commandline options: *   *  --formats: report all format drivers configured. *  --format [format]: report details of one format driver.  *  --optfile filename: expand an option file into the argument list.  *  --config key value: set system configuration option.  *  --debug [on/off/value]: set debug level. *  --help-general: report detailed help on general options.  * * The argument array is replaced "in place" and should be freed with  * CSLDestroy() when no longer needed.  The typical usage looks something * like the following.  Note that the formats should be registered so that * the --formats and --format options will work properly. * *  int main( int argc, char ** argv ) *  {  *    OGRAllRegister(); * *    argc = OGRGeneralCmdLineProcessor( argc, &argv, 0 ); *    if( argc < 1 ) *        exit( -argc ); * * @param nArgc number of values in the argument list. * @param Pointer to the argument list array (will be updated in place).  * * @return updated nArgc argument count.  Return of 0 requests terminate  * without error, return of -1 requests exit with error code. */int OGRGeneralCmdLineProcessor( int nArgc, char ***ppapszArgv, int nOptions ){    char **papszReturn = NULL;    int  iArg;    char **papszArgv = *ppapszArgv;    (void) nOptions;    /* -------------------------------------------------------------------- *//*      Preserve the program name.                                      *//* -------------------------------------------------------------------- */    papszReturn = CSLAddString( papszReturn, papszArgv[0] );/* ==================================================================== *//*      Loop over all arguments.                                        *//* ==================================================================== */    for( iArg = 1; iArg < nArgc; iArg++ )    {/* -------------------------------------------------------------------- *//*      --config                                                        *//* -------------------------------------------------------------------- */        if( EQUAL(papszArgv[iArg],"--config") )        {            if( iArg + 2 >= nArgc )            {                CPLError( CE_Failure, CPLE_AppDefined,                           "--config option given without a key and value argument." );                CSLDestroy( papszReturn );                return -1;            }            CPLSetConfigOption( papszArgv[iArg+1], papszArgv[iArg+2] );            iArg += 2;        }/* -------------------------------------------------------------------- *//*      --mempreload                                                    *//* -------------------------------------------------------------------- */        else if( EQUAL(papszArgv[iArg],"--mempreload") )        {            int i;            if( iArg + 1 >= nArgc )            {                CPLError( CE_Failure, CPLE_AppDefined,                           "--mempreload option given without directory path.");                CSLDestroy( papszReturn );                return -1;            }                        char **papszFiles = CPLReadDir( papszArgv[iArg+1] );            if( CSLCount(papszFiles) == 0 )            {                CPLError( CE_Failure, CPLE_AppDefined,                           "--mempreload given invalid or empty directory.");                CSLDestroy( papszReturn );                return -1;            }                            for( i = 0; papszFiles[i] != NULL; i++ )            {                CPLString osOldPath, osNewPath;                                if( EQUAL(papszFiles[i],".") || EQUAL(papszFiles[i],"..") )                    continue;                osOldPath = CPLFormFilename( papszArgv[iArg+1],                                              papszFiles[i], NULL );                osNewPath.Printf( "/vsimem/%s", papszFiles[i] );                CPLDebug( "VSI", "Preloading %s to %s.",                           osOldPath.c_str(), osNewPath.c_str() );                if( CPLCopyFile( osNewPath, osOldPath ) != 0 )                    return -1;            }                        CSLDestroy( papszFiles );            iArg += 1;        }/* -------------------------------------------------------------------- *//*      --debug                                                         *//* -------------------------------------------------------------------- */        else if( EQUAL(papszArgv[iArg],"--debug") )        {            if( iArg + 1 >= nArgc )            {                CPLError( CE_Failure, CPLE_AppDefined,                           "--debug option given without debug level." );                CSLDestroy( papszReturn );                return -1;            }            CPLSetConfigOption( "CPL_DEBUG", papszArgv[iArg+1] );            iArg += 1;

⌨️ 快捷键说明

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