Skip to content

Commit

Permalink
Add support for different separators (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetsu14 authored Feb 11, 2022
1 parent 5fecfa9 commit 7e9fafa
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions digitransit_geocoder_processing_plugin_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Created
# by Erno Mäkinen ([email protected])
# on 24.3.2018
# Modified
# by Pauliina Mäkinen
# on 10.02.2022

import json
import urllib
Expand All @@ -17,6 +20,7 @@
QgsProcessingParameterFile,
QgsProcessingParameterString,
QgsProcessingParameterBoolean,
QgsProcessingParameterEnum,
QgsProcessingParameterExtent,
QgsProcessingParameterNumber,
QgsWkbTypes,
Expand All @@ -38,9 +42,16 @@ class DigitransitGeocoderPluginAlgorithmError(Exception):
class DigitransitGeocoderPluginAlgorithm(QgsProcessingAlgorithm):
OUTPUT = 'OUTPUT'
INPUT = 'INPUT'
OTHER_SEPARATOR = 'OTHER_SEPARATOR'
SEPARATOR = 'SEPARATOR'
ADDRESS_FIELD_NAMES = 'ADDRESS_FIELD_NAMES'

SEPARATORS = [',',
';',
':',
'Other'
]

SEARCH_EXTENT = 'SEARCH_EXTENT'

SOURCE_OSM = 'SOURCE_OSM'
Expand All @@ -56,6 +67,12 @@ class DigitransitGeocoderPluginAlgorithm(QgsProcessingAlgorithm):

def initAlgorithm(self, config=None):

self.separators = [',',
';',
':',
self.tr('Other')
]

self.translator = None

self.address_field_indices = []
Expand All @@ -69,10 +86,19 @@ def initAlgorithm(self, config=None):
)

self.addParameter(
QgsProcessingParameterString(
QgsProcessingParameterEnum(
self.SEPARATOR,
self.tr('Column separator'),
','
self.separators,
defaultValue=0
)
)

self.addParameter(
QgsProcessingParameterString(
self.OTHER_SEPARATOR,
self.tr('Other column separator'),
optional=True
)
)

Expand Down Expand Up @@ -174,7 +200,11 @@ def processAlgorithm(self, parameters, context, feedback):
self.context = context
self.feedback = feedback

col_separator = self.parameterAsString(parameters, self.SEPARATOR, context)
# Let's assign column separator character
if self.SEPARATORS[self.parameterAsEnum(parameters, self.SEPARATOR, context)] == 'Other':
col_separator = self.parameterAsString(parameters, self.OTHER_SEPARATOR, context)
else:
col_separator = self.SEPARATORS[self.parameterAsEnum(parameters, self.SEPARATOR, context)]
address_field_names_string = self.parameterAsString(parameters, self.ADDRESS_FIELD_NAMES, context)

extent = self.parameterAsExtent(parameters, self.SEARCH_EXTENT, context,
Expand Down

0 comments on commit 7e9fafa

Please sign in to comment.