Skip to content

Commit

Permalink
fix: make extra_info work with request from two point/polyline layers
Browse files Browse the repository at this point in the history
Co-authored-by: Jakob Schnell <Jakob.Schnell@heigit.org>
  • Loading branch information
merydian and koebi authored May 29, 2024
1 parent 2f925e7 commit 85d4f76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ RELEASING:
14. Create new release in GitHub with tag version and release title of `vX.X.X`
-->

## Unreleased

### Fixed
- Add csv\_column parameter to request made by points\_layers\_proc([#260](https://github.com/GIScience/orstools-qgis-plugin/issues/260))
- make extra\_info work with two points layers

## [1.8.2] - 2024-05-20

### Fixed
Expand Down
12 changes: 10 additions & 2 deletions ORStools/common/directions_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def get_fields(
to_name: str = "TO_ID",
line: bool = False,
extra_info: list = [],
two_layers: bool = False,
) -> QgsFields:
"""
Builds output fields for directions response layer.
Expand Down Expand Up @@ -114,6 +115,8 @@ def get_fields(
fields.append(QgsField(from_name, from_type))
if not line:
fields.append(QgsField(to_name, to_type))
if two_layers:
fields.append(QgsField(from_name, from_type))
for info in extra_info:
field_type = QVariant.Int
if info in ["waytype", "surface", "waycategory", "roadaccessrestrictions", "steepness"]:
Expand Down Expand Up @@ -260,15 +263,16 @@ def build_default_parameters(
return params


def get_extra_info_features_directions(response: dict, extra_info_order: list[str]):
def get_extra_info_features_directions(
response: dict, extra_info_order: list[str], to_from_values: Optional[list] = None
):
extra_info_order = [
key if key != "waytype" else "waytypes" for key in extra_info_order
] # inconsistency in API
response_mini = response["features"][0]
coordinates = response_mini["geometry"]["coordinates"]
feats = list()
extra_info = response_mini["properties"]["extras"]
logger.log(str(extra_info))
extras_list = {i: [] for i in extra_info_order}
for key in extra_info_order:
try:
Expand All @@ -290,7 +294,11 @@ def get_extra_info_features_directions(response: dict, extra_info_order: list[st
extra = extras_list[j]
attr = extra[i]
attrs.append(attr)

if to_from_values: # for directions from two point layers
attrs = [to_from_values[0], to_from_values[1]] + attrs
feat.setAttributes(attrs)

feats.append(feat)

return feats
4 changes: 3 additions & 1 deletion ORStools/proc/directions_lines_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ def processAlgorithm(
)

if extra_info:
feats = directions_core.get_extra_info_features_directions(response)
feats = directions_core.get_extra_info_features_directions(
response, extra_info
)
for feat in feats:
sink.addFeature(feat)
else:
Expand Down
13 changes: 10 additions & 3 deletions ORStools/proc/directions_points_layers_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ def processAlgorithm(
options = self.parseOptions(parameters, context)

csv_factor = self.parameterAsDouble(parameters, self.CSV_FACTOR, context)
csv_column = self.parameterAsString(parameters, self.CSV_COLUMN, context)
if csv_factor > 0:
options["profile_params"] = {"weightings": {"csv_factor": csv_factor}}
options["profile_params"] = {
"weightings": {"csv_factor": csv_factor, "csv_column": csv_column}
}

extra_info = self.parameterAsEnums(parameters, self.EXTRA_INFO, context)
extra_info = [EXTRA_INFOS[i] for i in extra_info]
Expand Down Expand Up @@ -209,7 +212,9 @@ def sort_end(f):
field_types.update({"from_type": source_field.type()})
if destination_field:
field_types.update({"to_type": destination_field.type()})
sink_fields = directions_core.get_fields(**field_types, extra_info=extra_info)
sink_fields = directions_core.get_fields(
**field_types, extra_info=extra_info, two_layers=True
)

(sink, dest_id) = self.parameterAsSink(
parameters,
Expand Down Expand Up @@ -241,7 +246,9 @@ def sort_end(f):
continue

if extra_info:
feats = directions_core.get_extra_info_features_directions(response)
feats = directions_core.get_extra_info_features_directions(
response, extra_info, values
)
for feat in feats:
sink.addFeature(feat)
else:
Expand Down

0 comments on commit 85d4f76

Please sign in to comment.