您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CPLRealloc函数代码示例

51自学网 2021-06-01 20:04:49
  C++
这篇教程C++ CPLRealloc函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中CPLRealloc函数的典型用法代码示例。如果您正苦于以下问题:C++ CPLRealloc函数的具体用法?C++ CPLRealloc怎么用?C++ CPLRealloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了CPLRealloc函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: CPLQuadTreeNodeAddFeatureAlg1

static void CPLQuadTreeNodeAddFeatureAlg1( CPLQuadTree* hQuadTree,                                           QuadTreeNode *psNode,                                           void* hFeature,                                           const CPLRectObj* pRect){    int i;    if (psNode->nNumSubNodes == 0)    {        /* If we have reached the max bucket capacity, try to insert */        /* in a subnode if possible */        if (psNode->nFeatures >= hQuadTree->nBucketCapacity)        {            CPLRectObj half1, half2, quad1, quad2, quad3, quad4;            CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &psNode->rect, &half1, &half2);            CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &half1, &quad1, &quad2);            CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &half2, &quad3, &quad4);            if (memcmp(&psNode->rect, &quad1, sizeof(CPLRectObj)) != 0 &&                memcmp(&psNode->rect, &quad2, sizeof(CPLRectObj)) != 0 &&                memcmp(&psNode->rect, &quad3, sizeof(CPLRectObj)) != 0 &&                memcmp(&psNode->rect, &quad4, sizeof(CPLRectObj)) != 0 &&                (CPL_RectContained(pRect, &quad1) ||                CPL_RectContained(pRect, &quad2) ||                CPL_RectContained(pRect, &quad3) ||                CPL_RectContained(pRect, &quad4)))            {                psNode->nNumSubNodes = 4;                psNode->apSubNode[0] = CPLQuadTreeNodeCreate(&quad1);                psNode->apSubNode[1] = CPLQuadTreeNodeCreate(&quad2);                psNode->apSubNode[2] = CPLQuadTreeNodeCreate(&quad3);                psNode->apSubNode[3] = CPLQuadTreeNodeCreate(&quad4);                int oldNumFeatures = psNode->nFeatures;                void** oldFeatures = psNode->pahFeatures;                CPLRectObj* pasOldBounds = psNode->pasBounds;                psNode->nFeatures = 0;                psNode->pahFeatures = NULL;                psNode->pasBounds = NULL;                /* redispatch existing pahFeatures in apSubNodes */                int i;                for(i=0;i<oldNumFeatures;i++)                {                    if( hQuadTree->pfnGetBounds == NULL )                        CPLQuadTreeNodeAddFeatureAlg1(hQuadTree, psNode, oldFeatures[i], &pasOldBounds[i]);                    else                    {                        CPLRectObj bounds;                        hQuadTree->pfnGetBounds(oldFeatures[i], &bounds);                        CPLQuadTreeNodeAddFeatureAlg1(hQuadTree, psNode, oldFeatures[i], &bounds);                    }                }                CPLFree(oldFeatures);                CPLFree(pasOldBounds);                /* recurse back on this psNode now that it has apSubNodes */                CPLQuadTreeNodeAddFeatureAlg1(hQuadTree, psNode, hFeature, pRect);                return;            }        }    }    else    {    /* -------------------------------------------------------------------- */    /*      If there are apSubNodes, then consider whether this object        */    /*      will fit in them.                                               */    /* -------------------------------------------------------------------- */        for(i=0; i<psNode->nNumSubNodes; i++ )        {            if( CPL_RectContained(pRect, &psNode->apSubNode[i]->rect))            {                CPLQuadTreeNodeAddFeatureAlg1( hQuadTree, psNode->apSubNode[i], hFeature, pRect);                return;            }        }    }/* -------------------------------------------------------------------- *//*      If none of that worked, just add it to this psNodes list.         *//* -------------------------------------------------------------------- */    psNode->nFeatures++;    if( psNode->nFeatures == 1 )    {        CPLAssert( psNode->pahFeatures == NULL );        psNode->pahFeatures = (void**) CPLMalloc( hQuadTree->nBucketCapacity * sizeof(void*) );        if( hQuadTree->pfnGetBounds == NULL )            psNode->pasBounds = (CPLRectObj*) CPLMalloc( hQuadTree->nBucketCapacity * sizeof(CPLRectObj) );    }    else if( psNode->nFeatures > hQuadTree->nBucketCapacity )    {        psNode->pahFeatures = (void**) CPLRealloc( psNode->pahFeatures, sizeof(void*) * psNode->nFeatures );        if( hQuadTree->pfnGetBounds == NULL )            psNode->pasBounds = (CPLRectObj*) CPLRealloc( psNode->pasBounds, sizeof(CPLRectObj) * psNode->nFeatures );    }    psNode->pahFeatures[psNode->nFeatures-1] = hFeature;    if( hQuadTree->pfnGetBounds == NULL )        psNode->pasBounds[psNode->nFeatures-1] = *pRect;//.........这里部分代码省略.........
开发者ID:0004c,项目名称:node-gdal,代码行数:101,


示例2: CPLDebug

