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

📄 ogrpglayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            CPLFree( padfList );            CSLDestroy( papszTokens );        }        else        {            poFeature->SetField( iOGRField,                                  PQgetvalue( hCursorResult,                                              iRecord, iField ) );        }    }    return poFeature;}/************************************************************************//*                         GetNextRawFeature()                          *//************************************************************************/OGRFeature *OGRPGLayer::GetNextRawFeature(){    PGconn      *hPGConn = poDS->GetPGConn();    char        szCommand[4096];/* -------------------------------------------------------------------- *//*      Do we need to establish an initial query?                       *//* -------------------------------------------------------------------- */    if( iNextShapeId == 0 && hCursorResult == NULL )    {        CPLAssert( pszQueryStatement != NULL );        poDS->FlushSoftTransaction();        poDS->SoftStartTransaction();        sprintf( szCommand, "DECLARE %s CURSOR for %s",                 pszCursorName, pszQueryStatement );        CPLDebug( "OGR_PG", "PQexec(%s)", szCommand );        hCursorResult = PQexec(hPGConn, szCommand );        PQclear( hCursorResult );        sprintf( szCommand, "FETCH %d in %s", CURSOR_PAGE, pszCursorName );        hCursorResult = PQexec(hPGConn, szCommand );        bCursorActive = TRUE;        nResultOffset = 0;    }/* -------------------------------------------------------------------- *//*      Are we in some sort of error condition?                         *//* -------------------------------------------------------------------- */    if( hCursorResult == NULL         || PQresultStatus(hCursorResult) != PGRES_TUPLES_OK )    {        iNextShapeId = MAX(1,iNextShapeId);        return NULL;    }/* -------------------------------------------------------------------- *//*      Do we need to fetch more records?                               *//* -------------------------------------------------------------------- */    if( nResultOffset >= PQntuples(hCursorResult)         && bCursorActive )    {        PQclear( hCursorResult );        sprintf( szCommand, "FETCH %d in %s", CURSOR_PAGE, pszCursorName );        hCursorResult = PQexec(hPGConn, szCommand );        nResultOffset = 0;    }/* -------------------------------------------------------------------- *//*      Are we out of results?  If so complete the transaction, and     *//*      cleanup, but don't reset the next shapeid.                      *//* -------------------------------------------------------------------- */    if( nResultOffset >= PQntuples(hCursorResult) )    {        PQclear( hCursorResult );        if( bCursorActive )        {            sprintf( szCommand, "CLOSE %s", pszCursorName );                        hCursorResult = PQexec(hPGConn, szCommand);            PQclear( hCursorResult );        }        poDS->FlushSoftTransaction();        hCursorResult = NULL;        bCursorActive = FALSE;        iNextShapeId = MAX(1,iNextShapeId);        return NULL;    }    /* -------------------------------------------------------------------- *//*      Create a feature from the current result.                       *//* -------------------------------------------------------------------- */    OGRFeature *poFeature = RecordToFeature( nResultOffset );    nResultOffset++;    iNextShapeId++;    return poFeature;}/************************************************************************//*                             GetFeature()                             *//************************************************************************/OGRFeature *OGRPGLayer::GetFeature( long nFeatureId ){    /* This should be implemented! */    return NULL;}/************************************************************************//*                          BYTEAToGeometry()                           *//************************************************************************/OGRGeometry *OGRPGLayer::BYTEAToGeometry( const char *pszBytea ){    GByte       *pabyWKB;    int iSrc=0, iDst=0;    OGRGeometry *poGeometry;    if( pszBytea == NULL )        return NULL;    pabyWKB = (GByte *) CPLMalloc(strlen(pszBytea));    while( pszBytea[iSrc] != '\0' )    {        if( pszBytea[iSrc] == '\\' )        {            if( pszBytea[iSrc+1] >= '0' && pszBytea[iSrc+1] <= '9' )            {                pabyWKB[iDst++] =                     (pszBytea[iSrc+1] - 48) * 64                    + (pszBytea[iSrc+2] - 48) * 8                    + (pszBytea[iSrc+3] - 48) * 1;                iSrc += 4;            }            else            {                pabyWKB[iDst++] = pszBytea[iSrc+1];                iSrc += 2;            }        }        else        {            pabyWKB[iDst++] = pszBytea[iSrc++];        }    }    poGeometry = NULL;    OGRGeometryFactory::createFromWkb( pabyWKB, NULL, &poGeometry, iDst );    CPLFree( pabyWKB );    return poGeometry;}/************************************************************************//*                          GeometryToBYTEA()                           *//************************************************************************/char *OGRPGLayer::GeometryToBYTEA( OGRGeometry * poGeometry ){    int         nWkbSize = poGeometry->WkbSize();    GByte       *pabyWKB;    char        *pszTextBuf, *pszRetBuf;    pabyWKB = (GByte *) CPLMalloc(nWkbSize);    if( poGeometry->exportToWkb( wkbNDR, pabyWKB ) != OGRERR_NONE )        return CPLStrdup("");    pszTextBuf = (char *) CPLMalloc(nWkbSize*5+1);    int  iSrc, iDst=0;    for( iSrc = 0; iSrc < nWkbSize; iSrc++ )    {        if( pabyWKB[iSrc] < 40 || pabyWKB[iSrc] > 126            || pabyWKB[iSrc] == '\\' )        {            sprintf( pszTextBuf+iDst, "\\\\%03o", pabyWKB[iSrc] );            iDst += 5;        }        else            pszTextBuf[iDst++] = pabyWKB[iSrc];    }    pszTextBuf[iDst] = '\0';    pszRetBuf = CPLStrdup( pszTextBuf );    CPLFree( pszTextBuf );    return pszRetBuf;}/************************************************************************//*                          OIDToGeometry()                             *//************************************************************************/OGRGeometry *OGRPGLayer::OIDToGeometry( Oid oid ){    PGconn      *hPGConn = poDS->GetPGConn();    GByte       *pabyWKB;    int         fd, nBytes;    OGRGeometry *poGeometry;#define MAX_WKB 500000    if( oid == 0 )        return NULL;    fd = lo_open( hPGConn, oid, INV_READ );    if( fd < 0 )        return NULL;    pabyWKB = (GByte *) CPLMalloc(MAX_WKB);    nBytes = lo_read( hPGConn, fd, (char *) pabyWKB, MAX_WKB );    lo_close( hPGConn, fd );    poGeometry = NULL;    OGRGeometryFactory::createFromWkb( pabyWKB, NULL, &poGeometry, nBytes );    CPLFree( pabyWKB );    return poGeometry;}/************************************************************************//*                           GeometryToOID()                            *//************************************************************************/Oid OGRPGLayer::GeometryToOID( OGRGeometry * poGeometry ){    PGconn      *hPGConn = poDS->GetPGConn();    int         nWkbSize = poGeometry->WkbSize();    GByte       *pabyWKB;    Oid         oid;    int         fd, nBytesWritten;    pabyWKB = (GByte *) CPLMalloc(nWkbSize);    if( poGeometry->exportToWkb( wkbNDR, pabyWKB ) != OGRERR_NONE )        return 0;    oid = lo_creat( hPGConn, INV_READ|INV_WRITE );        fd = lo_open( hPGConn, oid, INV_WRITE );    nBytesWritten = lo_write( hPGConn, fd, (char *) pabyWKB, nWkbSize );    lo_close( hPGConn, fd );    if( nBytesWritten != nWkbSize )    {        CPLDebug( "OGR_PG",                   "Only wrote %d bytes of %d intended for (fd=%d,oid=%d).\n",                  nBytesWritten, nWkbSize, fd, oid );    }    CPLFree( pabyWKB );        return oid;}/************************************************************************//*                           TestCapability()                           *//************************************************************************/int OGRPGLayer::TestCapability( const char * pszCap ){    if( EQUAL(pszCap,OLCRandomRead) )        return FALSE;    else if( EQUAL(pszCap,OLCFastFeatureCount) )        return m_poFilterGeom == NULL || bHasPostGISGeometry;    else if( EQUAL(pszCap,OLCFastSpatialFilter) )        return TRUE;    else if( EQUAL(pszCap,OLCTransactions) )        return TRUE;    else         return FALSE;}/************************************************************************//*                          StartTransaction()                          *//************************************************************************/OGRErr OGRPGLayer::StartTransaction(){    return poDS->SoftStartTransaction();}/************************************************************************//*                         CommitTransaction()                          *//************************************************************************/OGRErr OGRPGLayer::CommitTransaction(){    return poDS->SoftCommit();}/************************************************************************//*                        RollbackTransaction()                         *//************************************************************************/OGRErr OGRPGLayer::RollbackTransaction(){    return poDS->SoftRollback();}/************************************************************************//*                           GetSpatialRef()                            *//************************************************************************/OGRSpatialReference *OGRPGLayer::GetSpatialRef(){    if( poSRS == NULL && nSRSId > -1 )    {        poSRS = poDS->FetchSRS( nSRSId );        if( poSRS != NULL )            poSRS->Reference();        else            nSRSId = -1;    }    return poSRS;}

⌨️ 快捷键说明

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