Skip to content

Commit

Permalink
[processing] Accept geometry-less layers in more algorithms
Browse files Browse the repository at this point in the history
Fixes #19685

(cherry picked from commit 83feea4)
  • Loading branch information
nyalldawson committed Aug 27, 2018
1 parent d416e14 commit 9d07a8f
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 67 deletions.
52 changes: 35 additions & 17 deletions python/plugins/processing/algs/gdal/OgrToPostGis.py
Expand Up @@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingException,
from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterEnum,
Expand All @@ -41,11 +42,11 @@


class OgrToPostGis(GdalAlgorithm):

INPUT = 'INPUT'
SHAPE_ENCODING = 'SHAPE_ENCODING'
GTYPE = 'GTYPE'
GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT', 'MULTIPOLYGON', 'MULTILINESTRING']
GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT',
'MULTIPOLYGON', 'MULTILINESTRING']
S_SRS = 'S_SRS'
T_SRS = 'T_SRS'
A_SRS = 'A_SRS'
Expand Down Expand Up @@ -82,15 +83,18 @@ def __init__(self):

def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer')))
self.tr('Input layer'),
types=[QgsProcessing.TypeVector]))
self.addParameter(QgsProcessingParameterString(self.SHAPE_ENCODING,
self.tr('Shape encoding'), "", optional=True))
self.addParameter(QgsProcessingParameterEnum(self.GTYPE,
self.tr('Output geometry type'), options=self.GEOMTYPE, defaultValue=0))
self.tr('Output geometry type'), options=self.GEOMTYPE,
defaultValue=0))
self.addParameter(QgsProcessingParameterCrs(self.A_SRS,
self.tr('Assign an output CRS'), defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterCrs(self.T_SRS,
self.tr('Reproject to this CRS on output '), defaultValue='', optional=True))
self.tr('Reproject to this CRS on output '), defaultValue='',
optional=True))
self.addParameter(QgsProcessingParameterCrs(self.S_SRS,
self.tr('Override source CRS'), defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterString(self.HOST,
Expand All @@ -109,26 +113,35 @@ def initAlgorithm(self, config=None):
self.tr('Table name, leave blank to use input name'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterString(self.PK,
self.tr('Primary key (new field)'), defaultValue='id', optional=True))
self.tr('Primary key (new field)'), defaultValue='id',
optional=True))
self.addParameter(QgsProcessingParameterField(self.PRIMARY_KEY,
self.tr('Primary key (existing field, used if the above option is left empty)'), parentLayerParameterName=self.INPUT, optional=True))
self.tr(
'Primary key (existing field, used if the above option is left empty)'),
parentLayerParameterName=self.INPUT, optional=True))
self.addParameter(QgsProcessingParameterString(self.GEOCOLUMN,
self.tr('Geometry column name'), defaultValue='geom', optional=True))
self.tr('Geometry column name'), defaultValue='geom',
optional=True))
self.addParameter(QgsProcessingParameterEnum(self.DIM,
self.tr('Vector dimensions'), options=self.DIMLIST, defaultValue=0))
self.tr('Vector dimensions'), options=self.DIMLIST,
defaultValue=0))
self.addParameter(QgsProcessingParameterString(self.SIMPLIFY,
self.tr('Distance tolerance for simplification'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterString(self.SEGMENTIZE,
self.tr('Maximum distance between 2 nodes (densification)'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterExtent(self.SPAT,
self.tr('Select features by extent (defined in input layer CRS)'), optional=True))
self.tr(
'Select features by extent (defined in input layer CRS)'),
optional=True))
self.addParameter(QgsProcessingParameterBoolean(self.CLIP,
self.tr('Clip the input layer using the above (rectangle) extent'),
self.tr(
'Clip the input layer using the above (rectangle) extent'),
defaultValue=False))
self.addParameter(QgsProcessingParameterString(self.WHERE,
self.tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'),
self.tr(
'Select features using a SQL "WHERE" statement (Ex: column=\'value\')'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterString(self.GT,
self.tr('Group N features per transaction (Default: 20000)'),
Expand All @@ -138,21 +151,26 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterBoolean(self.APPEND,
self.tr('Append to existing table'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.ADDFIELDS,
self.tr('Append and add new fields to existing table'), defaultValue=False))
self.tr('Append and add new fields to existing table'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.LAUNDER,
self.tr('Do not launder columns/table names'), defaultValue=False))
self.tr('Do not launder columns/table names'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.INDEX,
self.tr('Do not create spatial index'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.SKIPFAILURES,
self.tr('Continue after a failure, skipping the failed feature'), defaultValue=False))
self.tr(
'Continue after a failure, skipping the failed feature'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.PROMOTETOMULTI,
self.tr('Promote to Multipart'),
defaultValue=True))
self.addParameter(QgsProcessingParameterBoolean(self.PRECISION,
self.tr('Keep width and precision of input attributes'),
defaultValue=True))
self.addParameter(QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'), defaultValue='', optional=True))
self.tr('Additional creation options'), defaultValue='',
optional=True))

def name(self):
return 'importvectorintopostgisdatabasenewconnection'
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/processing/algs/gdal/ogr2ogr.py
Expand Up @@ -27,7 +27,8 @@

import os

from qgis.core import (QgsProcessingException,
from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
Expand All @@ -37,7 +38,6 @@


class ogr2ogr(GdalAlgorithm):

INPUT = 'INPUT'
OPTIONS = 'OPTIONS'
OUTPUT = 'OUTPUT'
Expand All @@ -47,7 +47,8 @@ def __init__(self):

def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer')))
self.tr('Input layer'),
types=[QgsProcessing.TypeVector]))

options_param = QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
Expand Down
52 changes: 35 additions & 17 deletions python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py
Expand Up @@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterFeatureSource,
from qgis.core import (QgsProcessing,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterEnum,
QgsProcessingParameterCrs,
Expand All @@ -41,12 +42,12 @@


class Ogr2OgrToPostGisList(GdalAlgorithm):

DATABASE = 'DATABASE'
INPUT = 'INPUT'
SHAPE_ENCODING = 'SHAPE_ENCODING'
GTYPE = 'GTYPE'
GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT', 'MULTIPOLYGON', 'MULTILINESTRING']
GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT',
'MULTIPOLYGON', 'MULTILINESTRING']
S_SRS = 'S_SRS'
T_SRS = 'T_SRS'
A_SRS = 'A_SRS'
Expand Down Expand Up @@ -91,15 +92,18 @@ def initAlgorithm(self, config=None):
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
self.addParameter(db_param)
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer')))
self.tr('Input layer'),
types=[QgsProcessing.TypeVector]))
self.addParameter(QgsProcessingParameterString(self.SHAPE_ENCODING,
self.tr('Shape encoding'), "", optional=True))
self.addParameter(QgsProcessingParameterEnum(self.GTYPE,
self.tr('Output geometry type'), options=self.GEOMTYPE, defaultValue=0))
self.tr('Output geometry type'), options=self.GEOMTYPE,
defaultValue=0))
self.addParameter(QgsProcessingParameterCrs(self.A_SRS,
self.tr('Assign an output CRS'), defaultValue='', optional=False))
self.addParameter(QgsProcessingParameterCrs(self.T_SRS,
self.tr('Reproject to this CRS on output '), defaultValue='', optional=True))
self.tr('Reproject to this CRS on output '), defaultValue='',
optional=True))
self.addParameter(QgsProcessingParameterCrs(self.S_SRS,
self.tr('Override source CRS'), defaultValue='', optional=True))