OGRLayer *OGRSelafinDataSource::ICreateLayer( const char *pszLayerName, OGRSpatialReference *poSpatialRefP, OGRwkbGeometryType eGType, char ** papszOptions  ) {    CPLDebug("Selafin","CreateLayer(%s,%s)",pszLayerName,(eGType==wkbPoint)?"wkbPoint":"wkbPolygon");    // Verify we are in update mode.    if ( !bUpdate )    {        CPLError( CE_Failure, CPLE_NoWriteAccess,                  "Data source %s opened read-only.  "                  "New layer %s cannot be created.",                  pszName, pszLayerName );        return NULL;    }    // Check that new layer is a point or polygon layer    if( eGType != wkbPoint )    {        CPLError( CE_Failure, CPLE_NoWriteAccess, "Selafin format can only handle %s layers whereas input is %s/n.", OGRGeometryTypeToName(wkbPoint),OGRGeometryTypeToName(eGType));        return NULL;    }    // Parse options    const char *pszTemp=CSLFetchNameValue(papszOptions,"DATE");    const double dfDate = pszTemp != NULL ? CPLAtof(pszTemp) : 0.0;    // Set the SRS of the datasource if this is the first layer    if (nLayers==0 && poSpatialRefP!=NULL) {        poSpatialRef=poSpatialRefP;        poSpatialRef->Reference();        const char* szEpsg=poSpatialRef->GetAttrValue("GEOGCS|AUTHORITY",1);        int nEpsg=0;        if (szEpsg!=NULL) nEpsg=(int)strtol(szEpsg,NULL,10);        if (nEpsg==0) {            CPLError(CE_Warning,CPLE_AppDefined,"Could not find EPSG code for SRS. The SRS won't be saved in the datasource.");        } else {            poHeader->nEpsg=nEpsg;        }    }    // Create the new layer in the Selafin file by adding a "time step" at the end    // Beware, as the new layer shares the same header, it automatically contains the same number of features and fields as the existing ones. This may not be intuitive for the user.    if (VSIFSeekL(poHeader->fp,0,SEEK_END)!=0) return NULL;    if (Selafin::write_integer(poHeader->fp,4)==0 ||        Selafin::write_float(poHeader->fp,dfDate)==0 ||        Selafin::write_integer(poHeader->fp,4)==0) {        CPLError( CE_Failure, CPLE_FileIO, "Could not write to Selafin file %s./n",pszName);        return NULL;    }    double *pdfValues=NULL;    if (poHeader->nPoints>0)    {        pdfValues=(double*)VSI_MALLOC2_VERBOSE(sizeof(double),poHeader->nPoints);        if( pdfValues == NULL )            return NULL;    }    for (int i=0;i<poHeader->nVar;++i) {        if (Selafin::write_floatarray(poHeader->fp,pdfValues,poHeader->nPoints)==0) {            CPLError( CE_Failure, CPLE_FileIO, "Could not write to Selafin file %s./n",pszName);            CPLFree(pdfValues);            return NULL;        }    }    CPLFree(pdfValues);    VSIFFlushL(poHeader->fp);    poHeader->nSteps++;    // Create two layers as usual, one for points and one for elements    nLayers+=2;    papoLayers = (OGRSelafinLayer **) CPLRealloc(papoLayers, sizeof(void*) * nLayers);    CPLString szName=pszLayerName;    CPLString szNewLayerName=szName+"_p";    papoLayers[nLayers-2] =        new OGRSelafinLayer( szNewLayerName, bUpdate, poSpatialRef, poHeader,                             poHeader->nSteps-1, POINTS );    szNewLayerName=szName+"_e";    papoLayers[nLayers-1] =        new OGRSelafinLayer( szNewLayerName, bUpdate, poSpatialRef, poHeader,                             poHeader->nSteps-1, ELEMENTS );    return papoLayers[nLayers-2];}
开发者ID:ryandavid,项目名称:rotobox,代码行数:73,


示例3: while

int OGRMDBDataSource::OpenGDB(OGRMDBTable* poGDB_GeomColumns){    int iTableName = poGDB_GeomColumns->GetColumnIndex("TableName", TRUE);    int iFieldName = poGDB_GeomColumns->GetColumnIndex("FieldName", TRUE);    int iShapeType = poGDB_GeomColumns->GetColumnIndex("ShapeType", TRUE);    int iExtentLeft = poGDB_GeomColumns->GetColumnIndex("ExtentLeft", TRUE);    int iExtentRight = poGDB_GeomColumns->GetColumnIndex("ExtentRight", TRUE);    int iExtentBottom = poGDB_GeomColumns->GetColumnIndex("ExtentBottom", TRUE);    int iExtentTop = poGDB_GeomColumns->GetColumnIndex("ExtentTop", TRUE);    int iSRID = poGDB_GeomColumns->GetColumnIndex("SRID", TRUE);    int iHasZ = poGDB_GeomColumns->GetColumnIndex("HasZ", TRUE);    if (iTableName < 0 || iFieldName < 0 || iShapeType < 0 ||        iExtentLeft < 0 || iExtentRight < 0 || iExtentBottom < 0 ||        iExtentTop < 0 || iSRID < 0 || iHasZ < 0)        return FALSE;    while(poGDB_GeomColumns->GetNextRow())    {        OGRMDBLayer  *poLayer;        char* pszTableName = poGDB_GeomColumns->GetColumnAsString(iTableName);        char* pszFieldName = poGDB_GeomColumns->GetColumnAsString(iFieldName);        if (pszTableName == NULL || pszFieldName == NULL)        {            CPLFree(pszTableName);            CPLFree(pszFieldName);            continue;        }        OGRMDBTable* poTable = poDB->GetTable(pszTableName);        if (poTable == NULL)        {            CPLFree(pszTableName);            CPLFree(pszFieldName);            continue;        }        poLayer = new OGRMDBLayer( this, poTable );        if( poLayer->Initialize( pszTableName,                                 pszFieldName,                                 poGDB_GeomColumns->GetColumnAsInt(iShapeType),                                 poGDB_GeomColumns->GetColumnAsDouble(iExtentLeft),                                 poGDB_GeomColumns->GetColumnAsDouble(iExtentRight),                                 poGDB_GeomColumns->GetColumnAsDouble(iExtentBottom),                                 poGDB_GeomColumns->GetColumnAsDouble(iExtentTop),                                 poGDB_GeomColumns->GetColumnAsInt(iSRID),                                 poGDB_GeomColumns->GetColumnAsInt(iHasZ) )            != CE_None )        {            delete poLayer;        }        else        {            papoLayers = (OGRMDBLayer**)CPLRealloc(papoLayers, (nLayers+1) * sizeof(OGRMDBLayer*));            papoLayers[nLayers++] = poLayer;        }        CPLFree(pszTableName);        CPLFree(pszFieldName);    }    return TRUE;}
开发者ID:0004c,项目名称:node-gdal,代码行数:65,


示例4: CPLStrdup

//.........这里部分代码省略.........        CSLFetchNameValue( papszOptions, "GEOMETRY_NAME" );    if( pszGeometryName == NULL )        pszGeometryName = "ORA_GEOMETRY";    const bool bGeomNullable =        CPLFetchBool(const_cast<const char**>(papszOptions), "GEOMETRY_NULLABLE", true);/* -------------------------------------------------------------------- *//*      Create a basic table with the FID.  Also include the            *//*      geometry if this is not a PostGIS enabled table.                *//* -------------------------------------------------------------------- */    const char *pszExpectedFIDName =        CPLGetConfigOption( "OCI_FID", "OGR_FID" );    OGROCIStatement oStatement( poSession );/* -------------------------------------------------------------------- *//*      If geometry type is wkbNone, do not create a geometry column.   *//* -------------------------------------------------------------------- */    if ( CSLFetchNameValue( papszOptions, "TRUNCATE" ) == NULL  )    {        if (eType == wkbNone)        {            snprintf( szCommand, sizeof(szCommand),                     "CREATE TABLE /"%s/" ( "                     "%s INTEGER PRIMARY KEY)",                     pszSafeLayerName, pszExpectedFIDName);        }        else        {            snprintf( szCommand, sizeof(szCommand),                     "CREATE TABLE /"%s/" ( "                     "%s INTEGER PRIMARY KEY, "                     "%s %s%s )",                     pszSafeLayerName, pszExpectedFIDName,                     pszGeometryName, SDO_GEOMETRY,                     (!bGeomNullable) ? " NOT NULL":"");        }        if (bNoLogging)        {            char     szCommand2[1024];            strncpy( szCommand2, szCommand, sizeof(szCommand) );            snprintf( szCommand, sizeof(szCommand), "%s NOLOGGING "              "VARRAY %s.SDO_ELEM_INFO STORE AS SECUREFILE LOB (NOCACHE NOLOGGING) "              "VARRAY %s.SDO_ORDINATES STORE AS SECUREFILE LOB (NOCACHE NOLOGGING) ",              szCommand2, pszGeometryName, pszGeometryName);        }        if( oStatement.Execute( szCommand ) != CE_None )        {            CPLFree( pszSafeLayerName );            return NULL;        }    }/* -------------------------------------------------------------------- *//*      Create the layer object.                                        *//* -------------------------------------------------------------------- */    const char *pszLoaderFile = CSLFetchNameValue(papszOptions,"LOADER_FILE");    OGROCIWritableLayer *poLayer;    if( pszLoaderFile == NULL )        poLayer = new OGROCITableLayer( this, pszSafeLayerName, eType,                                        EQUAL(szSRSId,"NULL") ? -1 : atoi(szSRSId),                                        TRUE, TRUE );    else        poLayer =            new OGROCILoaderLayer( this, pszSafeLayerName,                                   pszGeometryName,                                   EQUAL(szSRSId,"NULL") ? -1 : atoi(szSRSId),                                   pszLoaderFile );/* -------------------------------------------------------------------- *//*      Set various options on the layer.                               *//* -------------------------------------------------------------------- */    poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions, "LAUNDER", false) );    poLayer->SetPrecisionFlag( CSLFetchBoolean(papszOptions, "PRECISION", true));    if( CSLFetchNameValue(papszOptions,"DIM") != NULL )        poLayer->SetDimension( atoi(CSLFetchNameValue(papszOptions,"DIM")) );    poLayer->SetOptions( papszOptions );    if( eType != wkbNone && !bGeomNullable )        poLayer->GetLayerDefn()->GetGeomFieldDefn(0)->SetNullable(FALSE);/* -------------------------------------------------------------------- *//*      Add layer to data source layer list.                            *//* -------------------------------------------------------------------- */    papoLayers = (OGROCILayer **)        CPLRealloc( papoLayers,  sizeof(OGROCILayer *) * (nLayers+1) );    papoLayers[nLayers++] = poLayer;    CPLFree( pszSafeLayerName );    return poLayer;}
开发者ID:nextgis-borsch,项目名称:lib_gdal,代码行数:101,


示例5: CPLErrorV

void    CPLErrorV(CPLErr eErrClass, int err_no, const char *fmt, va_list args ){    CPLErrorContext *psCtx = CPLGetErrorContext();    if (psCtx->nFailureIntoWarning > 0 && eErrClass == CE_Failure)        eErrClass = CE_Warning;/* -------------------------------------------------------------------- *//*      Expand the error message                                        *//* -------------------------------------------------------------------- */#if defined(HAVE_VSNPRINTF)    {        int nPR;        va_list wrk_args;#ifdef va_copy        va_copy( wrk_args, args );#else        wrk_args = args;#endif/* -------------------------------------------------------------------- *//*      If CPL_ACCUM_ERROR_MSG=ON accumulate the error messages,        *//*      rather than just replacing the last error message.              *//* -------------------------------------------------------------------- */        int nPreviousSize = 0;        if ( psCtx->psHandlerStack != NULL &&             EQUAL(CPLGetConfigOption( "CPL_ACCUM_ERROR_MSG", "" ), "ON"))        {            nPreviousSize = strlen(psCtx->szLastErrMsg);            if (nPreviousSize)            {                if (nPreviousSize + 1 + 1 >= psCtx->nLastErrMsgMax)                {                    psCtx->nLastErrMsgMax *= 3;                    psCtx = (CPLErrorContext *)                         CPLRealloc(psCtx, sizeof(CPLErrorContext) - DEFAULT_LAST_ERR_MSG_SIZE + psCtx->nLastErrMsgMax + 1);                    CPLSetTLS( CTLS_ERRORCONTEXT, psCtx, TRUE );                }                psCtx->szLastErrMsg[nPreviousSize] = '/n';                psCtx->szLastErrMsg[nPreviousSize+1] = '0';                nPreviousSize ++;            }        }        while( ((nPR = CPLvsnprintf( psCtx->szLastErrMsg+nPreviousSize,                                  psCtx->nLastErrMsgMax-nPreviousSize, fmt, wrk_args )) == -1                || nPR >= psCtx->nLastErrMsgMax-nPreviousSize-1)               && psCtx->nLastErrMsgMax < 1000000 )        {#ifdef va_copy            va_end( wrk_args );            va_copy( wrk_args, args );#else            wrk_args = args;#endif            psCtx->nLastErrMsgMax *= 3;            psCtx = (CPLErrorContext *)                 CPLRealloc(psCtx, sizeof(CPLErrorContext) - DEFAULT_LAST_ERR_MSG_SIZE + psCtx->nLastErrMsgMax + 1);            CPLSetTLS( CTLS_ERRORCONTEXT, psCtx, TRUE );        }        va_end( wrk_args );    }#else    // !HAVE_VSNPRINTF    CPLvsnprintf( psCtx->szLastErrMsg, psCtx->nLastErrMsgMax, fmt, args);#endif/* -------------------------------------------------------------------- *//*      Obfuscate any password in error message                         *//* -------------------------------------------------------------------- */    char* pszPassword = strstr(psCtx->szLastErrMsg, "password=");    if( pszPassword != NULL )    {        char* pszIter = pszPassword + strlen("password=");        while( *pszIter != ' ' && *pszIter != '/0' )        {            *pszIter = 'X';            pszIter ++;        }    }/* -------------------------------------------------------------------- *//*      If the user provided an handling function, then                 *//*      call it, otherwise print the error to stderr and return.        *//* -------------------------------------------------------------------- */    psCtx->nLastErrNo = err_no;    psCtx->eLastErrType = eErrClass;    if( CPLGetConfigOption("CPL_LOG_ERRORS",NULL) != NULL )        CPLDebug( "CPLError", "%s", psCtx->szLastErrMsg );/* -------------------------------------------------------------------- *//*      Invoke the current error handler.                               *//* -------------------------------------------------------------------- */    if( psCtx->psHandlerStack != NULL )    {        psCtx->psHandlerStack->pfnHandler(eErrClass, err_no, //.........这里部分代码省略.........
开发者ID:drownedout,项目名称:datamap,代码行数:101,


示例6: MAIN_START

//.........这里部分代码省略.........            nOrder = atoi(argv[++i]);            aosTO.SetNameValue("MAX_GCP_ORDER", argv[i] );        }        else if( EQUAL(argv[i],"-tps") )        {            aosTO.SetNameValue("METHOD", "GCP_TPS" );            nOrder = -1;        }        else if( EQUAL(argv[i],"-rpc") )        {            aosTO.SetNameValue("METHOD", "RPC" );        }        else if( EQUAL(argv[i],"-geoloc") )        {            aosTO.SetNameValue("METHOD", "GEOLOC_ARRAY" );        }        else if( EQUAL(argv[i],"-i") )        {            bInverse = TRUE;        }        else if( EQUAL(argv[i],"-to")  )        {            CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);            aosTO.AddString( argv[++i] );        }        else if( EQUAL(argv[i],"-gcp") )        {            CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(4);            char* endptr = nullptr;            /* -gcp pixel line easting northing [elev] */            nGCPCount++;            pasGCPs = static_cast<GDAL_GCP *>(                CPLRealloc(pasGCPs, sizeof(GDAL_GCP) * nGCPCount));            GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );            pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtof(argv[++i]);            pasGCPs[nGCPCount-1].dfGCPLine = CPLAtof(argv[++i]);            pasGCPs[nGCPCount-1].dfGCPX = CPLAtof(argv[++i]);            pasGCPs[nGCPCount-1].dfGCPY = CPLAtof(argv[++i]);            if( argv[i+1] != nullptr &&                (CPLStrtod(argv[i+1], &endptr) != 0.0 || argv[i+1][0] == '0') )            {                // Check that last argument is really a number and not a                // filename looking like a number (see ticket #863).                if (endptr && *endptr == 0)                    pasGCPs[nGCPCount-1].dfGCPZ = CPLAtof(argv[++i]);            }            /* should set id and info? */        }        else if( EQUAL(argv[i],"-output_xy") )        {            bOutputXY = TRUE;        }        else if( EQUAL(argv[i],"-coord")  && i + 2 < argc)        {            bCoordOnCommandLine = true;            dfX = CPLAtof(argv[++i]);            dfY = CPLAtof(argv[++i]);            if( i + 1 < argc && CPLGetValueType(argv[i+1]) != CPL_VALUE_STRING )                dfZ = CPLAtof(argv[++i]);            if( i + 1 < argc && CPLGetValueType(argv[i+1]) != CPL_VALUE_STRING )                dfT = CPLAtof(argv[++i]);        }        else if( argv[i][0] == '-' )
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:67,


示例7: while

//.........这里部分代码省略.........    GByte *pszIconvSrcBuf = (GByte*) CPLCalloc((nSrcLen+1),nTargetCharWidth);    unsigned int iSrc;    for( iSrc = 0; iSrc <= nSrcLen; iSrc++ )    {        if( nTargetCharWidth == 1 )            pszIconvSrcBuf[iSrc] = (GByte) pwszSource[iSrc];        else if( nTargetCharWidth == 2 )            ((short *)pszIconvSrcBuf)[iSrc] = (short) pwszSource[iSrc];        else if( nTargetCharWidth == 4 )            ((GInt32 *)pszIconvSrcBuf)[iSrc] = pwszSource[iSrc];    }/* -------------------------------------------------------------------- *//*      Create the iconv() translation object.                          *//* -------------------------------------------------------------------- */    iconv_t sConv;    sConv = iconv_open( pszDstEncoding, pszSrcEncoding );    if ( sConv == (iconv_t)-1 )    {        CPLFree( pszIconvSrcBuf );        CPLError( CE_Warning, CPLE_AppDefined,                   "Recode from %s to %s failed with the error: /"%s/".",                   pszSrcEncoding, pszDstEncoding, strerror(errno) );        return CPLStrdup( "" );    }/* -------------------------------------------------------------------- *//*      XXX: There is a portability issue: iconv() function could be    *//*      declared differently on different platforms. The second         *//*      argument could be declared as char** (as POSIX defines) or      *//*      as a const char**. Handle it with the ICONV_CONST macro here.   *//* -------------------------------------------------------------------- */    ICONV_CONST char *pszSrcBuf = (ICONV_CONST char *) pszIconvSrcBuf;    /* iconv expects a number of bytes, not characters */    nSrcLen *= sizeof(wchar_t);/* -------------------------------------------------------------------- *//*      Allocate destination buffer.                                    *//* -------------------------------------------------------------------- */    size_t  nDstCurLen = MAX(CPL_RECODE_DSTBUF_SIZE, nSrcLen + 1);    size_t  nDstLen = nDstCurLen;    char    *pszDestination = (char *)CPLCalloc( nDstCurLen, sizeof(char) );    char    *pszDstBuf = pszDestination;    while ( nSrcLen > 0 )    {        size_t  nConverted =            iconv( sConv, &pszSrcBuf, &nSrcLen, &pszDstBuf, &nDstLen );        if ( nConverted == (size_t)-1 )        {            if ( errno == EILSEQ )            {                // Skip the invalid sequence in the input string.                nSrcLen--;                pszSrcBuf += sizeof(wchar_t);                static int bHasWarned = FALSE;                if (!bHasWarned)                {                    bHasWarned = TRUE;                    CPLError(CE_Warning, CPLE_AppDefined,                            "One or several characters couldn't be converted correctly from %s to %s./n"                            "This warning will not be emitted anymore",                             pszSrcEncoding, pszDstEncoding);                }                continue;            }            else if ( errno == E2BIG )            {                // We are running out of the output buffer.                // Dynamically increase the buffer size.                size_t nTmp = nDstCurLen;                nDstCurLen *= 2;                pszDestination =                    (char *)CPLRealloc( pszDestination, nDstCurLen );                pszDstBuf = pszDestination + nTmp - nDstLen;                nDstLen += nDstCurLen - nTmp;                continue;            }            else                break;        }    }    pszDestination[nDstCurLen - nDstLen] = '/0';    iconv_close( sConv );    CPLFree( pszIconvSrcBuf );    return pszDestination;}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:101,


示例8: LaunderName

//.........这里部分代码省略.........    else if( wkbFlatten(eType) == wkbGeometryCollection )    {    	if( IsNewIngres() )            pszGeometryType = "GEOMETRYCOLLECTION";    }    else if( wkbFlatten(eType) == wkbUnknown )    {    	if( IsNewIngres() )            // this is also used as the generic geometry type.            pszGeometryType = "GEOMETRYCOLLECTION";    }    /* -------------------------------------------------------------------- */    /*      Try to get the SRS Id of this spatial reference system,         */    /*      adding tot the srs table if needed.                             */    /* -------------------------------------------------------------------- */    int nSRSId = -1;        if( poSRS != NULL && IsNewIngres() == TRUE )        nSRSId = FetchSRSId( poSRS );/* -------------------------------------------------------------------- *//*      Form table creation command.                                    *//* -------------------------------------------------------------------- */    CPLString osCommand;    if( pszGeometryType == NULL )    {        osCommand.Printf( "CREATE TABLE %s ( "                          "   %s INTEGER )",                          pszLayerName, pszExpectedFIDName );    }    else    {        if(nSRSId != -1)        {            osCommand.Printf( "CREATE TABLE %s ("                              " %s INTEGER NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS seq_%s IDENTITY (START WITH 1 INCREMENT BY 1),"                                " %s %s SRID %d ) ",                              pszLayerName,                                                            pszExpectedFIDName,                              pszLayerName,                              pszGeomColumnName,                              pszGeometryType,                              nSRSId);        }        else        {            osCommand.Printf( "CREATE TABLE %s ("                              " %s INTEGER NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS seq_%s IDENTITY (START WITH 1 INCREMENT BY 1),"                              " %s %s )",                              pszLayerName,                                                            pszExpectedFIDName,                              pszLayerName,                              pszGeomColumnName,                              pszGeometryType);        }    }/* -------------------------------------------------------------------- *//*      Execute the create table command.                               *//* -------------------------------------------------------------------- */    {        OGRIngresStatement  oStmt( hConn );        if( !oStmt.ExecuteSQL( osCommand ) )            return NULL;    }/* -------------------------------------------------------------------- *//*      Create the layer object.                                        *//* -------------------------------------------------------------------- */    OGRIngresTableLayer     *poLayer;    OGRErr                  eErr;    poLayer = new OGRIngresTableLayer( this, pszLayerName, TRUE, nSRSId );    eErr = poLayer->Initialize(pszLayerName);    if (eErr == OGRERR_FAILURE)    {        delete poLayer;        return NULL;    }    poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions,"LAUNDER",TRUE) );    poLayer->SetPrecisionFlag( CSLFetchBoolean(papszOptions,"PRECISION",TRUE));/* -------------------------------------------------------------------- *//*      Add layer to data source layer list.                            *//* -------------------------------------------------------------------- */    papoLayers = (OGRIngresLayer **)        CPLRealloc( papoLayers,  sizeof(OGRIngresLayer *) * (nLayers+1) );    papoLayers[nLayers++] = poLayer;    CPLFree( pszLayerName );    return poLayer;}
开发者ID:0004c,项目名称:node-gdal,代码行数:101,


示例9: CPLStrdup

int OGRSDTSDataSource::Open( const char * pszFilename, int bTestOpen ){    pszName = CPLStrdup( pszFilename );/* -------------------------------------------------------------------- *//*      Verify that the extension is DDF if we are testopening.         *//* -------------------------------------------------------------------- */    if( bTestOpen && !(strlen(pszFilename) > 4 &&        EQUAL(pszFilename+strlen(pszFilename)-4,".ddf")) )        return FALSE;/* -------------------------------------------------------------------- *//*      Check a few bits of the header to see if it looks like an       *//*      SDTS file (really, if it looks like an ISO8211 file).           *//* -------------------------------------------------------------------- */    if( bTestOpen )    {        FILE    *fp;        char    pachLeader[10];        fp = VSIFOpen( pszFilename, "rb" );        if( fp == NULL )            return FALSE;        if( VSIFRead( pachLeader, 1, 10, fp ) != 10            || (pachLeader[5] != '1' && pachLeader[5] != '2'                && pachLeader[5] != '3' )            || pachLeader[6] != 'L'            || (pachLeader[8] != '1' && pachLeader[8] != ' ') )        {            VSIFClose( fp );            return FALSE;        }        VSIFClose( fp );    }/* -------------------------------------------------------------------- *//*      Create a transfer, and open it.                                 *//* -------------------------------------------------------------------- */    poTransfer = new SDTSTransfer();    if( !poTransfer->Open( pszFilename ) )    {        delete poTransfer;        poTransfer = NULL;        return FALSE;    }/* -------------------------------------------------------------------- *//*      Initialize the projection.                                      *//* -------------------------------------------------------------------- */    SDTS_XREF   *poXREF = poTransfer->GetXREF();    poSRS = new OGRSpatialReference();    if( EQUAL(poXREF->pszSystemName,"UTM") )    {        poSRS->SetUTM( poXREF->nZone, TRUE );    }    if( EQUAL(poXREF->pszDatum,"NAS") )        poSRS->SetGeogCS("NAD27", "North_American_Datum_1927",                         "Clarke 1866", 6378206.4, 294.978698213901 );    else if( EQUAL(poXREF->pszDatum,"NAX") )        poSRS->SetGeogCS("NAD83", "North_American_Datum_1983",                         "GRS 1980", 6378137, 298.257222101 );    else if( EQUAL(poXREF->pszDatum,"WGC") )        poSRS->SetGeogCS("WGS 72", "WGS_1972", "NWL 10D", 6378135, 298.26 );    else if( EQUAL(poXREF->pszDatum,"WGE") )        poSRS->SetGeogCS("WGS 84", "WGS_1984",                         "WGS 84", 6378137, 298.257223563 );    else        poSRS->SetGeogCS("WGS 84", "WGS_1984",                         "WGS 84", 6378137, 298.257223563 );    poSRS->Fixup();/* -------------------------------------------------------------------- *//*      Initialize a layer for each source dataset layer.               *//* -------------------------------------------------------------------- */    for( int iLayer = 0; iLayer < poTransfer->GetLayerCount(); iLayer++ )    {        SDTSIndexedReader       *poReader;        if( poTransfer->GetLayerType( iLayer ) == SLTRaster )            continue;        poReader = poTransfer->GetLayerIndexedReader( iLayer );        if( poReader == NULL )            continue;        papoLayers = (OGRSDTSLayer **)            CPLRealloc( papoLayers, sizeof(void*) * ++nLayers );//.........这里部分代码省略.........
开发者ID:bbradbury,项目名称:lib_gdal,代码行数:101,


示例10: CPLError

OGRLayer *OGRTABDataSource::ICreateLayer( const char * pszLayerName,                               OGRSpatialReference *poSRSIn,                               OGRwkbGeometryType /* eGeomTypeIn */,                               char ** papszOptions ){    IMapInfoFile        *poFile;    char                *pszFullFilename;    const char          *pszOpt = NULL;    if( !m_bUpdate )    {        CPLError( CE_Failure, CPLE_AppDefined,                     "Cannot create layer on read-only dataset.");        return NULL;    }/* -------------------------------------------------------------------- *//*      If it's a single file mode file, then we may have already       *//*      instantiated the low level layer.   We would just need to       *//*      reset the coordinate system and (potentially) bounds.           *//* -------------------------------------------------------------------- */    if( m_bSingleFile )    {        if( m_bSingleLayerAlreadyCreated )        {            CPLError( CE_Failure, CPLE_AppDefined,                       "Unable to create new layers in this single file dataset.");            return NULL;        }        m_bSingleLayerAlreadyCreated = TRUE;        poFile = (IMapInfoFile *) m_papoLayers[0];    }    else    {        if( m_bCreateMIF )        {            pszFullFilename = CPLStrdup( CPLFormFilename( m_pszDirectory,                                                          pszLayerName, "mif" ) );                        poFile = new MIFFile;        }        else        {            pszFullFilename = CPLStrdup( CPLFormFilename( m_pszDirectory,                                                          pszLayerName, "tab" ) );                        poFile = new TABFile;        }                if( poFile->Open( pszFullFilename, TABWrite, FALSE ) != 0 )        {            CPLFree( pszFullFilename );            delete poFile;            return FALSE;        }        m_nLayerCount++;        m_papoLayers = (IMapInfoFile **)            CPLRealloc(m_papoLayers,sizeof(void*)*m_nLayerCount);        m_papoLayers[m_nLayerCount-1] = poFile;        CPLFree( pszFullFilename );    }    poFile->SetDescription( poFile->GetName() );/* -------------------------------------------------------------------- *//*      Assign the coordinate system (if provided) and set              *//*      reasonable bounds.                                              *//* -------------------------------------------------------------------- */    if( poSRSIn != NULL )    {        poFile->SetSpatialRef( poSRSIn );        // SetSpatialRef() has cloned the passed geometry        poFile->GetLayerDefn()->GetGeomFieldDefn(0)->SetSpatialRef(poFile->GetSpatialRef());    }    // Pull out the bounds if supplied    if( (pszOpt=CSLFetchNameValue(papszOptions, "BOUNDS")) != NULL ) {        double dfBounds[4];        if( CPLsscanf(pszOpt, "%lf,%lf,%lf,%lf", &dfBounds[0],                                           &dfBounds[1],                                           &dfBounds[2],                                           &dfBounds[3]) != 4 )        {            CPLError( CE_Failure, CPLE_IllegalArg,                        "Invalid BOUNDS parameter, expected min_x,min_y,max_x,max_y/n" );        }        else        {            poFile->SetBounds( dfBounds[0], dfBounds[1], dfBounds[2], dfBounds[3] );        }    }    if( !poFile->IsBoundsSet() && !m_bCreateMIF )//.........这里部分代码省略.........
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:101,


示例11: oStatement

OGRSpatialReference *OGRIngresDataSource::FetchSRS( int nId ){    char         szCommand[1024];    char           **papszRow;    OGRIngresStatement oStatement(GetConn());                if( nId < 0 )        return NULL;    /*     * Only the new Ingres Geospatial library     */    if(IsNewIngres() == FALSE)        return NULL;/* -------------------------------------------------------------------- *//*      First, we look through our SRID cache, is it there?             *//* -------------------------------------------------------------------- */    int  i;    for( i = 0; i < nKnownSRID; i++ )    {        if( panSRID[i] == nId )            return papoSRS[i];    }    OGRSpatialReference *poSRS = NULL;    sprintf( szCommand,         "SELECT srtext FROM spatial_ref_sys WHERE srid = %d",         nId );    oStatement.ExecuteSQL(szCommand);            char    *pszWKT = NULL;    papszRow = NULL;        papszRow = oStatement.GetRow();    if( papszRow != NULL)    {        if(papszRow[0] != NULL )        {            //VARCHAR uses the first two bytes for length            pszWKT = &papszRow[0][2];        }    }     poSRS = new OGRSpatialReference();     if( pszWKT == NULL || poSRS->importFromWkt( &pszWKT ) != OGRERR_NONE )     {         delete poSRS;         poSRS = NULL;     }/* -------------------------------------------------------------------- *//*      Add to the cache.                                               *//* -------------------------------------------------------------------- */    panSRID = (int *) CPLRealloc(panSRID,sizeof(int) * (nKnownSRID+1) );    papoSRS = (OGRSpatialReference **)         CPLRealloc(papoSRS, sizeof(void*) * (nKnownSRID + 1) );    panSRID[nKnownSRID] = nId;    papoSRS[nKnownSRID] = poSRS;    return poSRS;}
开发者ID:0004c,项目名称:node-gdal,代码行数:67,


示例12: CPLAssert

int OGRTABDataSource::Open( GDALOpenInfo* poOpenInfo, int bTestOpen ){    CPLAssert( m_pszName == NULL );    m_pszName = CPLStrdup( poOpenInfo->pszFilename );    m_bUpdate = (poOpenInfo->eAccess == GA_Update );/* -------------------------------------------------------------------- *//*      If it is a file, try to open as a Mapinfo file.                 *//* -------------------------------------------------------------------- */    if( !poOpenInfo->bIsDirectory )    {        IMapInfoFile    *poFile;        poFile = IMapInfoFile::SmartOpen( m_pszName, m_bUpdate, bTestOpen );        if( poFile == NULL )            return FALSE;        poFile->SetDescription( poFile->GetName() );        m_nLayerCount = 1;        m_papoLayers = (IMapInfoFile **) CPLMalloc(sizeof(void*));        m_papoLayers[0] = poFile;        m_pszDirectory = CPLStrdup( CPLGetPath(m_pszName) );        m_bSingleFile = TRUE;        m_bSingleLayerAlreadyCreated = TRUE;    }/* -------------------------------------------------------------------- *//*      Otherwise, we need to scan the whole directory for files        *//*      ending in .tab or .mif.                                         *//* -------------------------------------------------------------------- */    else    {        char    **papszFileList = CPLReadDir( m_pszName );                m_pszDirectory = CPLStrdup( m_pszName );        for( int iFile = 0;             papszFileList != NULL && papszFileList[iFile] != NULL;             iFile++ )        {            IMapInfoFile *poFile;            const char  *pszExtension = CPLGetExtension(papszFileList[iFile]);            char        *pszSubFilename;            if( !EQUAL(pszExtension,"tab") && !EQUAL(pszExtension,"mif") )                continue;            pszSubFilename = CPLStrdup(                CPLFormFilename( m_pszDirectory, papszFileList[iFile], NULL ));            poFile = IMapInfoFile::SmartOpen( pszSubFilename, m_bUpdate, bTestOpen );            CPLFree( pszSubFilename );                        if( poFile == NULL )            {                CSLDestroy( papszFileList );                return FALSE;            }            poFile->SetDescription( poFile->GetName() );            m_nLayerCount++;            m_papoLayers = (IMapInfoFile **)                CPLRealloc(m_papoLayers,sizeof(void*)*m_nLayerCount);            m_papoLayers[m_nLayerCount-1] = poFile;        }        CSLDestroy( papszFileList );        if( m_nLayerCount == 0 )        {            if( !bTestOpen )                CPLError( CE_Failure, CPLE_OpenFailed,                          "No mapinfo files found in directory %s./n",                          m_pszDirectory );                        return FALSE;        }    }    return TRUE;}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:86,


示例13: CPLMalloc

CPLString &CPLString::vPrintf( const char *pszFormat, va_list args ){/* -------------------------------------------------------------------- *//*      This implementation for platforms without vsnprintf() will      *//*      just plain fail if the formatted contents are too large.        *//* -------------------------------------------------------------------- */#if !defined(HAVE_VSNPRINTF)    char *pszBuffer = (char *) CPLMalloc(30000);    if( vsprintf( pszBuffer, pszFormat, args) > 29998 )    {        CPLError( CE_Fatal, CPLE_AppDefined,                   "CPLString::vPrintf() ... buffer overrun." );    }    *this = pszBuffer;    CPLFree( pszBuffer );/* -------------------------------------------------------------------- *//*      This should grow a big enough buffer to hold any formatted      *//*      result.                                                         *//* -------------------------------------------------------------------- */#else    char szModestBuffer[500];    int nPR;    va_list wrk_args;#ifdef va_copy    va_copy( wrk_args, args );#else    wrk_args = args;#endif        nPR = vsnprintf( szModestBuffer, sizeof(szModestBuffer), pszFormat,                      wrk_args );    if( nPR == -1 || nPR >= (int) sizeof(szModestBuffer)-1 )    {        int nWorkBufferSize = 2000;        char *pszWorkBuffer = (char *) CPLMalloc(nWorkBufferSize);#ifdef va_copy        va_end( wrk_args );        va_copy( wrk_args, args );#else        wrk_args = args;#endif        while( (nPR=vsnprintf( pszWorkBuffer, nWorkBufferSize, pszFormat,wrk_args))               >= nWorkBufferSize-1                || nPR == -1 )        {            nWorkBufferSize *= 4;            pszWorkBuffer = (char *) CPLRealloc(pszWorkBuffer,                                                 nWorkBufferSize );#ifdef va_copy            va_end( wrk_args );            va_copy( wrk_args, args );#else            wrk_args = args;#endif        }        *this = pszWorkBuffer;        CPLFree( pszWorkBuffer );    }    else    {        *this = szModestBuffer;    }    va_end( wrk_args );#endif    return *this;}
开发者ID:dlsyaim,项目名称:osgEarthX,代码行数:72,


示例14: CPLQuadTreeNodeAddFeatureAlg2

static void CPLQuadTreeNodeAddFeatureAlg2( CPLQuadTree *hQuadTree,                                           QuadTreeNode *psNode,                                           void* hFeature,                                           const CPLRectObj* pRect,                                           int nMaxDepth){    int i;  /* -------------------------------------------------------------------- */  /*      If there are apSubNodes, then consider whether this object        */  /*      will fit in them.                                               */  /* -------------------------------------------------------------------- */    if( nMaxDepth > 1 && psNode->nNumSubNodes > 0 )    {        for(i=0; i<psNode->nNumSubNodes; i++ )        {            if( CPL_RectContained(pRect, &psNode->apSubNode[i]->rect))            {                CPLQuadTreeNodeAddFeatureAlg2( hQuadTree, psNode->apSubNode[i],                                               hFeature, pRect, nMaxDepth-1);                return;            }        }    }  /* -------------------------------------------------------------------- */  /*      Otherwise, consider creating four apSubNodes if could fit into    */  /*      them, and adding to the appropriate apSubNode.                    */  /* -------------------------------------------------------------------- */    else if( nMaxDepth > 1 && psNode->nNumSubNodes == 0 )    {        CPLRectObj half1, half2, quad1, quad2, quad3, quad4;        CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &psNode->rect, &half1, &half2);        CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &half1, &quad1, &quad2);        CPLQuadTreeSplitBounds(hQuadTree->dfSplitRatio, &half2, &quad3, &quad4);        if( memcmp(&psNode->rect, &quad1, sizeof(CPLRectObj)) != 0 &&            memcmp(&psNode->rect, &quad2, sizeof(CPLRectObj)) != 0 &&            memcmp(&psNode->rect, &quad3, sizeof(CPLRectObj)) != 0 &&            memcmp(&psNode->rect, &quad4, sizeof(CPLRectObj)) != 0 &&            (CPL_RectContained(pRect, &quad1) ||             CPL_RectContained(pRect, &quad2) ||             CPL_RectContained(pRect, &quad3) ||             CPL_RectContained(pRect, &quad4)) )        {            psNode->nNumSubNodes = 4;            psNode->apSubNode[0] = CPLQuadTreeNodeCreate(&quad1);            psNode->apSubNode[1] = CPLQuadTreeNodeCreate(&quad2);            psNode->apSubNode[2] = CPLQuadTreeNodeCreate(&quad3);            psNode->apSubNode[3] = CPLQuadTreeNodeCreate(&quad4);            /* recurse back on this psNode now that it has apSubNodes */            CPLQuadTreeNodeAddFeatureAlg2(hQuadTree, psNode, hFeature, pRect, nMaxDepth);            return;        }    }/* -------------------------------------------------------------------- *//*      If none of that worked, just add it to this psNodes list.         *//* -------------------------------------------------------------------- */    psNode->nFeatures++;    psNode->pahFeatures =            (void**) CPLRealloc( psNode->pahFeatures,                                 sizeof(void*) * psNode->nFeatures );    if( hQuadTree->pfnGetBounds == NULL )    {        psNode->pasBounds =            (CPLRectObj*) CPLRealloc( psNode->pasBounds,                                 sizeof(CPLRectObj) * psNode->nFeatures );    }    psNode->pahFeatures[psNode->nFeatures-1] = hFeature;    if( hQuadTree->pfnGetBounds == NULL )    {        psNode->pasBounds[psNode->nFeatures-1] = *pRect;    }}
开发者ID:0004c,项目名称:node-gdal,代码行数:78,


示例15: CPLAssert

//.........这里部分代码省略.........                    osLayerName += ".";                }                osLayerName += oTableList.GetColData(2);                papszTables = CSLAddString( papszTables, osLayerName );                papszGeomCol = CSLAddString(papszGeomCol,"");            }        }    }/* -------------------------------------------------------------------- *//*      If we have an explicit list of requested tables, use them       *//*      (non-spatial).                                                  *//* -------------------------------------------------------------------- */    for( int iTable = 0;         papszTables != nullptr && papszTables[iTable] != nullptr;         iTable++ )    {        if( strlen(papszGeomCol[iTable]) > 0 )            OpenTable( papszTables[iTable], papszGeomCol[iTable], bUpdate );        else            OpenTable( papszTables[iTable], nullptr, bUpdate );    }    CSLDestroy( papszTables );    CSLDestroy( papszGeomCol );/* -------------------------------------------------------------------- *//*      If no explicit list of tables was given, check for a list in    *//*      a geometry_columns table.                                       *//* -------------------------------------------------------------------- */    if ( pszSRSTableName )    {        CPLODBCStatement oSRSList( &oSession );        if ( !pszSRTextCol )            pszSRTextCol = CPLStrdup( "srtext" );        if ( !pszSRIDCol )            pszSRIDCol = CPLStrdup( "srid" );        oSRSList.Append( "SELECT " );        oSRSList.Append( pszSRIDCol );        oSRSList.Append( "," );        oSRSList.Append( pszSRTextCol );        oSRSList.Append( " FROM " );        oSRSList.Append( pszSRSTableName );        CPLDebug( "OGR_ODBC", "ExecuteSQL(%s) to read SRS table",                  oSRSList.GetCommand() );        if ( oSRSList.ExecuteSQL() )        {            int nRows = 256;     // A reasonable number of SRIDs to start from            panSRID = (int *)CPLMalloc( nRows * sizeof(int) );            papoSRS = (OGRSpatialReference **)                CPLMalloc( nRows * sizeof(OGRSpatialReference*) );            while ( oSRSList.Fetch() )            {                const char *pszSRID = oSRSList.GetColData( pszSRIDCol );                if ( !pszSRID )                    continue;                const char *pszSRText = oSRSList.GetColData( pszSRTextCol );                if ( pszSRText )                {                    if ( nKnownSRID > nRows )                    {                        nRows *= 2;                        panSRID = (int *)CPLRealloc( panSRID,                                                     nRows * sizeof(int) );                        papoSRS = (OGRSpatialReference **)                            CPLRealloc( papoSRS,                            nRows * sizeof(OGRSpatialReference*) );                    }                    panSRID[nKnownSRID] = atoi( pszSRID );                    papoSRS[nKnownSRID] = new OGRSpatialReference();                    if ( papoSRS[nKnownSRID]->importFromWkt( pszSRText )                         != OGRERR_NONE )                    {                        delete papoSRS[nKnownSRID];                        continue;                    }                    nKnownSRID++;                }            }        }    }    if ( pszSRIDCol )        CPLFree( pszSRIDCol );    if ( pszSRTextCol )        CPLFree( pszSRTextCol );    if ( pszSRSTableName )        CPLFree( pszSRSTableName );    return TRUE;}
开发者ID:koordinates,项目名称:gdal,代码行数:101,


示例16: CPLTestBool

//.........这里部分代码省略.........            ReleaseResultSet(poPostGISVersionLayer);        }    }    if( osAPIKey.size() && bUpdateIn )    {        ExecuteSQLInternal(                "DROP FUNCTION IF EXISTS ogr_table_metadata(TEXT,TEXT); "                "CREATE OR REPLACE FUNCTION ogr_table_metadata(schema_name TEXT, table_name TEXT) RETURNS TABLE "                "(attname TEXT, typname TEXT, attlen INT, format_type TEXT, "                "attnum INT, attnotnull BOOLEAN, indisprimary BOOLEAN, "                "defaultexpr TEXT, dim INT, srid INT, geomtyp TEXT, srtext TEXT) AS $$ "                "SELECT a.attname::text, t.typname::text, a.attlen::int, "                        "format_type(a.atttypid,a.atttypmod)::text, "                        "a.attnum::int, "                        "a.attnotnull::boolean, "                        "i.indisprimary::boolean, "                        "pg_get_expr(def.adbin, c.oid)::text AS defaultexpr, "                        "(CASE WHEN t.typname = 'geometry' THEN postgis_typmod_dims(a.atttypmod) ELSE NULL END)::int dim, "                        "(CASE WHEN t.typname = 'geometry' THEN postgis_typmod_srid(a.atttypmod) ELSE NULL END)::int srid, "                        "(CASE WHEN t.typname = 'geometry' THEN postgis_typmod_type(a.atttypmod) ELSE NULL END)::text geomtyp, "                        "srtext "                "FROM pg_class c "                "JOIN pg_attribute a ON a.attnum > 0 AND "                                        "a.attrelid = c.oid AND c.relname = $2 "                                        "AND c.relname IN (SELECT CDB_UserTables())"                "JOIN pg_type t ON a.atttypid = t.oid "                "JOIN pg_namespace n ON c.relnamespace=n.oid AND n.nspname = $1 "                "LEFT JOIN pg_index i ON c.oid = i.indrelid AND "                                        "i.indisprimary = 't' AND a.attnum = ANY(i.indkey) "                "LEFT JOIN pg_attrdef def ON def.adrelid = c.oid AND "                                            "def.adnum = a.attnum "                "LEFT JOIN spatial_ref_sys srs ON srs.srid = postgis_typmod_srid(a.atttypmod) "                "ORDER BY a.attnum "                "$$ LANGUAGE SQL");    }    if (osTables.size() != 0)    {        char** papszTables = CSLTokenizeString2(osTables, ",", 0);        for(int i=0;papszTables && papszTables[i];i++)        {            papoLayers = (OGRCARTOTableLayer**) CPLRealloc(                papoLayers, (nLayers + 1) * sizeof(OGRCARTOTableLayer*));            papoLayers[nLayers ++] = new OGRCARTOTableLayer(this, papszTables[i]);        }        CSLDestroy(papszTables);        return TRUE;    }    OGRLayer* poTableListLayer = ExecuteSQLInternal("SELECT CDB_UserTables()");    if( poTableListLayer )    {        OGRFeature* poFeat;        while( (poFeat = poTableListLayer->GetNextFeature()) != NULL )        {            if( poFeat->GetFieldCount() == 1 )            {                papoLayers = (OGRCARTOTableLayer**) CPLRealloc(                    papoLayers, (nLayers + 1) * sizeof(OGRCARTOTableLayer*));                papoLayers[nLayers ++] = new OGRCARTOTableLayer(                            this, poFeat->GetFieldAsString(0));            }            delete poFeat;        }        ReleaseResultSet(poTableListLayer);    }    else if( osCurrentSchema == "public" )        return FALSE;    /* There's currently a bug with CDB_UserTables() on multi-user accounts */    if( nLayers == 0 && osCurrentSchema != "public" )    {        CPLString osSQL;        osSQL.Printf("SELECT c.relname FROM pg_class c, pg_namespace n "                     "WHERE c.relkind in ('r', 'v') AND c.relname !~ '^pg_' AND c.relnamespace=n.oid AND n.nspname = '%s'",                     OGRCARTOEscapeLiteral(osCurrentSchema).c_str());        poTableListLayer = ExecuteSQLInternal(osSQL);        if( poTableListLayer )        {            OGRFeature* poFeat;            while( (poFeat = poTableListLayer->GetNextFeature()) != NULL )            {                if( poFeat->GetFieldCount() == 1 )                {                    papoLayers = (OGRCARTOTableLayer**) CPLRealloc(                        papoLayers, (nLayers + 1) * sizeof(OGRCARTOTableLayer*));                    papoLayers[nLayers ++] = new OGRCARTOTableLayer(                                this, poFeat->GetFieldAsString(0));                }                delete poFeat;            }            ReleaseResultSet(poTableListLayer);        }        else            return FALSE;    }    return TRUE;}
开发者ID:nextgis-borsch,项目名称:lib_gdal,代码行数:101,


示例17: CSLFetchNameValue

//.........这里部分代码省略.........    else if ( EQUAL(pszGeomType, "geography") )    {        if( CSLFetchNameValue( papszOptions, "GEOMETRY_NAME") != NULL )            pszGFldName = CSLFetchNameValue( papszOptions, "GEOMETRY_NAME");        else            pszGFldName = "the_geog";        if (nSRSId)            osCommand.Printf(                     "%s ( %s %s, /"%s/" geography(%s%s,%d), CONSTRAINT /"%s_pk/" PRIMARY KEY (%s) )",                     osCreateTable.c_str(), osFIDColumnNameEscaped.c_str(), pszSerialType, pszGFldName, pszGeometryType, nDimension == 2 ? "" : "Z", nSRSId, pszTableName, osFIDColumnNameEscaped.c_str() );        else            osCommand.Printf(                     "%s ( %s %s, /"%s/" geography(%s%s), CONSTRAINT /"%s_pk/" PRIMARY KEY (%s) )",                     osCreateTable.c_str(), osFIDColumnNameEscaped.c_str(), pszSerialType, pszGFldName, pszGeometryType, nDimension == 2 ? "" : "Z", pszTableName, osFIDColumnNameEscaped.c_str() );    }    else    {        osCommand.Printf(                 "%s ( %s %s, CONSTRAINT /"%s_pk/" PRIMARY KEY (%s) )",                 osCreateTable.c_str(), osFIDColumnNameEscaped.c_str(), pszSerialType, pszTableName, osFIDColumnNameEscaped.c_str() );    }    if (bCreateTable)        Log(osCommand);/* -------------------------------------------------------------------- *//*      Eventually we should be adding this table to a table of         *//*      "geometric layers", capturing the WKT projection, and           *//*      perhaps some other housekeeping.                                *//* -------------------------------------------------------------------- */    if( bCreateTable && bHavePostGIS && !EQUAL(pszGeomType, "geography"))    {        osCommand.Printf(                "SELECT AddGeometryColumn('%s',%s,'%s',%d,'%s',%d)",                pszSchemaName, pszEscapedTableNameSingleQuote, pszGFldName,                nSRSId, pszGeometryType, nDimension );        Log(osCommand);    }    const char *pszSI = CSLFetchNameValue( papszOptions, "SPATIAL_INDEX" );    int bCreateSpatialIndex = ( pszSI == NULL || CSLTestBoolean(pszSI) );    if( bCreateTable && bHavePostGIS && bCreateSpatialIndex )    {/* -------------------------------------------------------------------- *//*      Create the spatial index.                                       *//*                                                                      *//*      We're doing this before we add geometry and record to the table *//*      so this may not be exactly the best way to do it.               *//* -------------------------------------------------------------------- */        osCommand.Printf("CREATE INDEX /"%s_%s_geom_idx/" "                        "ON /"%s/"./"%s/" "                        "USING GIST (/"%s/")",                pszTableName, pszGFldName, pszSchemaName, pszTableName, pszGFldName);        Log(osCommand);    }/* -------------------------------------------------------------------- *//*      Create the layer object.                                        *//* -------------------------------------------------------------------- */    OGRPGDumpLayer     *poLayer;    int bWriteAsHex = !CSLFetchBoolean(papszOptions,"WRITE_EWKT_GEOM",FALSE);    poLayer = new OGRPGDumpLayer( this, pszSchemaName, pszTableName,                                  osFIDColumnName, bWriteAsHex, bCreateTable );    poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions,"LAUNDER",TRUE) );    poLayer->SetPrecisionFlag( CSLFetchBoolean(papszOptions,"PRECISION",TRUE));    const char* pszOverrideColumnTypes = CSLFetchNameValue( papszOptions, "COLUMN_TYPES" );    poLayer->SetOverrideColumnTypes(pszOverrideColumnTypes);    poLayer->SetUnknownSRSId(nUnknownSRSId);    poLayer->SetForcedSRSId(nForcedSRSId);    poLayer->SetCreateSpatialIndexFlag(bCreateSpatialIndex);    poLayer->SetPostGIS2(bPostGIS2);    if( bHavePostGIS )    {        OGRGeomFieldDefn oTmp( pszGFldName, eType );        OGRPGDumpGeomFieldDefn *poGeomField =            new OGRPGDumpGeomFieldDefn(&oTmp);        poGeomField->nSRSId = nSRSId;        poGeomField->nCoordDimension = nDimension;        poLayer->GetLayerDefn()->AddGeomFieldDefn(poGeomField, FALSE);    }/* -------------------------------------------------------------------- *//*      Add layer to data source layer list.                            *//* -------------------------------------------------------------------- */    papoLayers = (OGRPGDumpLayer **)        CPLRealloc( papoLayers,  sizeof(OGRPGDumpLayer *) * (nLayers+1) );    papoLayers[nLayers++] = poLayer;    CPLFree( pszTableName );    CPLFree( pszSchemaName );    return poLayer;}
开发者ID:anandthakker,项目名称:node-gdal,代码行数:101,


示例18: CPLError

OGRLayer   *OGRCARTODataSource::ICreateLayer( const char *pszNameIn,                                           OGRSpatialReference *poSpatialRef,                                           OGRwkbGeometryType eGType,                                           char ** papszOptions ){    if (!bReadWrite)    {        CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode");        return NULL;    }/* -------------------------------------------------------------------- *//*      Do we already have this layer?  If so, should we blow it        *//*      away?                                                           *//* -------------------------------------------------------------------- */    int iLayer;    for( iLayer = 0; iLayer < nLayers; iLayer++ )    {        if( EQUAL(pszNameIn,papoLayers[iLayer]->GetName()) )        {            if( CSLFetchNameValue( papszOptions, "OVERWRITE" ) != NULL                && !EQUAL(CSLFetchNameValue(papszOptions,"OVERWRITE"),"NO") )            {                DeleteLayer( iLayer );            }            else            {                CPLError( CE_Failure, CPLE_AppDefined,                          "Layer %s already exists, CreateLayer failed./n"                          "Use the layer creation option OVERWRITE=YES to "                          "replace it.",                          pszNameIn );                return NULL;            }        }    }    CPLString osName(pszNameIn);    if( CPLFetchBool(const_cast<const char**>(papszOptions), "LAUNDER", true) )    {        char* pszTmp = OGRPGCommonLaunderName(pszNameIn);        osName = pszTmp;        CPLFree(pszTmp);    }    OGRCARTOTableLayer* poLayer = new OGRCARTOTableLayer(this, osName);    const bool bGeomNullable = CPLFetchBool(const_cast<const char**>(papszOptions), "GEOMETRY_NULLABLE", true);    int nSRID = (poSpatialRef && eGType != wkbNone) ? FetchSRSId( poSpatialRef ) : 0;    bool bCartoify = CPLFetchBool(const_cast<const char**>(papszOptions), "CARTODBFY",                                    CPLFetchBool(const_cast<const char**>(papszOptions), "CARTODBIFY",                                                 true));    if( bCartoify )    {        if( nSRID != 4326 )        {            if( eGType != wkbNone )            {                CPLError(CE_Warning, CPLE_AppDefined,                        "Cannot register table in dashboard with "                        "cdb_cartodbfytable() since its SRS is not EPSG:4326");            }            bCartoify = false;        }    }    poLayer->SetLaunderFlag( CPLFetchBool(const_cast<const char**>(papszOptions), "LAUNDER", true) );    poLayer->SetDeferredCreation(eGType, poSpatialRef, bGeomNullable, bCartoify);    papoLayers = (OGRCARTOTableLayer**) CPLRealloc(                    papoLayers, (nLayers + 1) * sizeof(OGRCARTOTableLayer*));    papoLayers[nLayers ++] = poLayer;    return poLayer;}
开发者ID:nextgis-borsch,项目名称:lib_gdal,代码行数:75,


示例19: CPLStrdup

int OGRBNADataSource::Open( const char * pszFilename, int bUpdateIn){    int ok = FALSE;    pszName = CPLStrdup( pszFilename );    bUpdate = bUpdateIn;        VSILFILE* fp = VSIFOpenL(pszFilename, "rb");    if (fp)    {        BNARecord* record;        int curLine = 0;        const char* layerRadixName[] = { "points", "polygons", "lines", "ellipses"};        OGRwkbGeometryType wkbGeomTypes[] = { wkbPoint, wkbMultiPolygon, wkbLineString, wkbPolygon };        int i;#if defined(BNA_FAST_DS_OPEN)        record = BNA_GetNextRecord(fp, &ok, &curLine, FALSE, BNA_READ_NONE);        BNA_FreeRecord(record);        if (ok)        {            nLayers = 4;            papoLayers = (OGRBNALayer **) CPLMalloc(nLayers * sizeof(OGRBNALayer*));            for(i=0;i<4;i++)                papoLayers[i] = new OGRBNALayer( pszFilename,                                                 layerRadixName[i],                                                 (BNAFeatureType)i, wkbGeomTypes[i], FALSE, this );        }#else        int nFeatures[4] = { 0, 0, 0, 0 };        OffsetAndLine* offsetAndLineFeaturesTable[4] = { NULL, NULL, NULL, NULL };        int nIDs[4] = {0, 0, 0, 0};        int partialIndexTable = TRUE;        while(1)        {            int offset = (int) VSIFTellL(fp);            int line = curLine;            record =  BNA_GetNextRecord(fp, &ok, &curLine, FALSE, BNA_READ_NONE);            if (ok == FALSE)            {                BNA_FreeRecord(record);                if (line != 0)                    ok = TRUE;                break;            }            if (record == NULL)            {                /* end of file */                ok = TRUE;                /* and we have finally build the whole index table */                partialIndexTable = FALSE;                break;            }            if (record->nIDs > nIDs[record->featureType])                nIDs[record->featureType] = record->nIDs;            nFeatures[record->featureType]++;            offsetAndLineFeaturesTable[record->featureType] =                (OffsetAndLine*)CPLRealloc(offsetAndLineFeaturesTable[record->featureType],                                           nFeatures[record->featureType] * sizeof(OffsetAndLine));            offsetAndLineFeaturesTable[record->featureType][nFeatures[record->featureType]-1].offset = offset;            offsetAndLineFeaturesTable[record->featureType][nFeatures[record->featureType]-1].line = line;            BNA_FreeRecord(record);        }        nLayers = (nFeatures[0] != 0) + (nFeatures[1] != 0) + (nFeatures[2] != 0) + (nFeatures[3] != 0);        papoLayers = (OGRBNALayer **) CPLMalloc(nLayers * sizeof(OGRBNALayer*));        int iLayer = 0;        for(i=0;i<4;i++)        {            if (nFeatures[i])            {                papoLayers[iLayer] = new OGRBNALayer( pszFilename,                                                      layerRadixName[i],                                                      (BNAFeatureType)i,                                                      wkbGeomTypes[i],                                                      FALSE,                                                      this,                                                      nIDs[i]);                papoLayers[iLayer]->SetFeatureIndexTable(nFeatures[i],                                                        offsetAndLineFeaturesTable[i],                                                        partialIndexTable);                iLayer++;            }        }#endif        VSIFCloseL(fp);    }    return ok;}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:97,


示例20: iconv_open

char *CPLRecodeIconv( const char *pszSource,                       const char *pszSrcEncoding,                       const char *pszDstEncoding ){    iconv_t sConv;    sConv = iconv_open( pszDstEncoding, pszSrcEncoding );    if ( sConv == (iconv_t)-1 )    {        CPLError( CE_Warning, CPLE_AppDefined,                   "Recode from %s to %s failed with the error: /"%s/".",                   pszSrcEncoding, pszDstEncoding, strerror(errno) );        return CPLStrdup(pszSource);    }/* -------------------------------------------------------------------- *//*      XXX: There is a portability issue: iconv() function could be    *//*      declared differently on different platforms. The second         *//*      argument could be declared as char** (as POSIX defines) or      *//*      as a const char**. Handle it with the ICONV_CONST macro here.   *//* -------------------------------------------------------------------- */    ICONV_CONST char *pszSrcBuf = (ICONV_CONST char *)pszSource;    size_t  nSrcLen = strlen( pszSource );    size_t  nDstCurLen = MAX(CPL_RECODE_DSTBUF_SIZE, nSrcLen + 1);    size_t  nDstLen = nDstCurLen;    char    *pszDestination = (char *)CPLCalloc( nDstCurLen, sizeof(char) );    char    *pszDstBuf = pszDestination;    while ( nSrcLen > 0 )    {        size_t  nConverted =            iconv( sConv, &pszSrcBuf, &nSrcLen, &pszDstBuf, &nDstLen );        if ( nConverted == (size_t)-1 )        {            if ( errno == EILSEQ )            {                // Skip the invalid sequence in the input string.                static int bHasWarned = FALSE;                if (!bHasWarned)                {                    bHasWarned = TRUE;                    CPLError(CE_Warning, CPLE_AppDefined,                            "One or several characters couldn't be converted correctly from %s to %s./n"                            "This warning will not be emitted anymore",                             pszSrcEncoding, pszDstEncoding);                }                nSrcLen--, pszSrcBuf++;                continue;            }            else if ( errno == E2BIG )            {                // We are running out of the output buffer.                // Dynamically increase the buffer size.                size_t nTmp = nDstCurLen;                nDstCurLen *= 2;                pszDestination =                    (char *)CPLRealloc( pszDestination, nDstCurLen );                pszDstBuf = pszDestination + nTmp - nDstLen;                nDstLen += nDstCurLen - nTmp;                continue;            }            else                break;        }    }    pszDestination[nDstCurLen - nDstLen] = '/0';    iconv_close( sConv );    return pszDestination;}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:78,


示例21: CSLFetchNameValue

//.........这里部分代码省略.........                          "Layer %s already exists, CreateLayer failed./n"                          "Use the layer creation option OVERWRITE=YES to "                          "replace it.",                          pszLayerName );                return NULL;            }        }    }    /* Read our SRS_ID from the OGRSpatialReference */    int nSRSId = UNDEFINED_SRID;    if( poSpatialRef != NULL )        nSRSId = GetSrsId( poSpatialRef );            /* Requirement 25: The geometry_type_name value in a gpkg_geometry_columns */    /* row SHALL be one of the uppercase geometry type names specified in */    /* Geometry Types (Normative). */    const char *pszGeometryType = OGRToOGCGeomType(eGType);        /* Create the table! */    char *pszSQL = NULL;    if ( eGType != wkbNone )    {        pszSQL = sqlite3_mprintf(            "CREATE TABLE %s ( "            "%s INTEGER PRIMARY KEY AUTOINCREMENT, "            "%s %s )",             pszLayerName, pszFIDColumnName, pszGeomColumnName, pszGeometryType);    }    else    {        pszSQL = sqlite3_mprintf(            "CREATE TABLE %s ( "            "%s INTEGER PRIMARY KEY AUTOINCREMENT )",             pszLayerName, pszFIDColumnName);    }        err = SQLCommand(m_poDb, pszSQL);    sqlite3_free(pszSQL);    if ( OGRERR_NONE != err )        return NULL;    /* Only spatial tables need to be registered in the metadata (hmmm) */    if ( eGType != wkbNone )    {        /* Requirement 27: The z value in a gpkg_geometry_columns table row */        /* SHALL be one of 0 (none), 1 (mandatory), or 2 (optional) */        int bGeometryTypeHasZ = (wkb25DBit & eGType) != 0;        /* Update gpkg_geometry_columns with the table info */        pszSQL = sqlite3_mprintf(            "INSERT INTO gpkg_geometry_columns "            "(table_name,column_name,geometry_type_name,srs_id,z,m)"            " VALUES "            "('%q','%q','%q',%d,%d,%d)",            pszLayerName,pszGeomColumnName,pszGeometryType,            nSRSId,bGeometryTypeHasZ,0);            err = SQLCommand(m_poDb, pszSQL);        sqlite3_free(pszSQL);        if ( err != OGRERR_NONE )            return NULL;        /* Update gpkg_contents with the table info */        pszSQL = sqlite3_mprintf(            "INSERT INTO gpkg_contents "            "(table_name,data_type,identifier,last_change,srs_id)"            " VALUES "            "('%q','features','%q',strftime('%%Y-%%m-%%dT%%H:%%M:%%fZ',CURRENT_TIMESTAMP),%d)",            pszLayerName, pszLayerName, nSRSId);            err = SQLCommand(m_poDb, pszSQL);        sqlite3_free(pszSQL);        if ( err != OGRERR_NONE )            return NULL;    }    /* This is where spatial index logic will go in the future */    const char *pszSI = CSLFetchNameValue( papszOptions, "SPATIAL_INDEX" );    int bCreateSpatialIndex = ( pszSI == NULL || CSLTestBoolean(pszSI) );    if( eGType != wkbNone && bCreateSpatialIndex )    {        /* This is where spatial index logic will go in the future */    }        /* The database is now all set up, so create a blank layer and read in the */    /* info from the database. */    OGRGeoPackageLayer *poLayer = new OGRGeoPackageLayer(this, pszLayerName);        if( OGRERR_NONE != poLayer->ReadTableDefinition() )    {        delete poLayer;        return NULL;    }    m_papoLayers = (OGRLayer**)CPLRealloc(m_papoLayers,  sizeof(OGRGeoPackageLayer*) * (m_nLayers+1));    m_papoLayers[m_nLayers++] = poLayer;    return poLayer;}
开发者ID:0004c,项目名称:node-gdal,代码行数:101,


示例22: oStatement

OGRSpatialReference *OGROCIDataSource::FetchSRS( int nId ){    if( nId < 0 )        return NULL;/* -------------------------------------------------------------------- *//*      First, we look through our SRID cache, is it there?             *//* -------------------------------------------------------------------- */    int  i;    for( i = 0; i < nKnownSRID; i++ )    {        if( panSRID[i] == nId )            return papoSRS[i];    }/* -------------------------------------------------------------------- *//*      Try looking up in MDSYS.CS_SRS table.                           *//* -------------------------------------------------------------------- */    OGROCIStatement oStatement( GetSession() );    char            szSelect[200], **papszResult;    snprintf( szSelect, sizeof(szSelect),             "SELECT WKTEXT, AUTH_SRID, AUTH_NAME FROM MDSYS.CS_SRS "             "WHERE SRID = %d AND WKTEXT IS NOT NULL", nId );    if( oStatement.Execute( szSelect ) != CE_None )        return NULL;    papszResult = oStatement.SimpleFetchRow();    if( CSLCount(papszResult) < 1 )        return NULL;/* -------------------------------------------------------------------- *//*      Turn into a spatial reference.                                  *//* -------------------------------------------------------------------- */    char *pszWKT = papszResult[0];    OGRSpatialReference *poSRS = NULL;    poSRS = new OGRSpatialReference();    if( poSRS->importFromWkt( &pszWKT ) != OGRERR_NONE )    {        delete poSRS;        poSRS = NULL;    }/* -------------------------------------------------------------------- *//*      If we have a corresponding EPSG code for this SRID, use that    *//*      authority.                                                      *//* -------------------------------------------------------------------- */    int bGotEPSGMapping = FALSE;    for( i = 0; anEPSGOracleMapping[i] != 0; i += 2 )    {        if( anEPSGOracleMapping[i] == nId )        {            poSRS->SetAuthority( poSRS->GetRoot()->GetValue(), "EPSG",                                 anEPSGOracleMapping[i+1] );            bGotEPSGMapping = TRUE;            break;        }    }/* -------------------------------------------------------------------- *//*      Insert authority information, if it is available.               *//* -------------------------------------------------------------------- */    if( papszResult[1] != NULL && atoi(papszResult[1]) != 0        && papszResult[2] != NULL && strlen(papszResult[1]) != 0        && poSRS->GetRoot() != NULL        && !bGotEPSGMapping )    {        poSRS->SetAuthority( poSRS->GetRoot()->GetValue(),                             papszResult[2], atoi(papszResult[1]) );    }/* -------------------------------------------------------------------- *//*      Add to the cache.                                               *//* -------------------------------------------------------------------- */    panSRID = (int *) CPLRealloc(panSRID,sizeof(int) * (nKnownSRID+1) );    papoSRS = (OGRSpatialReference **)        CPLRealloc(papoSRS, sizeof(void*) * (nKnownSRID + 1) );    panSRID[nKnownSRID] = nId;    papoSRS[nKnownSRID] = poSRS;    nKnownSRID++;    return poSRS;}
开发者ID:nextgis-borsch,项目名称:lib_gdal,代码行数:88,


示例23: empty

//.........这里部分代码省略.........                return OGRERR_NONE;            }        }    }    /* Skip first '(' */    pszInput = OGRWktReadToken( pszInput, szToken );/* ==================================================================== *//*      Read each ring in turn.  Note that we try to reuse the same     *//*      point list buffer from ring to ring to cut down on              *//*      allocate/deallocate overhead.                                   *//* ==================================================================== */    OGRRawPoint *paoPoints = NULL;    int         nMaxPoints = 0, nMaxRings = 0;    double      *padfZ = NULL;    nCoordDimension = 2;        do    {        int     nPoints = 0;        const char* pszNext = OGRWktReadToken( pszInput, szToken );        if (EQUAL(szToken,"EMPTY"))        {/* -------------------------------------------------------------------- *//*      Do we need to grow the ring array?                              *//* -------------------------------------------------------------------- */            if( nRingCount == nMaxRings )            {                nMaxRings = nMaxRings * 2 + 1;                papoRings = (OGRLinearRing **)                    CPLRealloc(papoRings, nMaxRings * sizeof(OGRLinearRing*));            }            papoRings[nRingCount] = new OGRLinearRing();            nRingCount++;            pszInput = OGRWktReadToken( pszNext, szToken );            if ( !EQUAL(szToken, ",") )                break;            continue;        }/* -------------------------------------------------------------------- *//*      Read points for one ring from input.                            *//* -------------------------------------------------------------------- */        pszInput = OGRWktReadPoints( pszInput, &paoPoints, &padfZ, &nMaxPoints,                                     &nPoints );        if( pszInput == NULL || nPoints == 0 )        {            CPLFree( paoPoints );            return OGRERR_CORRUPT_DATA;        }        /* -------------------------------------------------------------------- *//*      Do we need to grow the ring array?                              *//* -------------------------------------------------------------------- */        if( nRingCount == nMaxRings )        {            nMaxRings = nMaxRings * 2 + 1;            papoRings = (OGRLinearRing **)                CPLRealloc(papoRings, nMaxRings * sizeof(OGRLinearRing*));        }
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:67,


示例24: tr_strcpy

void NASHandler::startElement( const XMLCh* const /* uri */,                               const XMLCh* const localname,                               const XMLCh* const /* qname */,                               const Attributes& attrs ){    char        szElementName[MAX_TOKEN_SIZE];    GMLReadState *poState = m_poReader->GetState();    tr_strcpy( szElementName, localname );    if ( ( m_bIgnoreFeature && m_nDepth >= m_nDepthFeature ) ||         ( m_osIgnoredElement != "" && m_nDepth >= m_nDepthElement ) )    {        m_nDepth ++;        return;    }    // ignore attributes of external references and "objektkoordinaten"    // (see PostNAS #3 and #15)    if ( EQUAL( szElementName, "zeigtAufExternes" ) ||         EQUAL( szElementName, "objektkoordinaten" ) )    {        m_osIgnoredElement = szElementName;        m_nDepthElement    = m_nDepth;        m_nDepth ++;        return;    }#ifdef DEBUG_VERBOSE    CPLDebug( "NAS",              "%*sstartElement %s m_bIgnoreFeature:%d depth:%d "              "depthFeature:%d featureClass:%s",              m_nDepth, "", szElementName,              m_bIgnoreFeature, m_nDepth, m_nDepthFeature,              poState->m_poFeature ? poState->m_poFeature->                  GetClass()->GetElementName() : "(no feature)"            );#endif/* -------------------------------------------------------------------- *//*      If we are in the midst of collecting a feature attribute        *//*      value, then this must be a complex attribute which we don't     *//*      try to collect for now, so just terminate the field             *//*      collection.                                                     *//* -------------------------------------------------------------------- */    if( m_pszCurField != NULL )    {        CPLFree( m_pszCurField );        m_pszCurField = NULL;    }/* -------------------------------------------------------------------- *//*      If we are collecting geometry, or if we determine this is a     *//*      geometry element then append to the geometry info.              *//* -------------------------------------------------------------------- */    const char *pszLast = NULL;    if( m_pszGeometry != NULL        || IsGeometryElement( szElementName ) )    {        const int nLNLen = tr_strlen( localname );        CPLString osAttributes = GetAttributes( &attrs );        /* should save attributes too! */        if( m_pszGeometry == NULL )            m_nGeometryDepth = poState->m_nPathLength;        if( m_pszGeometry == NULL ||            m_nGeomLen + nLNLen + 4 + (int)osAttributes.size() > m_nGeomAlloc )        {            m_nGeomAlloc = (int) (m_nGeomAlloc * 1.3 + nLNLen + osAttributes.size() + 1000);            m_pszGeometry = (char *)                CPLRealloc( m_pszGeometry, m_nGeomAlloc);        }        strcpy( m_pszGeometry+m_nGeomLen, "<" );        tr_strcpy( m_pszGeometry+m_nGeomLen+1, localname );        if( osAttributes.size() > 0 )        {            strcat( m_pszGeometry+m_nGeomLen, " " );            strcat( m_pszGeometry+m_nGeomLen, osAttributes );        }        strcat( m_pszGeometry+m_nGeomLen, ">" );        m_nGeomLen += static_cast<int>(strlen(m_pszGeometry+m_nGeomLen));    }/* -------------------------------------------------------------------- *//*      Is this the ogc:Filter element in a update operation            *//*      (wfs:Delete, wfsext:Replace or wfs:Update)?                     *//*      specialized sort of feature.                                    *//* -------------------------------------------------------------------- */    else if( EQUAL(szElementName,"Filter")             && (pszLast = m_poReader->GetState()->GetLastComponent()) != NULL             && (EQUAL(pszLast,"Delete") || EQUAL(pszLast,"Replace") ||                 EQUAL(pszLast,"Update")) )//.........这里部分代码省略.........
开发者ID:bbradbury,项目名称:lib_gdal,代码行数:101,


示例25: while

OGRGeometry *OGRIngresLayer::TranslateGeometry( const char *pszGeom ){    OGRGeometry *poGeom = NULL;/* -------------------------------------------------------------------- *//*      Parse the tuple list into an array of x/y vertices.  The        *//*      input may look like "(2,3)" or "((2,3),(4,5),...)".  Extra      *//*      spaces may occur between tokens.                                *//* -------------------------------------------------------------------- */    double *padfXY = NULL;    int    nVertMax = 0, nVertCount = 0;    int    nDepth = 0;    const char *pszNext = pszGeom;    while( *pszNext != '/0' )    {        while( *pszNext == ' ' )            pszNext++;        if( *pszNext == '(' )        {            pszNext++;            nDepth++;            continue;        }        if( *pszNext == ')' )        {            pszNext++;            CPLAssert( nDepth == 1 );            nDepth--;            break;        }        if( *pszNext == ',' )        {            pszNext++;            CPLAssert( nDepth == 1 );            continue;        }        if( nVertCount == nVertMax )        {            nVertMax = nVertMax * 2 + 1;            padfXY = (double *)                 CPLRealloc(padfXY, sizeof(double) * nVertMax * 2 );        }        if( !ParseXY( &pszNext, padfXY + nVertCount*2 ) )        {            CPLDebug( "INGRES", "Error parsing geometry: %s",                       pszGeom );            CPLFree( padfXY );            return NULL;        }                CPLAssert( *pszNext == ')' );        nVertCount++;        pszNext++;        nDepth--;        while( *pszNext == ' ' )            pszNext++;    }    CPLAssert( nDepth == 0 );/* -------------------------------------------------------------------- *//*      Handle Box/IBox.                                                *//* -------------------------------------------------------------------- */    if( EQUAL(osIngresGeomType,"BOX")        || EQUAL(osIngresGeomType,"IBOX") )    {        CPLAssert( nVertCount == 2 );        OGRLinearRing *poRing = new OGRLinearRing();        poRing->addPoint( padfXY[0], padfXY[1] );        poRing->addPoint( padfXY[2], padfXY[1] );        poRing->addPoint( padfXY[2], padfXY[3] );        poRing->addPoint( padfXY[0], padfXY[3] );        poRing->addPoint( padfXY[0], padfXY[1] );        OGRPolygon *poPolygon = new OGRPolygon();        poPolygon->addRingDirectly( poRing );        poGeom = poPolygon;    }/* -------------------------------------------------------------------- *//*      Handle Point/IPoint                                             *//* -------------------------------------------------------------------- */    else if( EQUAL(osIngresGeomType,"POINT")             || EQUAL(osIngresGeomType,"IPOINT") )    {        CPLAssert( nVertCount == 1 );        poGeom = new OGRPoint( padfXY[0], padfXY[1] );    }//.........这里部分代码省略.........
开发者ID:rashadkm,项目名称:lib_gdal,代码行数:101,


示例26: CPL_TO_BOOL

int OGRAmigoCloudDataSource::Open( const char * pszFilename,                                   char** papszOpenOptionsIn,                                   int bUpdateIn ){    bReadWrite = CPL_TO_BOOL(bUpdateIn);    pszName = CPLStrdup( pszFilename );    pszProjectId = CPLStrdup(pszFilename + strlen("AMIGOCLOUD:"));    char* pchSpace = strchr(pszProjectId, ' ');    if( pchSpace )        *pchSpace = '/0';    if( pszProjectId[0] == 0 )    {        CPLError(CE_Failure, CPLE_AppDefined, "Missing project id");        return FALSE;    }    osAPIKey = CSLFetchNameValueDef(papszOpenOptionsIn, "AMIGOCLOUD_API_KEY",                                    CPLGetConfigOption("AMIGOCLOUD_API_KEY", ""));    if (osAPIKey.empty())    {        osAPIKey = OGRAMIGOCLOUDGetOptionValue(pszFilename, "AMIGOCLOUD_API_KEY");    }    if (osAPIKey.empty())    {        CPLError(CE_Failure, CPLE_AppDefined, "AMIGOCLOUD_API_KEY is not defined./n");        return FALSE;    }    OGRLayer* poSchemaLayer = ExecuteSQLInternal("SELECT current_schema()");    if( poSchemaLayer )    {        OGRFeature* poFeat = poSchemaLayer->GetNextFeature();        if( poFeat )        {            if( poFeat->GetFieldCount() == 1 )            {                osCurrentSchema = poFeat->GetFieldAsString(0);            }            delete poFeat;        }        ReleaseResultSet(poSchemaLayer);    }    if( osCurrentSchema.empty() )        return FALSE;    CPLString osDatasets = OGRAMIGOCLOUDGetOptionValue(pszFilename, "datasets");    if (!osDatasets.empty())    {        char** papszTables = CSLTokenizeString2(osDatasets, ",", 0);        for(int i=0;papszTables && papszTables[i];i++)        {            papoLayers = (OGRAmigoCloudTableLayer**) CPLRealloc(                papoLayers, (nLayers + 1) * sizeof(OGRAmigoCloudTableLayer*));            papoLayers[nLayers ++] = new OGRAmigoCloudTableLayer(this, papszTables[i]);        }        CSLDestroy(papszTables);        // If OVERWRITE: YES, truncate the layer.        if( nLayers==1 &&            CPLFetchBool(papszOpenOptionsIn, "OVERWRITE", false) )        {           TruncateDataset(papoLayers[0]->GetTableName());        }        return TRUE;    } else {        // If 'datasets' word is in the filename, but no dataset id specified,        // print the list of available datasets        if(std::string(pszFilename).find("datasets") != std::string::npos)            ListDatasets();    }    return TRUE;}
开发者ID:liyq0307,项目名称:gdal,代码行数:79,



注:本文中的CPLRealloc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ CPLResetExtension函数代码示例
C++ CPLReadLine2L函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。