diff --git a/src/providers/grass/qgis.r.in.cpp b/src/providers/grass/qgis.r.in.cpp index 158fb65360f1..52c97dd93c73 100644 --- a/src/providers/grass/qgis.r.in.cpp +++ b/src/providers/grass/qgis.r.in.cpp @@ -51,6 +51,9 @@ extern "C" #define G_short_history Rast_short_history #define G_command_history Rast_command_history #define G_write_history Rast_write_history +#define G_set_c_null_value Rast_set_c_null_value +#define G_set_f_null_value Rast_set_f_null_value +#define G_set_d_null_value Rast_set_d_null_value #define G_set_raster_value_c Rast_set_c_value #define G_set_raster_value_f Rast_set_f_value #define G_set_raster_value_d Rast_set_d_value @@ -162,6 +165,8 @@ int main( int argc, char **argv ) { break; } + double noDataValue; + stdinStream >> noDataValue; stdinStream >> byteArray; checkStream( stdinStream ); @@ -185,11 +190,38 @@ int main( int argc, char **argv ) for ( int col = 0; col < cols; col++ ) { if ( grass_type == CELL_TYPE ) - G_set_raster_value_c( ptr, ( CELL )cell[col], grass_type ); + { + if (( CELL )cell[col] == ( CELL )noDataValue ) + { + G_set_c_null_value(( CELL* )ptr, 1 ); + } + else + { + G_set_raster_value_c( ptr, ( CELL )( cell[col] ), grass_type ); + } + } else if ( grass_type == FCELL_TYPE ) - G_set_raster_value_f( ptr, ( FCELL )fcell[col], grass_type ); + { + if (( FCELL )fcell[col] == ( FCELL )noDataValue ) + { + G_set_f_null_value(( FCELL* )ptr, 1 ); + } + else + { + G_set_raster_value_f( ptr, ( FCELL )( fcell[col] ), grass_type ); + } + } else if ( grass_type == DCELL_TYPE ) - G_set_raster_value_d( ptr, ( DCELL )dcell[col], grass_type ); + { + if (( DCELL )dcell[col] == ( DCELL )noDataValue ) + { + G_set_d_null_value(( DCELL* )ptr, 1 ); + } + else + { + G_set_raster_value_d( ptr, ( DCELL )dcell[col], grass_type ); + } + } ptr = G_incr_void_ptr( ptr, G_raster_size( grass_type ) ); } diff --git a/src/providers/grass/qgsgrassimport.cpp b/src/providers/grass/qgsgrassimport.cpp index f036482f197d..ef0b04a55dd7 100644 --- a/src/providers/grass/qgsgrassimport.cpp +++ b/src/providers/grass/qgsgrassimport.cpp @@ -273,6 +273,37 @@ bool QgsGrassRasterImport::import() delete block; return false; } + // prepare null values + double noDataValue; + if ( block->hasNoDataValue() ) + { + noDataValue = block->noDataValue(); + } + else + { + switch ( qgis_out_type ) + { + case QGis::Int32: + noDataValue = -2147483648.0; + break; + case QGis::Float32: + noDataValue = std::numeric_limits::max() * -1.0; + break; + case QGis::Float64: + noDataValue = std::numeric_limits::max() * -1.0; + break; + default: // should not happen + noDataValue = std::numeric_limits::max() * -1.0; + } + for ( qgssize i = 0; i < ( qgssize )block->width()*block->height(); i++ ) + { + if ( block->isNoData( i ) ) + { + block->setValue( i, noDataValue ); + } + } + } + char * data = block->bits( row, 0 ); int size = iterCols * block->dataTypeSize(); QByteArray byteArray = QByteArray::fromRawData( data, size ); // does not copy data and does not take ownership @@ -282,6 +313,8 @@ bool QgsGrassRasterImport::import() break; } outStream << false; // not canceled + outStream << noDataValue; + outStream << byteArray; // Without waitForBytesWritten() it does not finish ok on Windows (process timeout) diff --git a/src/providers/grass/qgsgrassprovidermodule.cpp b/src/providers/grass/qgsgrassprovidermodule.cpp index d3d872bf5d31..17cc119bd3aa 100644 --- a/src/providers/grass/qgsgrassprovidermodule.cpp +++ b/src/providers/grass/qgsgrassprovidermodule.cpp @@ -116,7 +116,8 @@ void QgsGrassMapsetItem::setState( State state ) { QgsDebugMsg( "Entered" ); QgsDirectoryItem::setState( state ); - + // TODO: verify and reenable, it seems to be causing strange icon switching during import, sometimes +#if 0 if ( state == Populated ) { if ( !mMapsetFileSystemWatcher ) @@ -135,6 +136,7 @@ void QgsGrassMapsetItem::setState( State state ) mMapsetFileSystemWatcher = 0; } } +#endif } bool QgsGrassMapsetItem::objectInImports( QgsGrassObject grassObject )