Expand All @@ -122,26 +126,35 @@ def initAlgorithm(self, config=None):
self.addParameter(table_param)

self.addParameter(QgsProcessingParameterString(self.PK,
self.tr('Primary key (new field)'), defaultValue='id', optional=True))
self.tr('Primary key (new field)'), defaultValue='id',
optional=True))
self.addParameter(QgsProcessingParameterField(self.PRIMARY_KEY,
self.tr('Primary key (existing field, used if the above option is left empty)'), parentLayerParameterName=self.INPUT, optional=True))
self.tr(
'Primary key (existing field, used if the above option is left empty)'),
parentLayerParameterName=self.INPUT, optional=True))
self.addParameter(QgsProcessingParameterString(self.GEOCOLUMN,
self.tr('Geometry column name'), defaultValue='geom', optional=True))
self.tr('Geometry column name'), defaultValue='geom',
optional=True))
self.addParameter(QgsProcessingParameterEnum(self.DIM,
self.tr('Vector dimensions'), options=self.DIMLIST, defaultValue=0))
self.tr('Vector dimensions'), options=self.DIMLIST,
defaultValue=0))
self.addParameter(QgsProcessingParameterString(self.SIMPLIFY,
self.tr('Distance tolerance for simplification'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterString(self.SEGMENTIZE,
self.tr('Maximum distance between 2 nodes (densification)'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterExtent(self.SPAT,
self.tr('Select features by extent (defined in input layer CRS)'), optional=True))
self.tr(
'Select features by extent (defined in input layer CRS)'),
optional=True))
self.addParameter(QgsProcessingParameterBoolean(self.CLIP,
self.tr('Clip the input layer using the above (rectangle) extent'),
self.tr(
'Clip the input layer using the above (rectangle) extent'),
defaultValue=False))
self.addParameter(QgsProcessingParameterString(self.WHERE,
self.tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'),
self.tr(
'Select features using a SQL "WHERE" statement (Ex: column=\'value\')'),
defaultValue='', optional=True))
self.addParameter(QgsProcessingParameterString(self.GT,
self.tr('Group N features per transaction (Default: 20000)'),
Expand All @@ -151,21 +164,26 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterBoolean(self.APPEND,
self.tr('Append to existing table'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.ADDFIELDS,
self.tr('Append and add new fields to existing table'), defaultValue=False))
self.tr('Append and add new fields to existing table'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.LAUNDER,
self.tr('Do not launder columns/table names'), defaultValue=False))
self.tr('Do not launder columns/table names'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.INDEX,
self.tr('Do not create spatial index'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.SKIPFAILURES,
self.tr('Continue after a failure, skipping the failed feature'), defaultValue=False))
self.tr(
'Continue after a failure, skipping the failed feature'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.PROMOTETOMULTI,
self.tr('Promote to Multipart'),
defaultValue=True))
self.addParameter(QgsProcessingParameterBoolean(self.PRECISION,
self.tr('Keep width and precision of input attributes'),
defaultValue=True))
self.addParameter(QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'), defaultValue='', optional=True))
self.tr('Additional creation options'), defaultValue='',
optional=True))

def name(self):
return 'importvectorintopostgisdatabaseavailableconnections'
Expand Down

0 comments on commit 9d07a8f

Please sign in to comment.