Skip to content

Commit

Permalink
[processing] Add option for converting field names to lowercase for I…
Browse files Browse the repository at this point in the history
…mport to PostGIS algorithm
  • Loading branch information
nyalldawson committed Mar 25, 2014
1 parent 5997c78 commit 748d261
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion python/plugins/processing/admintools/ImportIntoPostGIS.py
Expand Up @@ -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')
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
8 changes: 6 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 748d261

Please sign in to comment.