Skip to content
Permalink
Browse files
Merge pull request #46141 from agiudiceandrea/fix-46117-delimitedtext…
…-csvt

Fix Delimited Text provider types recognition from csvt
  • Loading branch information
elpaso committed Nov 22, 2021
2 parents 1d1d59d + 6a44d72 commit a21530b89f6949820ccc364d5fce4112cd29b1c8
@@ -222,6 +222,7 @@ QStringList QgsDelimitedTextProvider::readCsvtFieldTypes( const QString &filenam
// This is a slightly generous regular expression in that it allows spaces and unquoted field types
// not allowed in OGR CSVT files. Also doesn't care if int and string fields have

strTypeList = strTypeList.toLower();
const QRegularExpression reTypeList( QRegularExpression::anchoredPattern( QStringLiteral( "^(?:\\s*(\\\"?)(?:integer|real|double|long|longlong|int8|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" ) ) );
const QRegularExpressionMatch match = reTypeList.match( strTypeList );
if ( !match.hasMatch() )
@@ -236,7 +237,7 @@ QStringList QgsDelimitedTextProvider::readCsvtFieldTypes( const QString &filenam
QgsDebugMsgLevel( QStringLiteral( "Field type string: %1" ).arg( strTypeList ), 2 );

int pos = 0;
const QRegularExpression reType( QStringLiteral( "(integer|real|double|string|date|datetime|time)" ) );
const QRegularExpression reType( QStringLiteral( "(integer|real|double|string|datetime|date|time)" ) );
QRegularExpressionMatch typeMatch = reType.match( strTypeList, pos );
while ( typeMatch.hasMatch() )
{
@@ -933,6 +933,13 @@ def test_047_datetime(self):
assert vl.fields().at(6).type() == QVariant.Time
assert vl.fields().at(9).type() == QVariant.String

def test_048_csvt_file(self):
# CSVT field types non lowercase
filename = 'testcsvt5.csv'
params = {'geomType': 'none', 'type': 'csv'}
requests = None
self.runTest(filename, requests, **params)

def testSpatialIndex(self):
srcpath = os.path.join(TEST_DATA_DIR, 'provider')
basetestfile = os.path.join(srcpath, 'delimited_xyzm.csv')
@@ -2587,3 +2587,32 @@ def test_042_no_detect_types_csvt():
wanted['log'] = [
]
return wanted


def test_048_csvt_file():
wanted = {}
wanted['uri'] = 'file://testcsvt5.csv?geomType=none&type=csv'
wanted['fieldTypes'] = ['text', 'text', 'double', 'double', 'double']
wanted['geometryType'] = 4
wanted['data'] = {
2: {
'id': '01',
'description': 'Test csvt 1',
'f1': '0.3',
'f2': '0.8',
'f3': '1.4',
'#fid': 2,
'#geometry': 'None',
},
3: {
'id': '12',
'description': 'Test csvt 2',
'f1': '0.2',
'f2': '78.0',
'f3': '13.4',
'#fid': 3,
'#geometry': 'None',
},
}
wanted['log'] = []
return wanted
@@ -0,0 +1,3 @@
id,description,f1,f2,f3
01,Test csvt 1,0.3,0.8,1.4
12,Test csvt 2,0.2,78,13.4
@@ -0,0 +1 @@
"String","String","Real","Real","Real"

0 comments on commit a21530b

Please sign in to comment.