Skip to content
Permalink
Browse files

[processing] preserve field length and precision for temporary outputs (

#5654)



* add test case to cover length and precision through uri
  • Loading branch information
nirvn committed Nov 16, 2017
1 parent bb6fda6 commit 05d38b3d1d69324bd1575995f3b8f540faffc839
Showing with 20 additions and 1 deletion.
  1. +10 −1 src/core/providers/memory/qgsmemoryproviderutils.cpp
  2. +10 −0 tests/src/python/test_provider_memory.py
@@ -63,7 +63,16 @@ QgsVectorLayer *QgsMemoryProviderUtils::createMemoryLayer( const QString &name,
}
for ( const auto &field : fields )
{
parts << QStringLiteral( "field=%1:%2" ).arg( field.name(), memoryLayerFieldType( field.type() ) );
QString lengthPrecision;
if ( field.length() > 0 && field.precision() > 0 )
{
lengthPrecision = QStringLiteral( "(%1,%2)" ).arg( field.length() ).arg( field.precision() );
}
else if ( field.length() > 0 )
{
lengthPrecision = QStringLiteral( "(%1)" ).arg( field.length() );
}
parts << QStringLiteral( "field=%1:%2%3" ).arg( field.name(), memoryLayerFieldType( field.type() ), lengthPrecision );
}

QString uri = geomType + '?' + parts.join( '&' );
@@ -263,6 +263,16 @@ def testFromUri(self):
myProvider = myMemoryLayer.dataProvider()
assert myProvider is not None

def testLengthPrecisionFromUri(self):
"""Test we can assign length and precision from a uri"""
myMemoryLayer = QgsVectorLayer(
('Point?crs=epsg:4326&field=size:double(12,9)&index=yes'),
'test',
'memory')

self.assertEqual(myMemoryLayer.fields().field('size').length(), 12)
self.assertEqual(myMemoryLayer.fields().field('size').precision(), 9)

def testSaveFields(self):
# Create a new memory layer with no fields
myMemoryLayer = QgsVectorLayer(

0 comments on commit 05d38b3

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