Changeset 19615


Ignore:
Timestamp:
May 4, 2010 9:04:52 AM (6 years ago)
Author:
jorgearevalo
Message:

IReadBlock method slightly simplified. I assume PostgreSQL planner knows when is
necessary to activate sequential scanning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gdal/frmts/wktraster/wktrasterrasterband.cpp

    r19551 r19615  
    594594    double dfProjUpperRightY = 0.0;
    595595    char * pszHexWkb = NULL;
    596     GByte byMachineEndianess = NDR; // by default
    597596    int nTuples = 0;
    598597    GByte * pbyRasterData = NULL;
     
    606605    int nBlockYBound = 0;
    607606
    608 
    609     // Check parameters
     607    /* Check input parameters */
    610608    if (pImage == NULL || nBlockXOff < 0 || nBlockYOff < 0) {
    611609        CPLError(CE_Failure, CPLE_NotSupported,
     
    613611        return CE_Failure;
    614612    }
    615 
    616    
    617     // Check machine endianess
    618 #ifdef CPL_LSB
    619     byMachineEndianess = NDR;
    620 #else
    621     byMachineEndianess = XDR;
    622 #endif
    623613
    624614    /*************************************************************************
     
    700690     * or tiles/blocks (in case of non-regular blocking) that contain this block
    701691     **************************************************************************/
    702 
    703     if (poWKTRasterDS->pszWhereClause != NULL) {
    704 
    705         /**
    706          * Table has GIST index-
    707          * We could disable sequential scanning, but for versions of PostGIS
    708          * up to 0.8, this is no necessary. PostGIS >=0.8 is correctly
    709          * integrated with query planner, thus PostgreSQL will use indexes
    710          * whenever appropriate.
    711          * NOTE: We should add version checking here, and disable sequential
    712          * scanning when needed. See OGRDataSource::Open method.
    713          */
    714         if (poWKTRasterDS->bTableHasGISTIndex) {
    715 
    716             /**
    717              * This queries for the tiles that contains the given block. When
    718              * regular_blocking rasters, the blocks will have the same size of
    719              * a tile, so, we can use "contain" function and "~" operator.
    720              * But when non-regular_blocking, the only way this will work is
    721              * setting the block size to the smallest tile size. The problem is
    722              * how do we know all the tiles size?
    723              */
    724             osCommand.Printf(
    725                     "SELECT rid, %s FROM %s.%s WHERE %s ~ ST_SetSRID(ST_MakeBox2D\
    726                     (ST_Point(%f, %f),ST_Point(%f, %f)), %d) AND %s",
    727                     poWKTRasterDS->pszRasterColumnName,
    728                     poWKTRasterDS->pszSchemaName,
    729                     poWKTRasterDS->pszTableName,
    730                     poWKTRasterDS->pszRasterColumnName, dfProjLowerLeftX,
    731                     dfProjLowerLeftY, dfProjUpperRightX, dfProjUpperRightY,
    732                     poWKTRasterDS->nSrid, poWKTRasterDS->pszWhereClause);
    733 
    734         }            /**
    735              * Table hasn't a GIST index. Normal searching
    736              */
    737         else {
    738             osCommand.Printf(
    739                     "SELECT rid, %s FROM %s.%s WHERE _ST_Contains(%s, ST_SetSRID(\
    740                     ST_MakeBox2D(ST_Point(%f, %f), ST_Point(%f, %f)), %d)) AND\
    741                     %s",
    742                     poWKTRasterDS->pszRasterColumnName,
    743                     poWKTRasterDS->pszSchemaName,
    744                     poWKTRasterDS->pszTableName,
    745                     poWKTRasterDS->pszRasterColumnName, dfProjLowerLeftX,
    746                     dfProjLowerLeftY, dfProjUpperRightX, dfProjUpperRightY,
    747                     poWKTRasterDS->nSrid, poWKTRasterDS->pszWhereClause);
    748         }
    749 
    750 
    751     }        // No where clause
    752     else {
    753         /**
    754          * Table has a GIST index.
    755          */
    756         if (poWKTRasterDS->bTableHasGISTIndex) {
    757 
    758             osCommand.Printf(
    759                     "SELECT rid, %s FROM %s.%s WHERE %s ~ ST_SetSRID(ST_MakeBox2D(\
    760                     ST_Point(%f, %f),ST_Point(%f, %f)), %d)",
    761                     poWKTRasterDS->pszRasterColumnName,
    762                     poWKTRasterDS->pszSchemaName,
    763                     poWKTRasterDS->pszTableName,
    764                     poWKTRasterDS->pszRasterColumnName, dfProjLowerLeftX,
    765                     dfProjLowerLeftY,dfProjUpperRightX, dfProjUpperRightY,
    766                     poWKTRasterDS->nSrid);
    767 
    768         }
    769             /**
    770              * Table hasn't a GIST index. Normal searching
    771              */
    772         else {
    773             osCommand.Printf(
    774                     "SELECT rid, %s FROM %s.%s WHERE _ST_Contains(%s, ST_SetSRID(\
    775                     ST_MakeBox2D(ST_Point(%f, %f), ST_Point(%f, %f)), %d))",
    776                     poWKTRasterDS->pszRasterColumnName,
    777                     poWKTRasterDS->pszSchemaName,
    778                     poWKTRasterDS->pszTableName,
    779                     poWKTRasterDS->pszRasterColumnName, dfProjLowerLeftX,
    780                     dfProjLowerLeftY, dfProjUpperRightX, dfProjUpperRightY,
    781                     poWKTRasterDS->nSrid);
    782         }
     692    if (poWKTRasterDS->pszWhereClause != NULL)
     693    {
     694       osCommand.Printf(
     695               "SELECT %s FROM %s.%s WHERE %s ~ ST_SetSRID(ST_MakeBox2D\
     696                (ST_Point(%f, %f), ST_Point(%f, %f)), %d) AND %s",
     697               poWKTRasterDS->pszRasterColumnName, poWKTRasterDS->pszSchemaName,
     698               poWKTRasterDS->pszTableName, poWKTRasterDS->pszRasterColumnName,
     699               dfProjLowerLeftX, dfProjLowerLeftY, dfProjUpperRightX,
     700               dfProjUpperRightY, poWKTRasterDS->nSrid,
     701               poWKTRasterDS->pszWhereClause);
     702    }
     703
     704    else
     705    {
     706       osCommand.Printf(
     707               "SELECT %s FROM %s.%s WHERE %s ~ ST_SetSRID(ST_MakeBox2D\
     708                (ST_Point(%f, %f), ST_Point(%f, %f)), %d)",
     709               poWKTRasterDS->pszRasterColumnName, poWKTRasterDS->pszSchemaName,
     710               poWKTRasterDS->pszTableName, poWKTRasterDS->pszRasterColumnName,
     711               dfProjLowerLeftX, dfProjLowerLeftY, dfProjUpperRightX,
     712               dfProjUpperRightY, poWKTRasterDS->nSrid);
     713 
    783714    }
    784715
     
    803734     * No blocks found. Fill the buffer with nodata value
    804735     *****************************************************************/
    805     if (nTuples == 0) {
     736    if (nTuples == 0)
     737    {
    806738        NullBlock(pImage);
    807739        return CE_None;
     
    812744     * One block found. Regular blocking arrangements, no overlaps
    813745     ******************************************************************/
    814     else if (nTuples == 1) {
    815         int nRid = atoi(PQgetvalue(hPGresult, 0, 0));     
    816 
     746    else if (nTuples == 1)
     747    {
    817748        // Get HEXWKB representation of the block
    818         pszHexWkb = CPLStrdup(PQgetvalue(hPGresult, 0, 1));
     749        pszHexWkb = CPLStrdup(PQgetvalue(hPGresult, 0, 0));
    819750
    820751        PQclear(hPGresult);
    821752
    822753        // Raster hex must have an even number of characters
    823         if (pszHexWkb == NULL || strlen(pszHexWkb) % 2) {
     754        if (pszHexWkb == NULL || strlen(pszHexWkb) % 2)
     755        {
    824756            CPLError(CE_Failure, CPLE_AppDefined,
    825757                    "The HEXWKB data fetch from database must have an even number \
     
    831763        // Create a wrapper object
    832764        poWKTRasterWrapper = new WKTRasterWrapper();
    833         if (poWKTRasterWrapper->Initialize(pszHexWkb) == FALSE) {
     765        if (poWKTRasterWrapper->Initialize(pszHexWkb) == FALSE)
     766        {
    834767            CPLFree(pszHexWkb);
    835768            delete poWKTRasterWrapper;
     
    843776        // Create raster band wrapper
    844777        poWKTRasterBandWrapper = poWKTRasterWrapper->GetBand((GUInt16)nBand);
    845         if (poWKTRasterBandWrapper == NULL) {
     778        if (poWKTRasterBandWrapper == NULL)
     779        {
    846780            CPLError(CE_Failure, CPLE_ObjectNull,"Couldn't fetch band data");
    847781            delete poWKTRasterWrapper;
     
    859793         * Check if the raster is offline
    860794         **********************************************************/
    861         if (poWKTRasterBandWrapper->bIsOffline == TRUE) {
     795        if (poWKTRasterBandWrapper->bIsOffline == TRUE)
     796        {
    862797            // The raster data in this case is a path to the raster file
    863798            int nBandToRead = poWKTRasterBandWrapper->nOutDbBandNumber;
     
    865800
    866801            // Open dataset, if needed
    867             if  (poWKTRasterDS->poOutdbRasterDS == NULL) {
     802            if  (poWKTRasterDS->poOutdbRasterDS == NULL)
     803            {
    868804                poWKTRasterDS->poOutdbRasterDS = (GDALDataset *)
    869805                        GDALOpen((char *)pbyRasterData, GA_ReadOnly);
     
    878814                 */
    879815
    880                 /*
     816               
    881817                poWKTRasterDS->poOutdbRasterDS->GetRasterBand(nBandToRead)->ReadBlock(
    882                     nBlockXOff, nBlockYOff, pImage);
    883                  */
    884                 ;
    885             else {
     818                    nBlockXOff, nBlockYOff, pImage);                             
     819            else
     820            {
    886821                CPLError(CE_Failure, CPLE_ObjectNull,
    887822                    "Couldn't read band data from out-db raster");
     
    893828
    894829
    895         else {
     830        /****************************
     831         * Indb raster
     832         ****************************/
     833        else
     834        {
    896835            /**
    897836             * Copy the data buffer into pImage.
     
    915854         * More than one block found. Non regular blocking arrangements
    916855         *********************************************************************/
    917     else {
     856    else
     857    {
    918858        // Only regular_block supported, just now
    919859        PQclear(hPGresult);
     
    933873 * Returns: nothing
    934874 */
    935 void WKTRasterRasterBand::NullBlock(void *pData) {
     875void WKTRasterRasterBand::NullBlock(void *pData)
     876{
    936877    VALIDATE_POINTER0(pData, "NullBlock");
    937878
     
    945886    int bNoDataSet;
    946887    double dfNoData = GetNoDataValue(&bNoDataSet);
    947     if (!bNoDataSet) {
     888    if (!bNoDataSet)
     889    {
    948890        memset(pData, 0, nWords * nChunkSize);
    949     } else {
     891    }
     892    else
     893    {
    950894        int i = 0;
    951895        for (i = 0; i < nWords; i += nChunkSize)
Note: See TracChangeset for help on using the changeset viewer.