Skip to content

Commit

Permalink
[GRASS] vector import: increase cat by 1 if fid starts at 0
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 8, 2015
1 parent d709496 commit de20495
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/providers/grass/qgis.v.in.cpp
Expand Up @@ -221,6 +221,9 @@ int main( int argc, char **argv )
QgsFeature feature;
struct line_cats *cats = Vect_new_cats_struct();

qint32 fidToCatPlus;
stdinStream >> fidToCatPlus;

qint32 featureCount;
stdinStream >> featureCount;

Expand Down Expand Up @@ -250,7 +253,7 @@ int main( int argc, char **argv )
if ( !isPolygon )
{
Vect_reset_cats( cats );
Vect_cat_set( cats, 1, ( int )feature.id() );
Vect_cat_set( cats, 1, ( int )feature.id() + fidToCatPlus );
}

if ( geometryType == QGis::WKBPoint )
Expand Down Expand Up @@ -432,7 +435,7 @@ int main( int argc, char **argv )
if ( feature.geometry()->contains( centroid.geometry() ) )
{
QgsAttributes attr = centroid.attributes();
attr.append( feature.id() );
attr.append(( int )feature.id() + fidToCatPlus );
centroid.setAttributes( attr );
}
}
Expand Down
22 changes: 17 additions & 5 deletions src/providers/grass/qgsgrassimport.cpp
Expand Up @@ -598,19 +598,31 @@ bool QgsGrassVectorImport::import()

outStream << mProvider->fields();

// FID may be 0, but cat should be >= 1 -> check if fid 0 exists
qint32 fidToCatPlus = 0;
QgsFeature feature;
QgsFeatureIterator iterator = mProvider->getFeatures( QgsFeatureRequest().setFilterFid( 0 ) );
if ( iterator.nextFeature( feature ) )
{
fidToCatPlus = 1;
}
iterator.close();
outStream << fidToCatPlus;

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

QgsFeatureIterator iterator = mProvider->getFeatures();
QgsFeature feature;
mProgress->append( tr( "Writing features" ) );
for ( int i = 0; i < ( isPolygon ? 2 : 1 ); i++ ) // two cycles with polygons
{
iterator = mProvider->getFeatures();
// rewind does not work
#if 0
if ( i > 0 ) // second run for polygons
{
//iterator.rewind(); // rewind does not work
iterator = mProvider->getFeatures();
iterator.rewind();
}
#endif
QgsDebugMsg( "send features" );
// Better to get real progress from module (without buffer)
#if 0
Expand Down Expand Up @@ -681,8 +693,8 @@ bool QgsGrassVectorImport::import()
QgsDebugMsg( "got feedback" );
#endif
#endif
iterator.close();
}
iterator.close();

// Close write channel before waiting for response to avoid stdin buffer problem on Windows
mProcess->closeWriteChannel();
Expand Down

0 comments on commit de20495

Please sign in to comment.