Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Empty records cleaned from layer
  • Loading branch information
ccrook committed Apr 17, 2013
1 parent e5bdac7 commit d882c4c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Expand Up @@ -53,8 +53,10 @@ bool QgsDelimitedTextFeatureIterator::nextFeature( QgsFeature& feature )
while ( true )
{
QgsDelimitedTextFile::Status status = P->mFile->nextRecord( tokens );
int fid = P->mFile->recordLineNumber();
if ( status == QgsDelimitedTextFile::RecordEOF ) break;
if ( status != QgsDelimitedTextFile::RecordOk ) continue;
if( P->recordIsEmpty(tokens)) continue;

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

mFid++;

// At this point the current feature values are valid

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

if ( geom )
Expand Down Expand Up @@ -127,8 +127,6 @@ bool QgsDelimitedTextFeatureIterator::rewind()
if ( mClosed )
return false;

// Reset feature id to 0
mFid = 0;
// Skip to first data record
P->resetStream();
return true;
Expand Down
3 changes: 0 additions & 3 deletions src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.h
Expand Up @@ -38,9 +38,6 @@ class QgsDelimitedTextFeatureIterator : public QgsAbstractFeatureIterator
protected:
QgsDelimitedTextProvider* P;

//! Feature id
long mFid;

QgsGeometry* loadGeometryWkt( const QStringList& tokens );
QgsGeometry* loadGeometryXY( const QStringList& tokens );

Expand Down
11 changes: 11 additions & 0 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -246,6 +246,8 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
recordInvalidLine( tr( "Invalid record format at line %1" ) );
continue;
}
// Skip over empty records
if( recordIsEmpty(parts)) continue;

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

bool QgsDelimitedTextProvider::recordIsEmpty(QStringList &record)
{
foreach( QString s, record )
{
if( ! s.isEmpty()) return false;
}
return true;
}

void QgsDelimitedTextProvider::recordInvalidLine( QString message )
{
if ( mInvalidLines.size() < mMaxInvalidLines )
Expand Down
1 change: 1 addition & 0 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.h
Expand Up @@ -174,6 +174,7 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
void recordInvalidLine( QString message );
void handleInvalidLines();
void resetStream();
bool recordIsEmpty( QStringList &record );

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

0 comments on commit d882c4c

Please sign in to comment.