Skip to content

Commit 272dd9c

Browse files
committedSep 26, 2015
[GRASS] fixed hanging import of larger polygon layers on Linux
1 parent 48d16ed commit 272dd9c

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed
 

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,21 @@ int main( int argc, char **argv )
221221
QgsFeature feature;
222222
struct line_cats *cats = Vect_new_cats_struct();
223223

224-
qint32 featureCount = 0;
224+
qint32 featureCount;
225+
stdinStream >> featureCount;
226+
227+
qint32 count = 0;
225228
while ( true )
226229
{
227230
exitIfCanceled( stdinStream );
228231
stdinStream >> feature;
229232
checkStream( stdinStream );
230233
#ifndef Q_OS_WIN
231234
// cannot be used on Windows, see notes in qgis.r.in
235+
//#if 0
232236
stdoutStream << true; // feature received
233237
stdoutFile.flush();
238+
//#endif
234239
#endif
235240
if ( !feature.isValid() )
236241
{
@@ -310,7 +315,8 @@ int main( int argc, char **argv )
310315
G_fatal_error( "Cannot insert: %s", e.what() );
311316
}
312317
}
313-
featureCount++;
318+
count++;
319+
G_percent( count, featureCount, 1 );
314320
}
315321
db_commit_transaction( driver );
316322
db_close_database_shutdown_driver( driver );
@@ -395,16 +401,20 @@ int main( int argc, char **argv )
395401
centroids.insert( area, feature );
396402
spatialIndex.insertFeature( feature );
397403
}
404+
398405
G_message( "Attaching input polygons to cleaned areas" );
399406
// read once more to assign centroids to polygons
407+
count = 0;
400408
while ( true )
401409
{
402410
exitIfCanceled( stdinStream );
403411
stdinStream >> feature;
404412
checkStream( stdinStream );
405413
#ifndef Q_OS_WIN
414+
#if 0
406415
stdoutStream << true; // feature received
407416
stdoutFile.flush();
417+
#endif
408418
#endif
409419
if ( !feature.isValid() )
410420
{
@@ -426,12 +436,17 @@ int main( int argc, char **argv )
426436
centroid.setAttributes( attr );
427437
}
428438
}
439+
count++;
440+
G_percent( count, featureCount, 1 );
429441
}
430442

443+
G_message( "Copying lines from temporary map" );
431444
Vect_copy_map_lines( tmpMap, finalMap );
432445
Vect_close( tmpMap );
433446
Vect_delete( tmpName.toUtf8().data() );
434447

448+
int centroidsCount = centroids.size();
449+
count = 0;
435450
foreach ( QgsFeature centroid, centroids.values() )
436451
{
437452
QgsPoint point = centroid.geometry()->asPoint();
@@ -445,12 +460,16 @@ int main( int argc, char **argv )
445460
}
446461
writePoint( finalMap, GV_CENTROID, point, cats );
447462
}
463+
G_percent( count, centroidsCount, 1 );
448464
}
449465
}
450466

467+
G_message( "Building final map topology" );
451468
Vect_build( finalMap );
452469
Vect_close( finalMap );
453470

471+
G_message( "Done" );
472+
454473
stdoutStream << true; // to keep caller waiting until finished
455474
stdoutFile.flush();
456475
// TODO history

‎src/providers/grass/qgsgrassimport.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,11 @@ bool QgsGrassVectorImport::import()
588588

589589
outStream << mProvider->fields();
590590

591+
qint32 featureCount = mProvider->featureCount();
592+
outStream << featureCount;
593+
591594
QgsFeatureIterator iterator = mProvider->getFeatures();
592595
QgsFeature feature;
593-
mProgress->setRange( 1, mProvider->featureCount() );
594596
mProgress->append( tr( "Writing features" ) );
595597
for ( int i = 0; i < ( isPolygon ? 2 : 1 ); i++ ) // two cycles with polygons
596598
{
@@ -600,10 +602,13 @@ bool QgsGrassVectorImport::import()
600602
iterator = mProvider->getFeatures();
601603
}
602604
QgsDebugMsg( "send features" );
605+
// Better to get real progress from module (without buffer)
606+
#if 0
607+
mProgress->setRange( 1, featureCount );
608+
#endif
603609
int count = 0;
604610
while ( iterator.nextFeature( feature ) )
605611
{
606-
mProgress->setValue( count + 1 );
607612
if ( !feature.isValid() )
608613
{
609614
continue;
@@ -625,11 +630,26 @@ bool QgsGrassVectorImport::import()
625630

626631
#ifndef Q_OS_WIN
627632
// wait until the feature is written to allow quick cancel (don't send data to buffer)
633+
634+
// Feedback disabled because it was sometimes hanging on Linux, for example, when importing polygons
635+
// the features were written ok in the first run, but after cleaning of polygons, which takes some time
636+
// it was hanging here for few seconds after each feature, but data did not arrive to the modulee anyway,
637+
// QFSFileEnginePrivate::nativeRead() was hanging on fgetc()
638+
639+
// TODO: inspect what is happening in QProcess, if there is some buffer and how to disable it
640+
#if 0
628641
mProcess->waitForReadyRead();
629642
bool result;
630643
outStream >> result;
644+
#endif
631645
#endif
632646
count++;
647+
#if 0
648+
if ( count % 100 == 0 )
649+
{
650+
mProgress->setValue( count );
651+
}
652+
#endif
633653
// get some feedback for large datasets
634654
if ( count % 10000 == 0 )
635655
{
@@ -644,9 +664,12 @@ bool QgsGrassVectorImport::import()
644664
mProcess->waitForBytesWritten( -1 );
645665
QgsDebugMsg( "features sent" );
646666
#ifndef Q_OS_WIN
667+
#if 0
647668
mProcess->waitForReadyRead();
648669
bool result;
649670
outStream >> result;
671+
QgsDebugMsg( "got feedback" );
672+
#endif
650673
#endif
651674
}
652675
iterator.close();

0 commit comments

Comments
 (0)
Please sign in to comment.