Skip to content
Permalink
Browse files

[GRASS] raster import null values

  • Loading branch information
blazek committed Jun 25, 2015
1 parent 91058aa commit 492c6d91100b6003d05cc21b1b0828cd13e309c9
@@ -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 ) );
}
@@ -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
@@ -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)
@@ -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 )

0 comments on commit 492c6d9

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