Skip to content

Commit

Permalink
Ported r6511 to trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6512 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Feb 3, 2007
1 parent 62b5121 commit 2a42ccb
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -41,6 +41,7 @@
#include "qgsrect.h"
#include "qgsspatialrefsys.h"
#include "qgis.h"
#include "qgslogger.h"

#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
Expand Down Expand Up @@ -180,6 +181,12 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString uri)
// split the line on the delimiter
QStringList parts =
QStringList::split(mDelimiter, line, true);

// Skip malformed lines silently. Report line number with getNextFeature()
if ( (parts.size() <= fieldPositions[mXField]) || (parts.size() <= fieldPositions[mYField]) )
{
continue;
}
//if(parts.size() == attributeFields.size())
//{
// // we can populate attributes if required
Expand Down Expand Up @@ -338,24 +345,32 @@ QgsDelimitedTextProvider::getNextFeature_( QgsFeature & feature,
feature.setValid( false );
while ( ! mStream->atEnd() )
{
double x = 0.0;
double y = 0.0;
QString line = mStream->readLine(); // Default local 8 bit encoding
// lex the tokens from the current data line
QStringList tokens = QStringList::split(mDelimiter, line, true);

bool xOk = false;
bool yOk = false;

int xFieldPos = fieldPositions[mXField];
int yFieldPos = fieldPositions[mYField];
// Skip indexing malformed lines.
if ( ! ((tokens.size() <= fieldPositions[mXField]) || (tokens.size() <= fieldPositions[mXField])) )
{

int xFieldPos = fieldPositions[mXField];
int yFieldPos = fieldPositions[mYField];

double x = tokens[xFieldPos].toDouble( &xOk );
double y = tokens[yFieldPos].toDouble( &yOk );
x = tokens[xFieldPos].toDouble( &xOk );
y = tokens[yFieldPos].toDouble( &yOk );

}
if (! (xOk && yOk))
{
// Accumulate any lines that weren't ok, to report on them
// later, and look at the next line in the file, but only if
// we need to.
QgsDebugMsg("Malformed line : " + line);
if (mShowInvalidLines)
mInvalidLines << line;

Expand Down

0 comments on commit 2a42ccb

Please sign in to comment.