Skip to content
Permalink
Browse files

[processing] Add option for converting field names to lowercase for I…

…mport to PostGIS algorithm
  • Loading branch information
nyalldawson committed Mar 25, 2014
1 parent 5997c78 commit 748d261d2153dba03f0a30a204a4749a7fd9c5d9
@@ -50,6 +50,7 @@ class ImportIntoPostGIS(GeoAlgorithm):
OVERWRITE = 'OVERWRITE'
CREATEINDEX = 'CREATEINDEX'
GEOMETRY_COLUMN = 'GEOMETRY_COLUMN'
LOWERCASE_NAMES = 'LOWERCASE_NAMES'

def getIcon(self):
return QIcon(os.path.dirname(__file__) + '/../images/postgis.png')
@@ -59,6 +60,7 @@ def processAlgorithm(self, progress):
schema = self.getParameterValue(self.SCHEMA)
overwrite = self.getParameterValue(self.OVERWRITE)
createIndex = self.getParameterValue(self.CREATEINDEX)
convertLowerCase = self.getParameterValue(self.LOWERCASE_NAMES)
settings = QSettings()
mySettings = '/PostgreSQL/connections/' + connection
try:
@@ -93,7 +95,8 @@ def processAlgorithm(self, progress):
options = {}
if overwrite:
options['overwrite'] = True

if convertLowerCase:
options['lowercaseFieldNames'] = True
layerUri = self.getParameterValue(self.INPUT)
layer = dataobjects.getObjectFromUri(layerUri)
(ret, errMsg) = QgsVectorLayerImport.importLayer(
@@ -136,3 +139,5 @@ def defineCharacteristics(self):
self.addParameter(ParameterBoolean(self.OVERWRITE, 'Overwrite', True))
self.addParameter(ParameterBoolean(self.CREATEINDEX,
'Create spatial index', True))
self.addParameter(ParameterBoolean(self.LOWERCASE_NAMES,
'Convert field names to lowercase', False))
@@ -2844,8 +2844,6 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
QString *errorMessage,
const QMap<QString, QVariant> *options )
{
Q_UNUSED( options );

// populate members from the uri structure
QgsDataSourceURI dsUri( uri );
QString schemaName = dsUri.schema();
@@ -3048,6 +3046,12 @@ QgsVectorLayerImport::ImportError QgsPostgresProvider::createEmptyLayer(
continue;
}

if ( options->contains( "lowercaseFieldNames" ) && options->value( "lowercaseFieldNames" ).toBool() )
{
//convert field name to lowercase
fld.setName( fld.name().toLower() );
}

if ( !convertField( fld ) )
{
if ( errorMessage )

0 comments on commit 748d261

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