Skip to content
Permalink
Browse files

Fix bug causing raster blocks to be cleared when reprojecting

If a QgsRasterBlock had no nodata value set, then reprojecting
the raster using QgsRasterProjector would result in the entire
block being set to nodata.

Cherry-picked from 920f2eb
  • Loading branch information
nyalldawson committed Jun 9, 2015
1 parent 4fbda18 commit 870213842fb1bc8e40c3ffeec705ef74d9e6a133
@@ -180,6 +180,23 @@ class QgsRasterBlock
* @return true on success */
bool setIsNoDataExcept( const QRect & theExceptRect );

/** \brief Remove no data flag on pixel. If the raster block does not have an explicit
* no data value set then an internal map of no data pixels is maintained for the block.
* In this case it is possible to reset a pixel to flag it as having valid data using this
* method. This method has no effect for raster blocks with an explicit no data value set.
* @param row row index
* @param column column index
* @note added in QGIS 2.10 */
void setIsData( int row, int column );

/** \brief Remove no data flag on pixel. If the raster block does not have an explicit
* no data value set then an internal map of no data pixels is maintained for the block.
* In this case it is possible to reset a pixel to flag it as having valid data using this
* method. This method has no effect for raster blocks with an explicit no data value set.
* @param index data matrix index (long type in Python)
* @note added in QGIS 2.10 */
void setIsData( qgssize index );

/** \brief Get pointer to data
* @param row row index
* @param column column index
@@ -633,6 +633,33 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
}
}

void QgsRasterBlock::setIsData( int row, int column )
{
setIsData(( qgssize )row*mWidth + column );
}

void QgsRasterBlock::setIsData( qgssize index )
{
if ( mHasNoDataValue )
{
//no data value set, so mNoDataBitmap is not being used
return;
}

if ( mNoDataBitmap == 0 )
{
return;
}

// TODO: optimize
int row = ( int ) index / mWidth;
int column = index % mWidth;
qgssize byte = ( qgssize )row * mNoDataBitmapWidth + column / 8;
int bit = column % 8;
int nodata = 0x80 >> bit;
mNoDataBitmap[byte] = mNoDataBitmap[byte] & ~nodata;
}

char * QgsRasterBlock::bits( qgssize index )
{
// Not testing type to avoid too much overhead because this method is called per pixel
@@ -242,6 +242,23 @@ class CORE_EXPORT QgsRasterBlock
* @return true on success */
bool setIsNoDataExcept( const QRect & theExceptRect );

/** \brief Remove no data flag on pixel. If the raster block does not have an explicit
* no data value set then an internal map of no data pixels is maintained for the block.
* In this case it is possible to reset a pixel to flag it as having valid data using this
* method. This method has no effect for raster blocks with an explicit no data value set.
* @param row row index
* @param column column index
* @note added in QGIS 2.10 */
void setIsData( int row, int column );

/** \brief Remove no data flag on pixel. If the raster block does not have an explicit
* no data value set then an internal map of no data pixels is maintained for the block.
* In this case it is possible to reset a pixel to flag it as having valid data using this
* method. This method has no effect for raster blocks with an explicit no data value set.
* @param index data matrix index (long type in Python)
* @note added in QGIS 2.10 */
void setIsData( qgssize index );

/** \brief Get pointer to data
* @param row row index
* @param column column index
@@ -934,6 +934,7 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
continue;
}
memcpy( destBits, srcBits, pixelSize );
outputBlock->setIsData( i, j );
}
}

0 comments on commit 8702138

Please sign in to comment.
You can’t perform that action at this time.