Skip to content

Commit

Permalink
feat: add smoothing to isochrone params (#199)
Browse files Browse the repository at this point in the history

Co-authored-by: Jakob Schnell <github@ezelo.de>
Co-authored-by: mattamach <80196449+mattamach@users.noreply.github.com>
Co-authored-by: Merydian <Tillfrankenbach@web.de>
Co-authored-by: Till Frankenbach <81414045+Merydian@users.noreply.github.com>
  • Loading branch information
5 people authored Dec 6, 2023
1 parent 1718570 commit 774a6dd
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ RELEASING:
## Unreleased

### Added
- Additional parameter for the "smoothing factor" to isochrones processing algorithms ([#172](https://github.com/GIScience/orstools-qgis-plugin/issues/172))
- Mention omission of configuration options when using traveling salesman

## [1.6.0] - 2023-07-25
Expand All @@ -50,7 +51,6 @@ RELEASING:
- translation mechanism ([#183](https://github.com/GIScience/orstools-qgis-plugin/pull/183))
- german translation ([#183](https://github.com/GIScience/orstools-qgis-plugin/pull/183))


## [1.5.3] - 2023-03-30

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion ORStools/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@

AVOID_BORDERS = ['all', 'controlled', 'none']

ADVANCED_PARAMETERS = ["INPUT_AVOID_FEATURES", "INPUT_AVOID_BORDERS", "INPUT_AVOID_COUNTRIES", "INPUT_AVOID_POLYGONS"]
ADVANCED_PARAMETERS = ["INPUT_AVOID_FEATURES", "INPUT_AVOID_BORDERS", "INPUT_AVOID_COUNTRIES", "INPUT_AVOID_POLYGONS", 'INPUT_SMOOTHING']
Binary file modified ORStools/i18n/orstools_de.qm
Binary file not shown.
32 changes: 21 additions & 11 deletions ORStools/i18n/orstools_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,53 +165,63 @@
<context>
<name>ORSIsochronesLayerAlgo</name>
<message>
<location filename="../proc/isochrones_layer_proc.py" line="60"/>
<location filename="../proc/isochrones_layer_proc.py" line="64"/>
<source>Input Point layer</source>
<translation>Eingabelayer (Punkte)</translation>
</message>
<message>
<location filename="../proc/isochrones_layer_proc.py" line="69"/>
<location filename="../proc/isochrones_layer_proc.py" line="73"/>
<source>Input layer ID Field (mutually exclusive with Point option)</source>
<translation>ID-Attribut (schließt Punkt-Option aus)</translation>
</message>
<message>
<location filename="../proc/isochrones_layer_proc.py" line="75"/>
<location filename="../proc/isochrones_layer_proc.py" line="79"/>
<source>Dimension</source>
<translation>Dimension</translation>
</message>
<message>
<location filename="../proc/isochrones_layer_proc.py" line="81"/>
<location filename="../proc/isochrones_layer_proc.py" line="85"/>
<source>Comma-separated ranges [min or m]</source>
<translation>Komma-getrennte Reichweiten [min oder m]</translation>
</message>
<message>
<location filename="../proc/isochrones_layer_proc.py" line="203"/>
<location filename="../proc/isochrones_layer_proc.py" line="225"/>
<source>Isochrones from Point-Layer</source>
<translation>Isochronen aus Punkt-Layer</translation>
</message>
<message>
<location filename="../proc/isochrones_layer_proc.py" line="90"/>
<source>Smoothing factor between 0 [detailed] and 100 [generalized]</source>
<translation>Glättungsfaktor zwischen 0 [detailliert] und 100 [verallgemeinert]</translation>
</message>
</context>
<context>
<name>ORSIsochronesPointAlgo</name>
<message>
<location filename="../proc/isochrones_point_proc.py" line="55"/>
<location filename="../proc/isochrones_point_proc.py" line="58"/>
<source>Input Point from map canvas (mutually exclusive with layer option)</source>
<translation>Eingabepunkt aus Kartenansicht (schließt Ebenen-Option aus)</translation>
</message>
<message>
<location filename="../proc/isochrones_point_proc.py" line="60"/>
<location filename="../proc/isochrones_point_proc.py" line="63"/>
<source>Dimension</source>
<translation>Dimension</translation>
</message>
<message>
<location filename="../proc/isochrones_point_proc.py" line="66"/>
<location filename="../proc/isochrones_point_proc.py" line="69"/>
<source>Comma-separated ranges [min or m]</source>
<translation>Komma-getrennte Reichweiten [min oder m]</translation>
</message>
<message>
<location filename="../proc/isochrones_point_proc.py" line="144"/>
<location filename="../proc/isochrones_point_proc.py" line="163"/>
<source>Isochrones from Point</source>
<translation>Isochronen von einzelnem Punkt</translation>
</message>
<message>
<location filename="../proc/isochrones_point_proc.py" line="74"/>
<source>Smoothing factor between 0 [detailed] and 100 [generalized]</source>
<translation>Glättungsfaktor zwischen 0 [detailliert] und 100 [verallgemeinert]</translation>
</message>
</context>
<context>
<name>ORSMatrixAlgo</name>
Expand Down Expand Up @@ -244,12 +254,12 @@
<context>
<name>ORStoolsDialog</name>
<message>
<location filename="../gui/ORStoolsDialog.py" line="385"/>
<location filename="../gui/ORStoolsDialog.py" line="392"/>
<source>Apply</source>
<translation>Anwenden</translation>
</message>
<message>
<location filename="../gui/ORStoolsDialog.py" line="386"/>
<location filename="../gui/ORStoolsDialog.py" line="393"/>
<source>Close</source>
<translation>Schließen</translation>
</message>
Expand Down
34 changes: 28 additions & 6 deletions ORStools/proc/isochrones_layer_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterEnum
QgsProcessingParameterEnum,
QgsProcessingParameterNumber,
QgsProcessingParameterDefinition,
)

from ORStools.common import isochrones_core, PROFILES, DIMENSIONS
Expand All @@ -56,6 +58,8 @@ def __init__(self):
self.IN_RANGES = 'INPUT_RANGES'
self.IN_KEY = 'INPUT_APIKEY'
self.IN_DIFFERENCE = 'INPUT_DIFFERENCE'
self.USE_SMOOTHING = 'USE_SMOOTHING'
self.IN_SMOOTHING = 'INPUT_SMOOTHING'
self.PARAMETERS = [
QgsProcessingParameterFeatureSource(
name=self.IN_POINTS,
Expand All @@ -82,7 +86,16 @@ def __init__(self):
name=self.IN_RANGES,
description=self.tr("Comma-separated ranges [min or m]"),
defaultValue="5, 10"
)
),
QgsProcessingParameterNumber(
name=self.IN_SMOOTHING,
description=self.tr("Smoothing factor between 0 [detailed] and 100 [generalized]"),
defaultValue=None,
minValue=0,
maxValue=100,
optional=True
),

]

# Save some important references
Expand All @@ -103,10 +116,12 @@ def processAlgorithm(self, parameters, context, feedback):
factor = 60 if dimension == 'time' else 1
ranges_raw = parameters[self.IN_RANGES]
ranges_proc = [x * factor for x in map(int, ranges_raw.split(','))]

smoothing = parameters[self.IN_SMOOTHING]

# self.difference = self.parameterAsBool(parameters, self.IN_DIFFERENCE, context)
source = self.parameterAsSource(parameters, self.IN_POINTS, context)

# get smoothness parameter value
options = self.parseOptions(parameters, context)

# Make the actual requests
Expand All @@ -129,14 +144,21 @@ def processAlgorithm(self, parameters, context, feedback):
if feedback.isCanceled():
break

requests.append({
params = {
"locations": locations,
"range_type": dimension,
"range": ranges_proc,
"attributes": ['total_pop'],
"id": id_value,
"options": options
})
"options": options,
}

# only include smoothing if set
if smoothing is not None:
params["smoothing"] = smoothing

requests.append(params)


(sink, self.dest_id) = self.parameterAsSink(parameters, self.OUT, context,
self.isochrones.get_fields(),
Expand Down
23 changes: 21 additions & 2 deletions ORStools/proc/isochrones_point_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
QgsProcessingParameterString,
QgsProcessingParameterEnum,
QgsProcessingParameterPoint,
QgsProcessingParameterNumber,
QgsProcessingParameterDefinition
)

from ORStools.common import isochrones_core, PROFILES, DIMENSIONS
Expand All @@ -51,6 +53,7 @@ def __init__(self):
self.IN_RANGES = 'INPUT_RANGES'
self.IN_KEY = 'INPUT_APIKEY'
self.IN_DIFFERENCE = 'INPUT_DIFFERENCE'
self.IN_SMOOTHING = 'INPUT_SMOOTHING'
self.PARAMETERS = [
QgsProcessingParameterPoint(
name=self.IN_POINT,
Expand All @@ -67,9 +70,21 @@ def __init__(self):
name=self.IN_RANGES,
description=self.tr("Comma-separated ranges [min or m]"),
defaultValue="5, 10"
)
),
QgsProcessingParameterNumber(
name=self.IN_SMOOTHING,
description=self.tr("Smoothing factor between 0 [detailed] and 100 [generalized]"),
defaultValue=None,
minValue=0,
maxValue=100,
optional=True
),
]

# Set flag of smoothness parameters to advanced
smooth_param = next((i for i in self.PARAMETERS if i.name() == self.IN_SMOOTHING), None)
smooth_param.setFlags(smooth_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)

# Save some important references
# TODO bad style, refactor
isochrones = isochrones_core.Isochrones()
Expand All @@ -88,6 +103,7 @@ def processAlgorithm(self, parameters, context, feedback):
factor = 60 if dimension == 'time' else 1
ranges_raw = parameters[self.IN_RANGES]
ranges_proc = [x * factor for x in map(int, ranges_raw.split(','))]
smoothing = parameters[self.IN_SMOOTHING]

options = self.parseOptions(parameters, context)

Expand All @@ -102,9 +118,12 @@ def processAlgorithm(self, parameters, context, feedback):
"range": ranges_proc,
"attributes": ['total_pop'],
"id": None,
"options": options
"options": options,
}

if smoothing or smoothing == 0:
params["smoothing"] = smoothing

(sink, self.dest_id) = self.parameterAsSink(parameters, self.OUT, context,
self.isochrones.get_fields(),
QgsWkbTypes.Polygon,
Expand Down

0 comments on commit 774a6dd

Please sign in to comment.