Skip to content
Permalink
Browse files

[GRASS] vector import: increase cat by 1 if fid starts at 0

  • Loading branch information
blazek committed Oct 8, 2015
1 parent d709496 commit de204959111efefd52cf9c7d2f13619373625c39
Showing with 22 additions and 7 deletions.
  1. +5 −2 src/providers/grass/qgis.v.in.cpp
  2. +17 −5 src/providers/grass/qgsgrassimport.cpp
@@ -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;

@@ -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 )
@@ -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 );
}
}
@@ -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
@@ -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();

0 comments on commit de20495

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