Skip to content

Commit ab7828e

Browse files
committedMay 28, 2015
[GRASS] raster import blocking read for Windows
1 parent e721905 commit ab7828e

File tree

1 file changed

+68
-6
lines changed

1 file changed

+68
-6
lines changed
 

‎src/providers/grass/qgis.r.in.cpp

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,62 @@ extern "C"
6262
#define G_unopen_cell Rast_unopen
6363
#endif
6464

65+
// Bad, bad, bad
66+
// http://lists.qt-project.org/pipermail/interest/2012-May/002110.html
67+
// http://lists.qt-project.org/pipermail/interest/2012-May/002117.html
68+
// TODO: This is just test if it works on Windows
69+
QByteArray readData( QFile & file, quint32 size )
70+
{
71+
QByteArray byteArray;
72+
forever
73+
{
74+
byteArray += file.read( size - byteArray.size() );
75+
if ( byteArray.size() == size )
76+
{
77+
break;
78+
}
79+
}
80+
return byteArray;
81+
}
82+
83+
bool readBool( QFile & file )
84+
{
85+
QDataStream dataStream( readData( file, sizeof( bool ) ) );
86+
bool value;
87+
dataStream >> value;
88+
return value;
89+
}
90+
91+
qint32 readQint32( QFile & file )
92+
{
93+
QDataStream dataStream( readData( file, sizeof( qint32 ) ) );
94+
qint32 value;
95+
dataStream >> value;
96+
return value;
97+
}
98+
99+
quint32 readQuint32( QFile & file )
100+
{
101+
QDataStream dataStream( readData( file, sizeof( quint32 ) ) );
102+
quint32 value;
103+
dataStream >> value;
104+
return value;
105+
}
106+
107+
QgsRectangle readRectangle( QFile & file )
108+
{
109+
QDataStream dataStream( readData( file, 4*sizeof( double ) ) );
110+
QgsRectangle rectangle;
111+
dataStream >> rectangle;
112+
return rectangle;
113+
}
114+
115+
QByteArray readByteArray( QFile & file )
116+
{
117+
quint32 size = readQuint32( file );
118+
return readData( file, size );
119+
}
120+
65121
int main( int argc, char **argv )
66122
{
67123
char *name;
@@ -82,15 +138,18 @@ int main( int argc, char **argv )
82138

83139
QFile stdinFile;
84140
stdinFile.open( stdin, QIODevice::ReadOnly );
85-
QDataStream stdinStream( &stdinFile );
141+
//QDataStream stdinStream( &stdinFile );
86142

87143
QFile stdoutFile;
88144
stdoutFile.open( stdout, QIODevice::WriteOnly );
89145
QDataStream stdoutStream( &stdoutFile );
90146

91147
QgsRectangle extent;
92148
qint32 rows, cols;
93-
stdinStream >> extent >> cols >> rows;
149+
//stdinStream >> extent >> cols >> rows;
150+
extent = readRectangle( stdinFile );
151+
cols = readQint32( stdinFile );
152+
rows = readQint32( stdinFile );
94153

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

103162
QGis::DataType qgis_type;
104163
qint32 type;
105-
stdinStream >> type;
164+
//stdinStream >> type;
165+
type = readQint32( stdinFile );
106166
qgis_type = ( QGis::DataType )type;
107167

108168
RASTER_MAP_TYPE grass_type;
@@ -136,15 +196,16 @@ int main( int argc, char **argv )
136196
QByteArray byteArray;
137197
for ( int row = 0; row < rows; row++ )
138198
{
139-
stdinStream >> isCanceled;
199+
//stdinStream >> isCanceled;
200+
isCanceled = readBool( stdinFile );
140201
if ( isCanceled )
141202
{
142203
break;
143204
}
144-
stdinStream >> byteArray;
205+
byteArray = readByteArray( stdinFile );
145206
if ( byteArray.size() != expectedSize )
146207
{
147-
G_fatal_error( "Wrong byte array size, expected %d bytes, got %d", expectedSize, byteArray.size() );
208+
G_fatal_error( "Wrong byte array size, expected %d bytes, got %d, row %d / %d", expectedSize, byteArray.size(), row, rows );
148209
return 1;
149210
}
150211

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

179241
if ( isCanceled )
180242
{

0 commit comments

Comments
 (0)
Please sign in to comment.