Skip to content
Permalink
Browse files

Empty records cleaned from layer

  • Loading branch information
ccrook committed Apr 17, 2013
1 parent e5bdac7 commit d882c4c8bb0033a6ec2b83a1a2b775d39247531d
@@ -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 );
@@ -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 )
@@ -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;
@@ -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 );

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

0 comments on commit d882c4c

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