Skip to content
Permalink
Browse files

[GRASS] fixed hanging import of larger polygon layers on Linux

  • Loading branch information
blazek committed Sep 26, 2015
1 parent 48d16ed commit 272dd9c1cba92be0244e37a6e26b816fdb863a45
Showing with 46 additions and 4 deletions.
  1. +21 −2 src/providers/grass/qgis.v.in.cpp
  2. +25 −2 src/providers/grass/qgsgrassimport.cpp
@@ -221,16 +221,21 @@ int main( int argc, char **argv )
QgsFeature feature;
struct line_cats *cats = Vect_new_cats_struct();

qint32 featureCount = 0;
qint32 featureCount;
stdinStream >> featureCount;

qint32 count = 0;
while ( true )
{
exitIfCanceled( stdinStream );
stdinStream >> feature;
checkStream( stdinStream );
#ifndef Q_OS_WIN
// cannot be used on Windows, see notes in qgis.r.in
//#if 0
stdoutStream << true; // feature received
stdoutFile.flush();
//#endif
#endif
if ( !feature.isValid() )
{
@@ -310,7 +315,8 @@ int main( int argc, char **argv )
G_fatal_error( "Cannot insert: %s", e.what() );
}
}
featureCount++;
count++;
G_percent( count, featureCount, 1 );
}
db_commit_transaction( driver );
db_close_database_shutdown_driver( driver );
@@ -395,16 +401,20 @@ int main( int argc, char **argv )
centroids.insert( area, feature );
spatialIndex.insertFeature( feature );
}

G_message( "Attaching input polygons to cleaned areas" );
// read once more to assign centroids to polygons
count = 0;
while ( true )
{
exitIfCanceled( stdinStream );
stdinStream >> feature;
checkStream( stdinStream );
#ifndef Q_OS_WIN
#if 0
stdoutStream << true; // feature received
stdoutFile.flush();
#endif
#endif
if ( !feature.isValid() )
{
@@ -426,12 +436,17 @@ int main( int argc, char **argv )
centroid.setAttributes( attr );
}
}
count++;
G_percent( count, featureCount, 1 );
}

G_message( "Copying lines from temporary map" );
Vect_copy_map_lines( tmpMap, finalMap );
Vect_close( tmpMap );
Vect_delete( tmpName.toUtf8().data() );

int centroidsCount = centroids.size();
count = 0;
foreach ( QgsFeature centroid, centroids.values() )
{
QgsPoint point = centroid.geometry()->asPoint();
@@ -445,12 +460,16 @@ int main( int argc, char **argv )
}
writePoint( finalMap, GV_CENTROID, point, cats );
}
G_percent( count, centroidsCount, 1 );
}
}

G_message( "Building final map topology" );
Vect_build( finalMap );
Vect_close( finalMap );

G_message( "Done" );

stdoutStream << true; // to keep caller waiting until finished
stdoutFile.flush();
// TODO history
@@ -588,9 +588,11 @@ bool QgsGrassVectorImport::import()

outStream << mProvider->fields();

qint32 featureCount = mProvider->featureCount();
outStream << featureCount;

QgsFeatureIterator iterator = mProvider->getFeatures();
QgsFeature feature;
mProgress->setRange( 1, mProvider->featureCount() );
mProgress->append( tr( "Writing features" ) );
for ( int i = 0; i < ( isPolygon ? 2 : 1 ); i++ ) // two cycles with polygons
{
@@ -600,10 +602,13 @@ bool QgsGrassVectorImport::import()
iterator = mProvider->getFeatures();
}
QgsDebugMsg( "send features" );
// Better to get real progress from module (without buffer)
#if 0
mProgress->setRange( 1, featureCount );
#endif
int count = 0;
while ( iterator.nextFeature( feature ) )
{
mProgress->setValue( count + 1 );
if ( !feature.isValid() )
{
continue;
@@ -625,11 +630,26 @@ bool QgsGrassVectorImport::import()

#ifndef Q_OS_WIN
// wait until the feature is written to allow quick cancel (don't send data to buffer)

// Feedback disabled because it was sometimes hanging on Linux, for example, when importing polygons
// the features were written ok in the first run, but after cleaning of polygons, which takes some time
// it was hanging here for few seconds after each feature, but data did not arrive to the modulee anyway,
// QFSFileEnginePrivate::nativeRead() was hanging on fgetc()

// TODO: inspect what is happening in QProcess, if there is some buffer and how to disable it
#if 0
mProcess->waitForReadyRead();
bool result;
outStream >> result;
#endif
#endif
count++;
#if 0
if ( count % 100 == 0 )
{
mProgress->setValue( count );
}
#endif
// get some feedback for large datasets
if ( count % 10000 == 0 )
{
@@ -644,9 +664,12 @@ bool QgsGrassVectorImport::import()
mProcess->waitForBytesWritten( -1 );
QgsDebugMsg( "features sent" );
#ifndef Q_OS_WIN
#if 0
mProcess->waitForReadyRead();
bool result;
outStream >> result;
QgsDebugMsg( "got feedback" );
#endif
#endif
}
iterator.close();

0 comments on commit 272dd9c

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