Skip to content

Commit

Permalink
[GRASS] raster import null values
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jun 25, 2015
1 parent 91058aa commit 492c6d9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
38 changes: 35 additions & 3 deletions src/providers/grass/qgis.r.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -162,6 +165,8 @@ int main( int argc, char **argv )
{
break;
}
double noDataValue;
stdinStream >> noDataValue;
stdinStream >> byteArray;
checkStream( stdinStream );

Expand All @@ -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 ) );
}
Expand Down
33 changes: 33 additions & 0 deletions src/providers/grass/qgsgrassimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>::max() * -1.0;
break;
case QGis::Float64:
noDataValue = std::numeric_limits<double>::max() * -1.0;
break;
default: // should not happen
noDataValue = std::numeric_limits<double>::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
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/providers/grass/qgsgrassprovidermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -135,6 +136,7 @@ void QgsGrassMapsetItem::setState( State state )
mMapsetFileSystemWatcher = 0;
}
}
#endif
}

bool QgsGrassMapsetItem::objectInImports( QgsGrassObject grassObject )
Expand Down

0 comments on commit 492c6d9

Please sign in to comment.