Skip to content

Commit d882c4c

Browse files
committedApr 17, 2013
Empty records cleaned from layer
1 parent e5bdac7 commit d882c4c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed
 

‎src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ bool QgsDelimitedTextFeatureIterator::nextFeature( QgsFeature& feature )
5353
while ( true )
5454
{
5555
QgsDelimitedTextFile::Status status = P->mFile->nextRecord( tokens );
56+
int fid = P->mFile->recordLineNumber();
5657
if ( status == QgsDelimitedTextFile::RecordEOF ) break;
5758
if ( status != QgsDelimitedTextFile::RecordOk ) continue;
59+
if( P->recordIsEmpty(tokens)) continue;
5860

5961
while ( tokens.size() < P->mFieldCount )
6062
tokens.append( QString::null );
@@ -80,13 +82,11 @@ bool QgsDelimitedTextFeatureIterator::nextFeature( QgsFeature& feature )
8082
continue;
8183
}
8284

83-
mFid++;
84-
8585
// At this point the current feature values are valid
8686

8787
feature.setValid( true );
8888
feature.setFields( &P->attributeFields ); // allow name-based attribute lookups
89-
feature.setFeatureId( mFid );
89+
feature.setFeatureId( fid );
9090
feature.initAttributes( P->attributeFields.count() );
9191

9292
if ( geom )
@@ -127,8 +127,6 @@ bool QgsDelimitedTextFeatureIterator::rewind()
127127
if ( mClosed )
128128
return false;
129129

130-
// Reset feature id to 0
131-
mFid = 0;
132130
// Skip to first data record
133131
P->resetStream();
134132
return true;

‎src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class QgsDelimitedTextFeatureIterator : public QgsAbstractFeatureIterator
3838
protected:
3939
QgsDelimitedTextProvider* P;
4040

41-
//! Feature id
42-
long mFid;
43-
4441
QgsGeometry* loadGeometryWkt( const QStringList& tokens );
4542
QgsGeometry* loadGeometryXY( const QStringList& tokens );
4643

‎src/providers/delimitedtext/qgsdelimitedtextprovider.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
246246
recordInvalidLine( tr( "Invalid record format at line %1" ) );
247247
continue;
248248
}
249+
// Skip over empty records
250+
if( recordIsEmpty(parts)) continue;
249251

250252
// If not using column headers, then expand column count to include
251253
// last non-null (blank) column
@@ -534,6 +536,15 @@ void QgsDelimitedTextProvider::clearInvalidLines()
534536
mNExtraInvalidLines = 0;
535537
}
536538

539+
bool QgsDelimitedTextProvider::recordIsEmpty(QStringList &record)
540+
{
541+
foreach( QString s, record )
542+
{
543+
if( ! s.isEmpty()) return false;
544+
}
545+
return true;
546+
}
547+
537548
void QgsDelimitedTextProvider::recordInvalidLine( QString message )
538549
{
539550
if ( mInvalidLines.size() < mMaxInvalidLines )

‎src/providers/delimitedtext/qgsdelimitedtextprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
174174
void recordInvalidLine( QString message );
175175
void handleInvalidLines();
176176
void resetStream();
177+
bool recordIsEmpty( QStringList &record );
177178

178179
QgsGeometry *geomFromWkt( QString &sWkt );
179180
bool pointFromXY( QString &sX, QString &sY, QgsPoint &point );

0 commit comments

Comments
 (0)
Please sign in to comment.