Skip to content

Commit

Permalink
Merge branch 'main' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
koebi authored Aug 23, 2024
2 parents 163492b + d5ede0c commit 713eb7d
Show file tree
Hide file tree
Showing 46 changed files with 5,835 additions and 5,107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
tets/
docs/wiki/OSMtools.wiki/
.idea/
Expand Down
48 changes: 47 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,47 @@ RELEASING:
14. Create new release in GitHub with tag version and release title of `vX.X.X`
-->

## [1.8.4] - 2024-07-29

### Fixed
- issue with missing locale value for non-default user([#271](https://github.com/GIScience/orstools-qgis-plugin/issues/271))

## [1.8.3] - 2024-05-29

### 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
- use python 3.9-compatible type hint

## [1.8.1] - 2024-05-17

### Fixed
- use if-else instead of structural pattern matching

## [1.8.0] - 2024-05-17

### Added
- Add support for decimal ranges with isochrones([#237](https://github.com/GIScience/orstools-qgis-plugin/issues/237))
- Add hint for joining with `Layer ID Field` ([#143](https://github.com/GIScience/orstools-qgis-plugin/issues/143))
- Add option to export order of optimization route points ([#145](https://github.com/GIScience/orstools-qgis-plugin/issues/145))
- Add `extra_info` parameter to directions processing algorithms ([#251](https://github.com/GIScience/orstools-qgis-plugin/pull/251))

### Changed
- Rename `Ok` button in configuration window to `Save` for clarification ([#241](https://github.com/GIScience/orstools-qgis-plugin/issues/241))
- Replace PyQt5 imports with qgis.PyQt imports to prepare for Qt6-QGis builds

### Fixed
- QGis crashes when selecting more than two vertices for deletion ([#230](https://github.com/GIScience/orstools-qgis-plugin/issues/230))
- Vertices on canvas not depicted fully with n having more than one digit in length ([#235](https://github.com/GIScience/orstools-qgis-plugin/issues/235))
- Replace qt QSettings with QgsSettings for centralized configuration management ([#239](https://github.com/GIScience/orstools-qgis-plugin/issues/239))
- Point Annotations stay after saving project and not deleting them manually ([#229](https://github.com/GIScience/orstools-qgis-plugin/issues/229))
- Issue with MultiPoint-layers and optimization
- Improved type hints


# Unreleased
### Added
Expand Down Expand Up @@ -225,7 +266,12 @@ RELEASING:
- first working version of ORS Tools, after replacing OSM Tools plugin


[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.7.1...HEAD
[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.4...HEAD
[1.8.4]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.3...v1.8.4
[1.8.3]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.2...v1.8.3
[1.8.2]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.1...v1.8.2
[1.8.1]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.0...v1.8.1
[1.8.0]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.7.1...v1.8.0
[1.7.1]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.7.0...v1.7.1
[1.7.0]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.6.0...v1.7.0
[1.6.0]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.5.3...v1.6.0
Expand Down
3 changes: 2 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2021 HeiGIT gGmbH
Copyright (c) 2017 Nils Nolde
Copyright (c) 2019 HeiGIT gGmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 22 additions & 0 deletions ORStools/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2017 Nils Nolde
Copyright (c) 2019 HeiGIT gGmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 20 additions & 12 deletions ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
***************************************************************************/
"""

from qgis.core import QgsApplication
from PyQt5.QtCore import QTranslator, QSettings, qVersion, QCoreApplication
from qgis.gui import QgisInterface
from qgis.core import QgsApplication, QgsSettings
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication, QLocale
import os.path

from .gui import ORStoolsDialog
Expand All @@ -40,7 +41,7 @@ class ORStools:

# noinspection PyTypeChecker,PyArgumentList,PyCallByClass

def __init__(self, iface):
def __init__(self, iface: QgisInterface) -> None:
"""Constructor.
:param iface: An interface instance that will be passed to this class
Expand All @@ -55,23 +56,30 @@ def __init__(self, iface):
self.plugin_dir = os.path.dirname(__file__)

# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))
try:
locale = QgsSettings().value("locale/userLocale")
if not locale:
locale = QLocale().name()
locale = locale[0:2]

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

def initGui(self):
if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
except TypeError:
pass

def initGui(self) -> None:
"""Create the menu entries and toolbar icons inside the QGIS GUI."""

QgsApplication.processingRegistry().addProvider(self.provider)
self.dialog.initGui()

def unload(self):
def unload(self) -> None:
"""remove menu entry and toolbar icons"""
QgsApplication.processingRegistry().removeProvider(self.provider)
self.dialog.unload()
20 changes: 20 additions & 0 deletions ORStools/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@
"INPUT_AVOID_COUNTRIES",
"INPUT_AVOID_POLYGONS",
"INPUT_SMOOTHING",
"EXTRA_INFO",
"CSV_FACTOR",
"CSV_COLUMN",
]

LOCATION_TYPES = ["start", "destination"]

EXTRA_INFOS = [
"steepness",
"suitability",
"surface",
"waytype",
"waycategory",
"tollways",
"traildifficulty",
"osmid",
"roadaccessrestrictions",
"countryinfo",
"green",
"noise",
"csv",
"shadow",
]
18 changes: 13 additions & 5 deletions ORStools/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
import random
import time
from datetime import datetime, timedelta
from typing import Union, Dict, List, Optional
from urllib.parse import urlencode

from PyQt5.QtCore import QObject, pyqtSignal
from qgis.PyQt.QtCore import QObject, pyqtSignal
from requests.utils import unquote_unreserved

from ORStools import __version__
Expand All @@ -48,7 +49,7 @@
class Client(QObject):
"""Performs requests to the ORS API services."""

def __init__(self, provider=None, agent=None):
def __init__(self, provider: Optional[dict] = None, agent: Optional[str] = None) -> None:
"""
:param provider: A openrouteservice provider from config.yml
:type provider: dict
Expand Down Expand Up @@ -87,7 +88,14 @@ def __init__(self, provider=None, agent=None):

overQueryLimit = pyqtSignal()

def request(self, url, params, first_request_time=None, retry_counter=0, post_json=None):
def request(
self,
url: str,
params: dict,
first_request_time: Optional[datetime.time] = None,
retry_counter: int = 0,
post_json: Optional[dict] = None,
):
"""Performs HTTP GET/POST with credentials, returning the body as
JSON.
Expand Down Expand Up @@ -194,7 +202,7 @@ def request(self, url, params, first_request_time=None, retry_counter=0, post_js

return json.loads(content.decode("utf-8"))

def _check_status(self):
def _check_status(self) -> None:
"""
Casts JSON response to dict
Expand Down Expand Up @@ -231,7 +239,7 @@ def _check_status(self):
elif status_code != 200:
raise exceptions.GenericServerError(str(status_code), message)

def _generate_auth_url(self, path, params):
def _generate_auth_url(self, path: str, params: Union[Dict, List]) -> str:
"""Returns the path and query string portion of the request URL, first
adding any necessary parameters.
Expand Down
104 changes: 82 additions & 22 deletions ORStools/common/directions_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

from itertools import product
from qgis.core import QgsPoint, QgsPointXY, QgsGeometry, QgsFeature, QgsFields, QgsField
from typing import List
from typing import List, Generator, Tuple, Any, Optional

from PyQt5.QtCore import QVariant
from qgis.PyQt.QtCore import QVariant

from ORStools.utils import convert
from ORStools.utils import convert, logger


def get_request_point_features(route_dict, row_by_row):
def get_request_point_features(route_dict: dict, row_by_row: str) -> Generator[List, Tuple, None]:
"""
Processes input point features depending on the layer to layer relation in directions settings
Expand Down Expand Up @@ -75,12 +75,14 @@ def get_request_point_features(route_dict, row_by_row):


def get_fields(
from_type=QVariant.String,
to_type=QVariant.String,
from_name="FROM_ID",
to_name="TO_ID",
line=False,
):
from_type: QVariant.Type = QVariant.String,
to_type: QVariant.Type = QVariant.String,
from_name: str = "FROM_ID",
to_name: str = "TO_ID",
line: bool = False,
extra_info: list = [],
two_layers: bool = False,
) -> QgsFields:
"""
Builds output fields for directions response layer.
Expand All @@ -104,21 +106,34 @@ def get_fields(
"""

fields = QgsFields()
fields.append(QgsField("DIST_KM", QVariant.Double))
fields.append(QgsField("DURATION_H", QVariant.Double))
fields.append(QgsField("PROFILE", QVariant.String))
fields.append(QgsField("PREF", QVariant.String))
fields.append(QgsField("OPTIONS", QVariant.String))
fields.append(QgsField(from_name, from_type))
if not extra_info:
fields.append(QgsField("DIST_KM", QVariant.Double))
fields.append(QgsField("DURATION_H", QVariant.Double))
fields.append(QgsField("PROFILE", QVariant.String))
fields.append(QgsField("PREF", QVariant.String))
fields.append(QgsField("OPTIONS", QVariant.String))
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"]:
field_type = QVariant.String
fields.append(QgsField(info.upper(), field_type))

return fields


def get_output_feature_directions(
response, profile, preference, options=None, from_value=None, to_value=None
):
response: dict,
profile: str,
preference: str,
options: Optional[str] = None,
from_value: Any = None,
to_value: Any = None,
) -> QgsFeature:
"""
Build output feature based on response attributes for directions endpoint.
Expand Down Expand Up @@ -165,7 +180,9 @@ def get_output_feature_directions(
return feat


def get_output_features_optimization(response, profile, from_value=None):
def get_output_features_optimization(
response: dict, profile: str, from_value: Any = None
) -> QgsFeature:
"""
Build output feature based on response attributes for optimization endpoint.
Expand Down Expand Up @@ -205,9 +222,10 @@ def get_output_features_optimization(response, profile, from_value=None):

def build_default_parameters(
preference: str,
point_list: List[QgsPointXY] = None,
coordinates: list = None,
options: dict = None,
point_list: Optional[List[QgsPointXY]] = None,
coordinates: Optional[list] = None,
options: Optional[dict] = None,
extra_info: Optional[list] = None,
) -> dict:
"""
Build default parameters for directions endpoint. Either uses a list of QgsPointXY to create the coordinates
Expand Down Expand Up @@ -239,6 +257,48 @@ def build_default_parameters(
"elevation": True,
"id": None,
"options": options,
"extra_info": extra_info,
}

return params


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"]
extras_list = {i: [] for i in extra_info_order}
for key in extra_info_order:
try:
values = extra_info[key]["values"]
except KeyError:
logger.log(f"{key} is not available as extra_info.")
continue
for val in values:
for i in range(val[0], val[1]):
value = convert.decode_extrainfo(key, val[2])
extras_list[key].append(value)

for i in range(len(coordinates) - 1):
feat = QgsFeature()
qgis_coords = [QgsPoint(x, y, z) for x, y, z in coordinates[i : i + 2]]
feat.setGeometry(QgsGeometry.fromPolyline(qgis_coords))
attrs = list()
for j in extras_list:
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
Loading

0 comments on commit 713eb7d

Please sign in to comment.