Skip to content
Permalink
Browse files
[GRASS] raster import blocking read for Windows
  • Loading branch information
blazek committed May 28, 2015
1 parent e721905 commit ab7828e90bb698050d90be37c1ce12d8815b7289
Showing with 68 additions and 6 deletions.
  1. +68 −6 src/providers/grass/qgis.r.in.cpp
@@ -62,6 +62,62 @@ extern "C"
#define G_unopen_cell Rast_unopen
#endif

// Bad, bad, bad
// http://lists.qt-project.org/pipermail/interest/2012-May/002110.html
// http://lists.qt-project.org/pipermail/interest/2012-May/002117.html
// TODO: This is just test if it works on Windows
QByteArray readData( QFile & file, quint32 size )
{
QByteArray byteArray;
forever
{
byteArray += file.read( size - byteArray.size() );
if ( byteArray.size() == size )
{
break;
}
}
return byteArray;
}

bool readBool( QFile & file )
{
QDataStream dataStream( readData( file, sizeof( bool ) ) );
bool value;
dataStream >> value;
return value;
}

qint32 readQint32( QFile & file )
{
QDataStream dataStream( readData( file, sizeof( qint32 ) ) );
qint32 value;
dataStream >> value;
return value;
}

quint32 readQuint32( QFile & file )
{
QDataStream dataStream( readData( file, sizeof( quint32 ) ) );
quint32 value;
dataStream >> value;
return value;
}

QgsRectangle readRectangle( QFile & file )
{
QDataStream dataStream( readData( file, 4*sizeof( double ) ) );
QgsRectangle rectangle;
dataStream >> rectangle;
return rectangle;
}

QByteArray readByteArray( QFile & file )
{
quint32 size = readQuint32( file );
return readData( file, size );
}

int main( int argc, char **argv )
{
char *name;
@@ -82,15 +138,18 @@ int main( int argc, char **argv )

QFile stdinFile;
stdinFile.open( stdin, QIODevice::ReadOnly );
QDataStream stdinStream( &stdinFile );
//QDataStream stdinStream( &stdinFile );

QFile stdoutFile;
stdoutFile.open( stdout, QIODevice::WriteOnly );
QDataStream stdoutStream( &stdoutFile );

QgsRectangle extent;
qint32 rows, cols;
stdinStream >> extent >> cols >> rows;
//stdinStream >> extent >> cols >> rows;
extent = readRectangle( stdinFile );
cols = readQint32( stdinFile );
rows = readQint32( stdinFile );

QString err = QgsGrass::setRegion( &window, extent, rows, cols );
if ( !err.isEmpty() )
@@ -102,7 +161,8 @@ int main( int argc, char **argv )

QGis::DataType qgis_type;
qint32 type;
stdinStream >> type;
//stdinStream >> type;
type = readQint32( stdinFile );
qgis_type = ( QGis::DataType )type;

RASTER_MAP_TYPE grass_type;
@@ -136,15 +196,16 @@ int main( int argc, char **argv )
QByteArray byteArray;
for ( int row = 0; row < rows; row++ )
{
stdinStream >> isCanceled;
//stdinStream >> isCanceled;
isCanceled = readBool( stdinFile );
if ( isCanceled )
{
break;
}
stdinStream >> byteArray;
byteArray = readByteArray( stdinFile );
if ( byteArray.size() != expectedSize )
{
G_fatal_error( "Wrong byte array size, expected %d bytes, got %d", expectedSize, byteArray.size() );
G_fatal_error( "Wrong byte array size, expected %d bytes, got %d, row %d / %d", expectedSize, byteArray.size(), row, rows );
return 1;
}

@@ -175,6 +236,7 @@ int main( int argc, char **argv )
stdoutStream << ( bool )true; // row written
stdoutFile.flush();
}
//G_fatal_error( "%s", msg.toAscii().data() );

if ( isCanceled )
{

0 comments on commit ab7828e

Please sign in to comment.