Skip to content

Commit

Permalink
[GRASS] raster import blocking read for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 28, 2015
1 parent e721905 commit ab7828e
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions src/providers/grass/qgis.r.in.cpp
Expand Up @@ -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;
Expand All @@ -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() )
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit ab7828e

Please sign in to comment.