Skip to content
Permalink
Browse files

Fix delimited text layers set to unknown geometry type if first row has

null geometry (fix #13749)
  • Loading branch information
nyalldawson committed Nov 6, 2015
1 parent 6a1d206 commit 743964393450178289e6717d67cdba04c6206e23
@@ -409,6 +409,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
QList<bool> couldBeInt;
QList<bool> couldBeLongLong;
QList<bool> couldBeDouble;
bool foundFirstGeometry = false;

while ( true )
{
@@ -458,11 +459,12 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
if ( mGeometryType == QGis::UnknownGeometry || geom->type() == mGeometryType )
{
mGeometryType = geom->type();
if ( mNumberFeatures == 0 )
if ( !foundFirstGeometry )
{
mNumberFeatures++;
mWkbType = type;
mExtent = geom->boundingBox();
foundFirstGeometry = true;
}
else
{
@@ -517,7 +519,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )

if ( ok )
{
if ( mNumberFeatures > 0 )
if ( foundFirstGeometry )
{
mExtent.combineExtentWith( pt.x(), pt.y() );
}
@@ -527,6 +529,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
mExtent.set( pt.x(), pt.y(), pt.x(), pt.y() );
mWkbType = QGis::WKBPoint;
mGeometryType = QGis::Point;
foundFirstGeometry = true;
}
mNumberFeatures++;
if ( buildSpatialIndex && qIsFinite( pt.x() ) && qIsFinite( pt.y() ) )
@@ -778,13 +781,15 @@ void QgsDelimitedTextProvider::rescanFile()
mNumberFeatures = 0;
mExtent = QgsRectangle();
QgsFeature f;
bool foundFirstGeometry = false;
while ( fi.nextFeature( f ) )
{
if ( mGeometryType != QGis::NoGeometry )
{
if ( mNumberFeatures == 0 )
if ( !foundFirstGeometry )
{
mExtent = f.constGeometry()->boundingBox();
foundFirstGeometry = true;
}
else
{
@@ -43,7 +43,8 @@
QgsVectorLayer,
QgsFeatureRequest,
QgsRectangle,
QgsMessageLog
QgsMessageLog,
QGis
)

from utilities import (getQgisTestApp,
@@ -190,7 +191,7 @@ def delimitedTextData(testname, filename, requests, verbose, **params):
msg = re.sub(r'file\s+.*' + re.escape(filename), 'file ' + filelogname, msg)
msg = msg.replace(filepath, filelogname)
log.append(msg)
return dict(fields=fields, fieldTypes=fieldTypes, data=data, log=log, uri=uri)
return dict(fields=fields, fieldTypes=fieldTypes, data=data, log=log, uri=uri, geometryType=layer.geometryType())


def printWanted(testname, result):
@@ -206,6 +207,7 @@ def printWanted(testname, result):
print prefix + "wanted={}"
print prefix + "wanted['uri']=" + repr(result['uri'])
print prefix + "wanted['fieldTypes']=" + repr(result['fieldTypes'])
print prefix + "wanted['geometryType']=" + repr(result['geometryType'])
print prefix + "wanted['data']={"
for k in sorted(data.keys()):
row = data[k]
@@ -272,6 +274,10 @@ def runTest(file, requests, **params):
msg = "Layer field types ({0}) doesn't match expected ({1})".format(
result['fieldTypes'], wanted['fieldTypes'])
failures.append(msg)
if result['geometryType'] != wanted['geometryType']:
msg = "Layer geometry type ({0}) doesn't match expected ({1})".format(
result['geometryType'], wanted['geometryType'])
failures.append(msg)
wanted_data = wanted['data']
for id in sorted(wanted_data.keys()):
wrec = wanted_data[id]
@@ -728,5 +734,13 @@ def test_038_type_inference(self):
requests = None
runTest(filename, requests, **params)

def test_039_issue_13749(self):
# First record contains missing geometry
filename = 'test13749.csv'
params = {'yField': 'geom_y', 'xField': 'geom_x', 'type': 'csv'}
requests = None
runTest(filename, requests, **params)


if __name__ == '__main__':
unittest.main()

0 comments on commit 7439643

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